• Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
v3.5.1 Latest
Buy Hosting

Handling socket event sent from theme (on client) inside plugin (on server)

Scheduled Pinned Locked Moved NodeBB Plugins
3 Posts 2 Posters 1.9k Views
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vatsal
    wrote on last edited by vatsal
    #1

    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.

    1 Reply Last reply
    0
  • julianJ Offline
    julianJ Offline
    julian GNU/Linux
    wrote on last edited by julian
    #2

    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);

    V 1 Reply Last reply
    0
  • V Offline
    V Offline
    vatsal
    replied to julian on last edited by
    #3

    @julian great will try this now, thanks for quick reply!

    1 Reply Last reply
    0

Copyright © 2023 NodeBB | Contributors
  • Login

  • Don't have an account? Register

  • Login or register to search.
Powered by NodeBB Contributors
  • First post
    Last post
0
  • Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development