mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
SquashSRS4: Add demo for RTC
This commit is contained in:
parent
206d95879f
commit
becbe45bcd
34 changed files with 836 additions and 85 deletions
36
trunk/3rdparty/signaling/www/demos/js/srs.sig.js
vendored
36
trunk/3rdparty/signaling/www/demos/js/srs.sig.js
vendored
|
@ -59,7 +59,7 @@ function SrsRtcSignalingAsync() {
|
|||
// The message is a json object.
|
||||
self.send = async function (message) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var r = {tid: new Date().getTime().toString(16), msg: message};
|
||||
var r = {tid: Number(new Date().getTime() + parseInt(String(Math.random() * 10000000000))).toString(16), msg: message};
|
||||
self._internals.msgs[r.tid] = {resolve: resolve, reject: reject};
|
||||
self.ws.send(JSON.stringify(r));
|
||||
});
|
||||
|
@ -100,21 +100,49 @@ function SrsRtcSignalingParse(location) {
|
|||
|
||||
let wsPort = location.href.split('wsp=')[1];
|
||||
wsPort = wsPort? wsPort.split('&')[0] : location.host.split(':')[1];
|
||||
wsHost = wsPort? wsHost.split(':')[0] + ':' + wsPort : wsHost;
|
||||
|
||||
let host = location.href.split('host=')[1];
|
||||
host = host? host.split('&')[0] : location.hostname;
|
||||
|
||||
let room = location.href.split('room=')[1];
|
||||
room = room? room.split('&')[0] : null;
|
||||
|
||||
let display = location.href.split('display=')[1];
|
||||
display = display? display.split('&')[0] : new Date().getTime().toString(16).substr(3);
|
||||
display = display? display.split('&')[0] : Number(new Date().getTime() + parseInt(String(Math.random() * 10000000000))).toString(16).substr(3);
|
||||
|
||||
let autostart = location.href.split('autostart=')[1];
|
||||
autostart = autostart && autostart.split('&')[0] === 'true';
|
||||
|
||||
// Remove data in query.
|
||||
let rawQuery = query;
|
||||
if (query) {
|
||||
query = query.replace('wss=' + wsSchema, '');
|
||||
query = query.replace('wsh=' + wsHost, '');
|
||||
query = query.replace('wsp=' + wsPort, '');
|
||||
query = query.replace('host=' + host, '');
|
||||
if (room) {
|
||||
query = query.replace('room=' + room, '');
|
||||
}
|
||||
query = query.replace('display=' + display, '');
|
||||
query = query.replace('autostart=' + autostart, '');
|
||||
|
||||
while (query.indexOf('&&') >= 0) {
|
||||
query = query.replace('&&', '&');
|
||||
}
|
||||
query = query.replace('?&', '?');
|
||||
if (query.lastIndexOf('?') === query.length - 1) {
|
||||
query = query.substr(0, query.length - 1);
|
||||
}
|
||||
if (query.lastIndexOf('&') === query.length - 1) {
|
||||
query = query.substr(0, query.length - 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Regenerate the host of websocket.
|
||||
wsHost = wsPort? wsHost.split(':')[0] + ':' + wsPort : wsHost;
|
||||
|
||||
return {
|
||||
query: query, wsSchema: wsSchema, wsHost: wsHost, host: host,
|
||||
query: query, rawQuery: rawQuery, wsSchema: wsSchema, wsHost: wsHost, host: host,
|
||||
room: room, display: display, autostart: autostart,
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue