socket.js
457 Bytes
const sio = require('socket.io');
const db = require('./db');
let io;
module.exports = {
init(http) {
io = sio(http);
io.on('connection', (socket) => {
socket.on('init', (id) => {
console.log(`init ${id}`);
db.get('subthread').find({parent: id}, {sort: '+_id'}).each((thread, _) => {
socket.emit('thread', thread);
});
});
});
}
};