octoblu / meshblu

Meshblu is a cross-protocol IoT machine-to-machine messaging system.
https://meshblu.readme.io/
MIT License
815 stars 182 forks source link

socketLogic.js if fn is a string , my local meshblu reports error and crashed. #122

Closed eternaltao closed 8 years ago

eternaltao commented 8 years ago

~/meshblu/lib/socketLogic.js

socket.on('subscribe', throttler.throttle(function(message, fn) {
      fn = fn || _.noop;
      ...
      ...
      if (typeof fn != "function") {
                 return;
      }
     fn({"api": "subscribe", "socketid": socket.id, "toUuid": message.uuid, "result": true});

Do I need to add a judgment about the type of fn? I don't know how you avoid this.

I used a client with socket.io-android--- https://github.com/nkzawa/socket.io-android-chat to connect my local meshblu, when I try to emit a subscribe event:

 JSONObject subscribeUUID = new JSONObject();
   try {
          subscribeUUID.put("uuid","383ff240-2bc0-4582-bb5d-1f04971c089c");
    } catch (JSONException e) {
          e.printStackTrace();
    }

    mSocket.emit("subscribe", subscribeUUID, new Emitter.Listener(){
     @Override
      public void call(Object... args) {
      Log.i(TAG,args[0].toString());
      }
  });

My local meshblu reports error and crashed. Because fn is a string ,not a function.

com.github.nkzawa.socketio.androidchat.MeshbluTest$1$1$1@424cdc60

TypeError: fn is not a function
  at /home/dev/workspace/meshblu/lib/socketLogic.js:242:15
  at /home/dev/workspace/meshblu/lib/simpleAuth.coffee:183:7
  at /home/dev/workspace/meshblu/lib/simpleAuth.coffee:36:20
  at UUIDAliasResolver.resolve (/home/dev/workspace/meshblu/src/uuid-alias-resolver.coffee:11:12)
  at UUIDAliasResolver.resolve (/home/dev/workspace/meshblu/src/uuid-alias-resolver.coffee:1:1)
  at /home/dev/workspace/meshblu/lib/simpleAuth.coffee:29:30
  ....