UNPKG

skyriver

Version:

SkyRiver Streaming Cloud server-side library for NodeJS

120 lines (100 loc) 2.9 kB
'use strict'; var Credentials = require('./credentials') , API = require('./api'), fmt = require('util'), util = require('./util'), config = require('./config'); function Hub(credentials) { this.credentials = credentials; this.hub = config.const.DEFAULT_HUB; this.host = config.API_HOST; this.port = config.API_PORT; API.init(); }; function vodUrlPath(key) { var path = fmt.format('/v1/files/%s/vodurl', key); const expires = 3600; var deadline = expires + Math.floor(Date.now() / 1000); if (path.indexOf('?') >= 0) { path += '&nonce='; } else { path += '?nonce='; } path += deadline; var signature = util.hmacSha1(path, config.APP_SECRET); var encodedSign = util.base64ToUrlSafe(signature); var downloadToken = config.APP_KEY + ':' + encodedSign; path += '&token=' + downloadToken; return path; } Hub.prototype.createStream = function(options, fn) { API.createStream(this.credentials, this.hub, options, fn); } Hub.prototype.getStream = function(streamId, fn) { API.getStream(this.credentials, streamId, fn); } Hub.prototype.listStreams = function(options, fn) { API.listStreams(this.credentials, this.hub, options, fn); } Hub.prototype.getStreamsConnect = function(streamIds, fn) { var ids = { streamIds: streamIds }; API.getStreamsConnect(this.credentials, ids, fn); } Hub.prototype.getReceiver = function(streamId, fn) { API.getReceiver(this.credentials, streamId, fn); }; Hub.prototype.getDispatchers = function(fn) { API.getDispatchers(this.credentials, fn); }; Hub.prototype.getReceivers = function(fn) { API.getReceivers(this.credentials, fn); }; Hub.prototype.getStorage = function(uploadToken, fn) { API.getStorage(this.credentials, uploadToken, fn); }; /** * 生成api网关获取点播接口链接 * @param key * @returns http://12.7.0.0.1:8000/v1/files/key/vodurl?e=1111&token=downloadtoken */ Hub.prototype.vodURL = function(key) { var path = vodUrlPath(key); return fmt.format('http://%s:%s%s', this.host, this.port, path); }; /** * 获取点播地址 * @param key * @returns * { key, nonce: curNonce, token: '1234', ports: { rtmp: dispatcher.port_publish, hls: dispatcher.port_play }, urls: { hls: `/vod/${key}?nonce=${curNonce}&token=1234` }, dispatchers: dispatcher.dispatchers } */ Hub.prototype.getVodPlayURL = function(key, fn) { var path = vodUrlPath(key); API.getVodPlayURL(this.credentials, path, fn); }; /** * 删除点播/录制文件,删除录制文件需要传streamId * @param key * @param fn */ Hub.prototype.delVodFile = function(key, streamId, fn) { API.deleteVodFile(this.credentials, key, streamId, fn); }; /** * 获取服务器配置的转码参数 * @param fn */ Hub.prototype.getAvthumbConfig = function(fn) { API.getAvthumbConfig(this.credentials, fn); }; module.exports = Hub;