Naming convention for socket.io message?
-
Is there any standard naming convention for socket.io message?
I did some search and find out some patterns below:
- nodebb plugin -
event:{type}
eg.event:user_status_change
- custom plugin -
{pluginName}:{type}
eg.nodebb-plugin-myplugin:data_change
Any official comment on this? Thanks!
- nodebb plugin -
-
@Bruce-Lee something like
var PluginSockets = require.main.require('./src/socket.io/plugins'); PluginSockets.yourPlugin = {}; PluginSockets.yourPlugin.whatever = function (a, b, c) {};
On the server side equates to
socket.emit('plugins.yourPlugin.whatever', a, b, c);
On the client.
-
Actually it's
//server side PluginSockets.yourPlugin.whatever = function (socket, data, callback) { //socket.uid - uid of the user making the call or 0 for guests //data - data passed from the client //callback - notify client when you are done, pass err as first param }; //client side socket.emit('plugins.yourPlugin.whatever', {foo: 'bar'}, function(err, data) { if (err) { app.alertError(err.message); } //success });
Copyright © 2024 NodeBB | Contributors