Ha! Yeah I hear you. Every time I load up a regex library I feel like there ought to be a better way... luckily I'm at least semi-proficient at writing a regular expression, but don't ask me to make sense of one after a week's time LOL
Access socket.io, client and server-side. As-well as redis database.
Solved
NodeBB Plugins
-
Hello! I haven't seen anywhere talking about accessing
via the client-side, as-well as listening to the client-side. I've used before, but I don't know if it's recommended that I just start a new instance of , 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? -
From the client side, the instantiated
library can be accessed via the global variablesocket
.On the server side, you can access the primary database through our abstraction layer:
var db = module.parent.require('../database');
-
Thank you so much!
-
@julian said:
From the client side, the instantiated
library can be accessed via the global variablesocket
.On the server side, you can access the primary database through our abstraction layer:
var db = module.parent.require('../database');
Also: What about
server-side? Is there a global variable for socket io? would it be var io = module.parent.require('../socket');? -
Awesome. Thanks!
-
@julian Last thing. Should I just be calling a new instance of
, and have it listening to port 80? Or is there a way I can access the instance of that's already running (in the backend) and just make a room/namespace? -
@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'),