wilk / ng-websocket

AngularJS HTML5 WebSocket powerful library
MIT License
267 stars 78 forks source link

$on custom events not working properly #34

Closed kuravih closed 8 years ago

kuravih commented 8 years ago

How do I setup a custom event?

I'm trying to do it as given in $on. I have the following in my controller to catch a config event I'm firing from a node ws server.

var socket = $websocket.$new('ws://localhost:3000')
    .$on('$open', function () {
        console.log('Server connected');
    })
    .$on('$close', function () {
        console.log('Server disconnected');
    })
    .$on('$error', function () {
        console.log('Server error');
    })
    .$on('$message', function (message) {
        console.log(message);
    })
    .$on('config', function (data) {
        console.log(data);
    });

I'm logging all messages to make sure I receive the config object. The js console prints Object {config: 'testconfig'} so I'm receiving it. but I can't get the .$on('config', function (data) {console.log(data);}); bit to activate.

What am I missing? Is this a bug with $on or is that not how its supposed to be used? Should I be taking this to ws?

My server code for reference

var WebSocketServer = require('ws').Server;
var socketServer = new WebSocketServer({port: 3000});
socketServer.on('connection', function(socket) {
    console.log('server connected');
    socket.on('close', function() {
        console.log('server disconnected');
    })
    .send(JSON.stringify({config:'testconfig'}))
});
wilk commented 8 years ago

This project is no longer mainteined. Sorry.