How To: Using websockets in your plugin
-
Hey @Mr_Waffle would you like this guide to be a guest post on our blog? Maybe omit the initial bits and get straight to the solution etc.
Thanks for the guide
-
@psychobunny said:
Hey @Mr_Waffle would you like this guide to be a guest post on our blog? Maybe omit the initial bits and get straight to the solution etc.
Thanks for the guide
Sure, go ahead
-
-
Thanks @Mr_Waffle !
I started implementing this method in my static page plugin. I actually saw it in your shoutbox code on github (and stole it ) before you wrote this how to.
-
I was just about to ask about this, thanks for the guide! Just to be thorough, maybe include how to send a message in the other direction, server to client? If plugin authors are starting to append to existing modules in the core, maybe we should establish some namespacing conventions?
-
Server can do
socket.emit
and client can listen tosocket.on
without too much extra work. Keep me up to date with what you're doing and I can lend you a hand if you run into any problems -
Yeah, I know, I was able to figure that part out I was just saying for the sake of anyone starting out. It's not as straightforward as socket.io demonstrates...
@Mr_Waffle 's Shoutbox plugin was a good example of using something likevar socketIndex = module.parent.require('./socket.io/index'); socketIndex.server.sockets.emit('event:imgbed.server.rcv.end', { id: id, url: url, alt: alt} );
to send a message to the client, whereas simply using
socket.emit('event:imgbed.server.rvc.end', { id: "this is the id" });
will crash the server. -
@BDHarrington7 said:
Yeah, I know, I was able to figure that part out I was just saying for the sake of anyone starting out. It's not as straightforward as socket.io demonstrates...
@Mr_Waffle 's Shoutbox plugin was a good example of using something likevar socketIndex = module.parent.require('./socket.io/index'); socketIndex.server.sockets.emit('event:imgbed.server.rcv.end', { id: id, url: url, alt: alt} );
to send a message to the client, whereas simply using
socket.emit('event:imgbed.server.rvc.end', { id: "this is the id" });
will crash the server.Ye this is a little bit tricky, but you can figure this out by looking at some of the core code, especially the chat and new topic/reply sockets. Because you can already figure this out by looking at core code, I didn't think it'd be that important to write a guide on that as well Creating your own sockets isn't something that you can figure out from looking at core code!
-
@Schamper lol dat
NaN
tho