josephg / node-browserchannel

An implementation of a google browserchannel server in node.js
287 stars 47 forks source link

send message #49

Closed akurniawan closed 10 years ago

akurniawan commented 10 years ago

hello, first of all thanks for this great stuff. i have a little problem here, while using socket.io we can easily differ message by sending message to some specific event like emit('send_message_a') and emit('send_message_b'), how does things like this works in browserchannel, thanks :D

josephg commented 10 years ago

Hi!

Browserchannel is like TCP. You're smart enough to write that code yourself, so browserchannel gets out of the way and lets you do it however you want.

If you want to make different messages get handled by different bits of code, you should use a switch statement in your message handler. Your messages could be {type:'message a', data:...} or {type:'message b', data:...} then function onmessage(msg) { switch(msg.type) { ... } }.