How to use socket.io in ionicframework?


#1

I need an easy way to implement socket.io to my cordova project, connect it to the server and catch events. could any of you please guide me step by step on how to do so? I have tried all kind of libraries with no real success.


#2

The real thing to remember is that an ionic app is an angular app.
So any angular app tutorial should suffice.

http://www.html5rocks.com/en/tutorials/frameworks/angular-websockets/


#3

i returns me this error:

the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.
index):1 XMLHttpRequest cannot load http://178.62.83.248:1337/socket.io/?EIO=3&transport=polling&t=1422436920441-7. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.

anye ideas of to solve this? my server side is based on sails.js


#4

Hey! I just ran into this exact same problem. What worked for me was adding to my list of onlyAllowOrigins in sails.config.sockets.onlyAllowOrigins (see https://next.sailsjs.com/documentation/reference/configuration/sails-config-sockets). Also note that, to get more info, you can lift Sails with --silly. I also made a note in the docs to help make this easier in the future: https://github.com/balderdashy/sails-docs/commit/37055467d91303d56d24442fc1f9ced40f1919a0