Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var crypto = require('crypto');
- function generateSecurePathHash(expires, client_ip, secret) {
- if (!expires || !client_ip || !secret) throw new Error('Must provide all token components');
- var input = expires + client_ip + ' ' + secret;
- var binaryHash = crypto.createHash('md5').update(input).digest();
- var base64Value = new Buffer(binaryHash).toString('base64');
- return base64Value.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
- }
- function getStreamUrl(ip, secret) {
- const expiresTimestamp = new Date(Date.now() + (1000 * 60 * 30)).getTime();
- const expires = String(Math.round(expiresTimestamp / 1000));
- const token = generateSecurePathHash(expires, ip, secret);
- return `https://example.com/video/hls/${token}/${expires}/live.m3u8`;
- }
- getStreamUrl('127.0.0.1', 'uigfp(@#tfpIUDGPFiouGDF');
- // https://example.com/video/hls/LdS-kcC-JGVHGNTFlX-6Sw/1526373776/live.m3u8
Advertisement
Add Comment
Please, Sign In to add comment