Does Phonegap have socket.io integration in 3.5.0-0.20.10 version?
Since I am updating my PhoneGap to version 3.5.0-0.20.10 I am having problems in my project.
When I start the PhoneGap service, I see in the cli;
[phonegap] 200 /socket.io/?EIO=2&transport=polling&t=.......
But I don't use socket.io
. Using Chrome developer tools, I can see that my project has a folder socket.io
with socket.io.js
. So I think PhoneGap will import it by itself.
And I have RequireJS problem:
Unprepared ReferenceError: io is not defined
I tried to remove RequireJS, then it works, but I need RequireJS. Everything works fine on the old version 3.5.0-0.20.5
source to share
Found the answer ... Change consoler.js in the phonegap node-modules directory (usually / usr / local / lib / node_modules / phonegap / node_modules / connect-phonegap / res / middleware ) to download socket.io via AMD, not directly :
<!-- <script src="/socket.io/socket.io.js"></script> -->
<script>
(function(window) {
require(['/socket.io/socket.io.js'],function(io){
var socket = io('http://' + document.location.host);
var previousConsole = window.console || {};
window.console = {
log:function(msg){
previousConsole.log && previousConsole.log(msg);
socket.emit('console','log', msg);
},
warn:function(msg){
previousConsole.warn && previousConsole.warn(msg);
socket.emit('console','warn', msg);
},
error:function(msg){
previousConsole.error && previousConsole.error(msg);
socket.emit('console','error', msg);
}
}
});
})(window);
</script>
source to share