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'}))
});
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.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