LiveQing直播RTMP点播视频流媒体平台如何携带登录接口返回sid和token、streamToken
1、前言
先前的文章介绍了,一步一步搭建RTMP推流直播流媒体服务, OBS如何配置推流到RTMP流媒体服务直播视频文件直播桌面操作让微信手机端电脑浏览器无插件直播观看,这篇文章介绍接口调用及相关示例。
2、JQuery 调用示例
2.1、携带 sid 请求
下面是完整的 jquery 调用示例
<html>
<head>
<title>LiveNVR 接口调用示例</title>
<script src="jquery-2.2.4.js"></script>
</head>
<body>
</body>
<script>
$.ajax({
url: "http://127.0.0.1:10080/api/v1/login",
type: 'GET',
data: {
username:"test",
password:"098f6bcd4621d373cade4e832627b4f6"
},
xhrFields: {
withCredentials: true
},
crossDomain: true,
success: function (ret) {
console.log(ret)
var sid = ret.data.sid;
alert(sid )
getlives(sid )
},
error: function(xhr,textStatus,errorThrown){
alert(xhr.status)
}
}
);
<!--携带token调用其他接口示例 -->
function getlives(sid ) {
$.ajax({
url: "http://127.0.0.1:10080/api/v1/live/list",
type: 'GET',
data: {
start:0,
limit:10
},
xhrFields: {
withCredentials: true
},
crossDomain: true,
beforeSend: function (xhr) {
xhr.setRequestHeader("cookie", "sid="+sid );
},
success: function (ret) {
console.log(ret)
alert(JSON.stringify(ret));
},
error: function(xhr,textStatus,errorThrown){
alert(xhr.status)
}
}
);
}
</script>
</html>
2.2、携带 token 请求
下面是完整的 jquery 调用示例
<html>
<head>
<title>LiveNVR 接口调用示例</title>
<script src="jquery-2.2.4.js"></script>
</head>
<body>
</body>
<script>
$.ajax({
url: "http://127.0.0.1:10080/api/v1/login",
type: 'GET',
data: {
username:"test",
password:"098f6bcd4621d373cade4e832627b4f6"
},
xhrFields: {
withCredentials: true
},
crossDomain: true,
success: function (ret) {
console.log(ret)
var sid = ret.data.token;
alert(token)
getlives(token)
},
error: function(xhr,textStatus,errorThrown){
alert(xhr.status)
}
}
);
<!--携带token调用其他接口示例 -->
function getlives(token) {
$.ajax({
url: "http://127.0.0.1:10080/api/v1/live/list",
type: 'GET',
data: {
start:0,
limit:10,
token:token,
},
xhrFields: {
withCredentials: true
},
crossDomain: true,
success: function (ret) {
console.log(ret)
alert(JSON.stringify(ret));
},
error: function(xhr,textStatus,errorThrown){
alert(xhr.status)
}
}
);
}
</script>
</html>
3、携带streamToken
直接在获取的视频流原始地址后面加上 token=streamToken的值 , 如:
http://localhost:10080/flv/hls/test-002.flv?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1OTg2MDUxNTcsInB3IjoiMjEyMzJmMjk3YTU3YTVhNzQzODk0YTBlNGE4MDFmYzMiLCJ0bSI6MTU5ODYwNDg1NywidW4iOiJhZG1pbiJ9.Sx_eTWN4ynLzFCGM6AJ-s6XQF-3QrBV36zlB5MT39eI