代码拉取完成,页面将自动刷新
//
// Created by Mingliang Chen on 17/8/23.
// illuspas[a]gmail.com
// Copyright (c) 2018 Nodemedia. All rights reserved.
//
const Crypto = require('crypto');
const EventEmitter = require('events');
const context = require('./node_core_ctx');
function generateNewSessionID() {
let sessionID = '';
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWKYZ0123456789';
const numPossible = possible.length;
do {
for (let i = 0; i < 8; i++) {
sessionID += possible.charAt((Math.random() * numPossible) | 0);
}
} while (context.sessions.has(sessionID))
return sessionID;
}
function genRandomName() {
let name = '';
const possible = 'abcdefghijklmnopqrstuvwxyz0123456789';
const numPossible = possible.length;
for (let i = 0; i < 4; i++) {
name += possible.charAt((Math.random() * numPossible) | 0);
}
return name;
}
function verifyAuth(signStr, streamId, secretKey) {
if (signStr === undefined) {
return false;
}
let now = Date.now() / 1000 | 0;
let exp = parseInt(signStr.split('-')[0]);
let shv = signStr.split('-')[1];
let str = streamId + '-' + exp + '-' + secretKey;
if (exp < now) {
return false;
}
let md5 = Crypto.createHash('md5');
let ohv = md5.update(str).digest('hex');
return shv === ohv;
}
module.exports.generateNewSessionID = generateNewSessionID;
module.exports.verifyAuth = verifyAuth;
module.exports.genRandomName = genRandomName;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。