xBytez / slackbotapi

node.js Slack RTM API module
GNU Lesser General Public License v3.0
135 stars 40 forks source link

self.ws doesn't have on() #25

Closed ptarjan closed 9 years ago

ptarjan commented 9 years ago

I'm getting

TypeError: self.ws.on is not a function
    at slackAPI.213.slackAPI.connectSlack (index.js:174)
    at index.js:121
    at Request._callback (index.js:142)
    at Request.322.Request.init.self.callback (request.js:198)
    at Request.166.EventEmitter.emit (events.js:80)
    at Request.<anonymous> (request.js:1073)
    at Request.166.EventEmitter.emit (events.js:99)
    at null.<anonymous> (request.js:1019)
    at 166.EventEmitter.emit (events.js:99)
    at endReadableNT (_stream_readable.js:944)

If I put a debugger, I see that self.ws has a onClose and an onOpen, etc, but no on. Is there a version mismatch somewhere? When I installed I ended up with version 0.8.0 of ws.

franciskim commented 9 years ago

how did you go with this? Can you console.log(self) and console.log(self.ws) and post the output here?

ptarjan commented 9 years ago

I figured this out. The Browser WebSocket Class and the NodeJS WebSocket Class do NOT have the same API. You are relying on the fact that this is NodeJS and not being run using browserify.

I put in this code, and your library works. Maybe you should include it yourself if the on method doesn't exist?

      WebSocket.prototype.on = function(event, callback) {
        this['on' + event] = function(message) {
          callback(message.data);
        };
      };