This commit is contained in:
梁朝伟 2022-09-07 12:00:31 +08:00
parent 23f3576720
commit f29f543ac6
4 changed files with 43 additions and 29 deletions

View File

@ -83,7 +83,7 @@ function getQiniuToken(config, params) {
*/
function getLivestream(params, context) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var streamTitle, expireAt, config, hub, path, key, bodyStr, token, url, obj;
var streamTitle, expireAt, config, hub, path, key, bodyStr, contentType, token, url, obj;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
@ -100,30 +100,35 @@ function getLivestream(params, context) {
bodyStr = JSON.stringify({
key: key,
});
contentType = 'application/json';
return [4 /*yield*/, getQiniuToken(config, {
method: 'POST',
path: path,
contentType: 'application/json',
contentType: contentType,
bodyStr: bodyStr,
})];
case 2:
token = (_a.sent()).token;
url = "http://pili.qiniuapi.com/v2/hubs/".concat(hub, "/stearms");
return [4 /*yield*/, fetch(url, {
method: 'POST',
headers: new Headers({
'Authorization': token,
'Content-Type': 'application/json',
}),
body: bodyStr,
mode: 'no-cors',
}).then(function (res) {
console.log(res.json());
})];
case 3:
_a.sent();
url = 'http://pili.qiniuapi.com/v2/hubs/test-play-space/streams';
console.log(bodyStr, url, token);
fetch(url, {
method: 'POST',
headers: {
Authorization: token,
'Content-Type': contentType,
},
body: bodyStr,
mode: 'no-cors',
})
.then(function (res) {
console.log(res.json());
}).then(function (res) {
console.log(res);
}).catch(function (e) {
console.log(e);
});
return [4 /*yield*/, getStreamObj(config, streamTitle, expireAt)];
case 4:
case 3:
obj = _a.sent();
return [2 /*return*/, obj];
}
@ -165,7 +170,7 @@ function getStreamObj(config, streamTitle, expireAt) {
hub = config.hub, publishDomain = config.publishDomain, rtmpPlayDomain = config.rtmpPlayDomain, publishKey = config.publishKey, playKey = config.playKey;
signStr = "/".concat(hub, "/").concat(streamTitle, "?expire=").concat(expireAt);
sourcePath = "/".concat(hub, "/").concat(streamTitle);
token = (0, sign_1.urlSafeBase64Encode)((0, sign_1.hmacSha1)(signStr, publishKey));
token = (0, sign_1.base64ToUrlSafe)((0, sign_1.hmacSha1)(signStr, publishKey));
rtmpPushUrl = "rtmp://".concat(publishDomain).concat(signStr, "&token=").concat(token);
t = expireAt.toString(16).toLowerCase();
playSign = ts_md5_1.Md5.hashStr(playKey + sourcePath + t).toString().toLowerCase();

View File

@ -29,6 +29,7 @@ var QiniuLiveInstance = /** @class */ (function () {
if (bodyStr && contentType && contentType !== "application/octet-stream") {
data += bodyStr;
}
console.log('data', data);
var sign = (0, sign_1.hmacSha1)(data, secretKey);
var encodedSign = (0, sign_1.base64ToUrlSafe)(sign);
var toke = "Qiniu " + accessKey + ":" + encodedSign;

View File

@ -5,7 +5,7 @@ import { Schema as Livestream } from '../general-app-domain/Livestream/Schema';
import QiniuLive from '../utils/externalUpload/qiniu_live';
import { Datetime } from 'oak-domain/lib/types/DataType';
import { Md5 } from 'ts-md5';
import { hmacSha1, urlSafeBase64Encode } from '../utils/sign';
import { hmacSha1, base64ToUrlSafe } from '../utils/sign';
async function getQiniuUploadInfo<ED extends EntityDict, Cxt extends GeneralRuntimeContext<ED>>(
context: Cxt
@ -103,24 +103,31 @@ export async function getLivestream<ED extends EntityDict, Cxt extends GeneralRu
const bodyStr = JSON.stringify({
key,
})
const contentType = 'application/json';
const { token } = await getQiniuToken(config, {
method: 'POST',
path,
contentType: 'application/json',
contentType,
bodyStr,
});
const url = `http://pili.qiniuapi.com/v2/hubs/${hub}/stearms`;
await fetch(url, {
const url = 'http://pili.qiniuapi.com/v2/hubs/test-play-space/streams';
console.log(bodyStr, url, token);
fetch(url, {
method: 'POST',
headers: new Headers({
'Authorization': token,
'Content-Type': 'application/json',
}),
headers: {
Authorization: token,
'Content-Type': contentType,
},
body: bodyStr,
mode: 'no-cors',
}).then((res) => {
console.log(res.json());
})
.then((res) => {
console.log(res.json());
}).then((res) => {
console.log(res);
}).catch((e) => {
console.log(e);
})
const obj = await getStreamObj(config, streamTitle, expireAt);
return obj;
@ -184,7 +191,7 @@ async function getStreamObj(
const {hub, publishDomain, rtmpPlayDomain, publishKey, playKey } = config;
const signStr = `/${hub}/${streamTitle}?expire=${expireAt}`;
const sourcePath = `/${hub}/${streamTitle}`;
const token = urlSafeBase64Encode(hmacSha1(signStr, publishKey));
const token = base64ToUrlSafe(hmacSha1(signStr, publishKey));
const rtmpPushUrl = `rtmp://${publishDomain}${signStr}&token=${token}`
// 生成播放地址
const t = expireAt.toString(16).toLowerCase();

View File

@ -48,6 +48,7 @@ export default class QiniuLiveInstance {
if(bodyStr && contentType && contentType !== "application/octet-stream") {
data+=bodyStr;
}
console.log('data', data);
const sign = hmacSha1(data, secretKey);
const encodedSign = base64ToUrlSafe(sign);
const toke = "Qiniu " + accessKey + ":" + encodedSign;