Access socket.io, client and server-side. As-well as redis database.
Solved
NodeBB Plugins
-
-
Thank you so much!
-
@julian said:
From the client side, the instantiated socket.io library can be accessed via the global variable
socket
.On the server side, you can access the primary database through our abstraction layer:
var db = module.parent.require('../database');
Also: What about socket.io server-side? Is there a global variable for socket io? would it be var io = module.parent.require('../socket');?
-
Awesome. Thanks!
-
-
@baris said:
sockets.server.in('someRoom').emit('myEvent', {foo:'bar'});
I'm getting 'server' as undefined ( TypeError: Cannot call method 'in' of undefined_, using the following code.
(function() { 'use strict'; var winston = module.parent.require('winston'), plugins = module.parent.require('./plugins'), fs = require('fs'), path = require('path'), util = require('util'), sockets = require('../socket.io'), app; var Plugin = { staticAppLoad: function(params, callback) { winston.verbose("nodebb-plugin-market - staticAppLoad called"); app = params.app; var router = params.router; var renderCustomPage = function (req, res) { res.render('products.tpl', {someInjectedData: "Longer dPlugin Title"}); sockets.server.in('products').emit('TEST!'); } router.get('/products', params.middleware.buildHeader, renderCustomPage); if (typeof callback === 'function') { callback(); } }, //staticAppLoad }; module.exports = Plugin; })();
-
I think your require is wrong, should be
module.parent.require('./socket.io'),
Copyright © 2024 NodeBB | Contributors