Socket.io in ionic cordova

2019-05-11 00:51发布

Initially I have used btford socket.io library for my ionic project, but I am having trouble working with it. Now I am trying to install socket.io directly to an ionic project. However I am not sure whether it should installed as an npm install which will store it in the node_modules folder, or should i store the library in ionicprj/www/lib ?

2条回答
贪生不怕死
2楼-- · 2019-05-11 01:22

socket.io client library should go in www/lib/ to emit events from the ionic app. On the server you'll want socket.io as an npm module.

There's a helpful tutorial here: http://www.htmlxprs.com/post/6/creating-a-realtime-image-sharing-app-with-ionic-and-socketio-tutorial

查看更多
家丑人穷心不美
3楼-- · 2019-05-11 01:24

cordova-plugin-whitelist seems to be "mandatory" at present.

install it

cordova plugin add cordova-plugin-whitelist

configure config.xml

You can keep your current setup with * or change for more restrictive rules

add a html policy on index.html, you shall add a Policy also. To authorise everything, here it is :

<meta http-equiv="Content-Security-Policy" content="default-src *; 
style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe eval'">
查看更多
登录 后发表回答