Usted tiene que agregar el host socketio a la tecla "ExternalHosts" en PhoneGap. Plist.
Ver Faq:
Q. Links to and imported files from external hosts don't load?
A. The latest code has the new white-list feature. If you are referencing external hosts, you will have to add the host in PhoneGap.plist under the "ExternalHosts" key. Wildcards are ok. So if you are connecting to " http://phonegap.com ", you have to add "phonegap.com" to the list (or use the wildcard "*.phonegap.com" which will match subdomains as well). (Note: If you open the plist file in Xcode, you won't need to fiddle with the XML syntax.)
para Android tiene que editar y añadir cordova.xml el acceso al host socketio:
<access origin="HOST*"/>
index.html (con socketio ejemplo):
...
<script src="HOST/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('HOST');
socket.on('news', function (data) {
socket.emit('my other event', { my: 'data' });
});
</script>
...
app.js (lado del servidor JavaScript/socketio ejemplo básico):
var io = require('socket.io').listen(80);
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
el host que tiene que reemplazar con el nombre de host de su servidor socket.io!
¿Es solo Android? Estoy compilando para iOS y no tengo un cordova.xml, solo un cordova.plist. ¿Has hecho esto en iOS? ¡Gracias! – fancy
Sí (cordova.xml es solo para Android). Para iOS, debe colocar el HOST en PhoneGap.plist (consulte http: // stackoverflow.com/a/8972890/584545) –
Agregar un host a la lista blanca no hace nada en cuanto a configurar el orgin, que es el problema. Shazron, a continuación (quien crea PhoneGap) tiene la idea correcta, simplemente no sé cómo hacer eso. – fancy