rebyte
rebyte

Reputation: 80

Phonegap/Cordova - Socket plugins end up with: undefined is not a function in cordova.js

I have added this phonegap/cordova plugin (android) for sockets and can't get it work. https://github.com/blocshop/sockets-for-cordova/tree/version1.1

I am getting the log messages "debug 1" and "debug2". So creating the socketHandle object works. But it fails on socketHandle.open. The console says:

Console Log

file:///android_asset/www/cordova.js: Line 927 : Uncaught TypeError : undefined is not a function

JS Code

    console.log("debug 1");

    var socketHandle = new Socket();

    console.log("debug 2");

    socketHandle.open(
      "192.168.1.15",
      51213,
      function() {
        alert("success");
        // invoked after successful opening of socket
      },
      function(errorMessage) {
        alert("failed");
        // invoked after unsuccessful opening of socket
      });

    console.log("debug 3");

cordova.js Line 927 (within androidExec function):

var messages = nativeApiProvider.get().exec(bridgeSecret, service, action, callbackId, argsJson);

I have tried other socket plugins but they end up with the same problem. Hopefully someone can help me or point me in the right direction.

Upvotes: 0

Views: 1007

Answers (1)

rebyte
rebyte

Reputation: 80

Seems that phonegap does not load the js include in the right order. I have put the include of cordova.js in the head section of my index.html and it does work now. Really strange

Upvotes: 0

Related Questions