代码拉取完成,页面将自动刷新
同步操作将从 Piplin/Piplin 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
var jwt = require('jsonwebtoken');
var fs = require('fs');
require('dotenv').load();
var debug = (process.env.APP_DEBUG === 'true' || process.env.APP_DEBUG === true);
var Redis = require('ioredis');
var redis = new Redis({
port: process.env.REDIS_PORT || 6379,
host: process.env.REDIS_HOST || '127.0.0.1',
db: process.env.REDIS_DATABASE || 0,
password: process.env.REDIS_PASSWORD || null
});
if (/^https/i.test(process.env.SOCKET_URL)) {
var ssl_conf = {
key: (process.env.SOCKET_SSL_KEY_FILE ? fs.readFileSync(process.env.SOCKET_SSL_KEY_FILE) : null),
cert: (process.env.SOCKET_SSL_CERT_FILE ? fs.readFileSync(process.env.SOCKET_SSL_CERT_FILE) : null),
ca: (process.env.SOCKET_SSL_CA_FILE ? fs.readFileSync(process.env.SOCKET_SSL_CA_FILE) : null)
};
var app = require('https').createServer(ssl_conf, handler);
} else {
var app = require('http').createServer(handler);
}
var io = require('socket.io')(app);
app.listen(parseInt(process.env.SOCKET_PORT), function() {
if (debug) {
console.log('Server is running!');
}
});
function handler(req, res) {
res.writeHead(200);
res.end('');
}
// Middleware to check the JWT
io.use(function(socket, next) {
var decoded;
if (debug) {
console.log('Token - ' + socket.handshake.query.jwt);
}
try {
decoded = jwt.verify(socket.handshake.query.jwt, process.env.JWT_SECRET);
if (debug) {
console.log(decoded);
}
} catch (err) {
if (debug) {
console.error(err);
}
next(new Error('Invalid token!'));
}
if (decoded) {
// everything went fine - save userId as property of given connection instance
socket.userId = decoded.data.userId;
next();
} else {
// invalid token - terminate the connection
next(new Error('Invalid token!'));
}
});
io.on('connection', function(socket) {
if (debug) {
console.log('connection');
}
});
redis.psubscribe('*', function(err, count) {
if (debug) {
console.log('psubscribe');
}
});
redis.on('pmessage', function(subscribed, channel, message) {
message = JSON.parse(message);
if (message.event.indexOf('RestartSocketServer') !== -1) {
if (debug) {
console.log('Restart command received');
}
process.exit();
return;
}
if (debug) {
console.log('Message received from event ' + message.event + ' to channel ' + channel);
}
io.emit(channel + ':' + message.event, message.data);
});
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。