This is the reason...
NOW
Image Credit: @phenomlab 😉
unknownjjj.png
Absolutely brilliant @baris, the difference is clear 👍
PREVIOUSLY
Screenshot_2021-05-10 TalkCounty com(3).png
I have created a custom theme which allows users to interact with topics in more than default ways, essentially it is rating system for topics. I have successfully added a new hash field to topics on "topic.save".
My theme has extra buttons for custom rating, clicking on which through my theme.js I am sending socket emit to be handled on server side. But my plugin doesn't seems to be responding to those socket events. However, if I put same socket.on handler inside src/socket.io/index.js, it works.
I need to find a way to handle custom socket events emitted from my theme through my plugin. Otherwise I don't want to tangle with the core source of the software, which of course is not a wise decision.
It's not recommended to add listeners to any other socket.io namespace besides plugins.js
, since that one is purposefully empty and built for plugins to use.
If you add a new method there, e.g.:
var SocketPlugins = module.parent.require('./socket.io/plugins');
SocketPlugins.myPlugin = {};
SocketPlugins.myPlugin.myMethod = function(someObj) { ... };
Then that method will be invoked when you do this on the client side:
socket.emit('plugins.myPlugin.myMethod', someObj, callback);