mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-06-15 01:42:18 +02:00
feat: socket.io 3 changes (#8845)
* feat: socket.io 3 changes * feat: replace socketio-wildcard with socket.onAny up socket.io-redis to 6.x * feat: remove mongodb/psql socket.io adapters * feat: show data on fail * fix: tests * fix: typo * fix: logger test fix * fix: logger.io_close * chore: up deps * chore: update readme to reflect redis requirement * fix: increase timeout show data if test fails
This commit is contained in:
committed by
GitHub
parent
d7f5efd960
commit
1c45fa1ba5
@@ -181,11 +181,6 @@ mongoModule.close = function (callback) {
|
||||
client.close(err => callback(err));
|
||||
};
|
||||
|
||||
mongoModule.socketAdapter = function () {
|
||||
const mongoAdapter = require('@nodebb/socket.io-adapter-mongo');
|
||||
return mongoAdapter(connection.getConnectionString(), connection.getConnectionOptions());
|
||||
};
|
||||
|
||||
require('./mongo/main')(mongoModule);
|
||||
require('./mongo/hash')(mongoModule);
|
||||
require('./mongo/sets')(mongoModule);
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const mubsub = require('@nodebb/mubsub');
|
||||
const connection = require('./connection');
|
||||
|
||||
const client = mubsub(connection.getConnectionString(), connection.getConnectionOptions());
|
||||
client.on('error', err => console.error(err));
|
||||
const channel = client.channel('pubsub');
|
||||
channel.on('error', err => console.error(err));
|
||||
module.exports = channel;
|
||||
@@ -406,13 +406,6 @@ postgresModule.close = function (callback) {
|
||||
postgresModule.pool.end(callback);
|
||||
};
|
||||
|
||||
postgresModule.socketAdapter = function () {
|
||||
var postgresAdapter = require('socket.io-adapter-postgres');
|
||||
return postgresAdapter(connection.getConnectionOptions(), {
|
||||
pubClient: postgresModule.pool,
|
||||
});
|
||||
};
|
||||
|
||||
require('./postgres/main')(postgresModule);
|
||||
require('./postgres/hash')(postgresModule);
|
||||
require('./postgres/sets')(postgresModule);
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const util = require('util');
|
||||
const winston = require('winston');
|
||||
const EventEmitter = require('events').EventEmitter;
|
||||
const pg = require('pg');
|
||||
const connection = require('./connection');
|
||||
|
||||
const PubSub = function () {
|
||||
const self = this;
|
||||
|
||||
const subClient = new pg.Client(connection.getConnectionOptions());
|
||||
|
||||
subClient.connect(function (err) {
|
||||
if (err) {
|
||||
winston.error(err.stack);
|
||||
return;
|
||||
}
|
||||
|
||||
subClient.query('LISTEN pubsub', function (err) {
|
||||
if (err) {
|
||||
winston.error(err.stack);
|
||||
}
|
||||
});
|
||||
|
||||
subClient.on('notification', function (message) {
|
||||
if (message.channel !== 'pubsub') {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
var msg = JSON.parse(message.payload);
|
||||
self.emit(msg.event, msg.data);
|
||||
} catch (err) {
|
||||
winston.error(err.stack);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
util.inherits(PubSub, EventEmitter);
|
||||
|
||||
PubSub.prototype.publish = function (event, data) {
|
||||
const db = require('../postgres');
|
||||
db.pool.query({
|
||||
name: 'pubSubPublish',
|
||||
text: `SELECT pg_notify('pubsub', $1::TEXT)`,
|
||||
values: [JSON.stringify({ event: event, data: data })],
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = new PubSub();
|
||||
Reference in New Issue
Block a user