LiveQing RTMP On-demand video streaming platform how to return SID and Token and streamToken with login interface

  • 1, the preface
  • 2. JQuery call example
    • 2.1. Carry SID requests
    • 2.2 Request with Token
  • 3. Carry streamToken

1, the preface

The previous article introduced the step by step construction of RTMP push live streaming media service, OBS how to configure push stream to RTMP streaming media service live video files live desktop operation so that wechat mobile end computer browser without plug-ins live watching, this article introduces the interface call and related examples.

2. JQuery call example

2.1. Carry SID requests

Here is a complete example of a jquery call

< HTML >< head> <title>LiveNVR interface call example </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)}}); <! Example - carrying token call other interface - > 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>Copy the code

2.2 Request with Token

Here is a complete example of a jquery call

< HTML >< head> <title>LiveNVR interface call example </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)}}); <! Example - carrying token call other interface - > 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>Copy the code

3. Carry streamToken

Add the value of token=streamToken directly after the original address of the obtained video stream, as follows:

http://localhost:10080/flv/hls/test-002.flv?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1OTg2MDUxNTcsInB3IjoiM jEyMzJmMjk3YTU3YTVhNzQzODk0YTBlNGE4MDFmYzMiLCJ0bSI6MTU5ODYwNDg1NywidW4iOiJhZG1pbiJ9.Sx_eTWN4ynLzFCGM6AJ-s6XQF-3QrBV36zlB 5MT39eI