Access socket.io, client and server-side. As-well as redis database.
-
Hello! I haven't seen anywhere talking about accessing socket.io via the client-side, as-well as listening to the client-side. I've used socket.io before, but I don't know if it's recommended that I just start a new instance of socket.io, or if there's a global variable of some sort I can access. On top of that, I was wondering the same for Redis database. I don't want to just create another instance/connection to the database if there's a global variable. Could someone enlighten me on this?
-
-
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'),