build
This commit is contained in:
69
hs-im-server/build/hd-glasses-app/conf/nginx.conf
Normal file
69
hs-im-server/build/hd-glasses-app/conf/nginx.conf
Normal file
@@ -0,0 +1,69 @@
|
||||
user root;
|
||||
worker_processes auto;
|
||||
|
||||
error_log /var/log/nginx/error.log notice;
|
||||
pid /var/run/nginx.pid;
|
||||
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
|
||||
http {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
'$status $body_bytes_sent "$http_referer" '
|
||||
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||
|
||||
access_log /var/log/nginx/access.log main;
|
||||
|
||||
sendfile on;
|
||||
#tcp_nopush on;
|
||||
|
||||
keepalive_timeout 65;
|
||||
|
||||
#gzip on;
|
||||
gzip on;
|
||||
gzip_min_length 1k;
|
||||
gzip_comp_level 9;
|
||||
gzip_types text/plain application/x-javascript text/javascript application/x-httpd-php text/css text/xml text/jsp application/eot application/ttf application/otf application/svg application/woff application/javascript application/xml image/jpeg image/gif image/png;
|
||||
gzip_vary on;
|
||||
gzip_disable "MSIE [1-6].";
|
||||
|
||||
server {
|
||||
listen 20081;
|
||||
server_name localhost;
|
||||
|
||||
location ^~/znzq {
|
||||
proxy_pass http://127.0.0.1:8080/znzq;
|
||||
proxy_set_header Host 127.0.0.1;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
}
|
||||
|
||||
location /znzq/websocket {
|
||||
proxy_pass http://127.0.0.1:8080/znzq/websocket;
|
||||
proxy_http_version 1.1;
|
||||
proxy_connect_timeout 3600s;
|
||||
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
}
|
||||
|
||||
location / {
|
||||
root /usr/share/nginx/html/;
|
||||
index index.html index.htm;
|
||||
if (!-e $request_filename) {
|
||||
rewrite ^(.*)$ /index.html?s=$1last;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
}
|
||||
1
hs-im-server/build/hd-glasses-app/dist/css/10.619efbf9.css
vendored
Normal file
1
hs-im-server/build/hd-glasses-app/dist/css/10.619efbf9.css
vendored
Normal file
File diff suppressed because one or more lines are too long
1
hs-im-server/build/hd-glasses-app/dist/css/app.c4c80034.css
vendored
Normal file
1
hs-im-server/build/hd-glasses-app/dist/css/app.c4c80034.css
vendored
Normal file
@@ -0,0 +1 @@
|
||||
#app{font-family:Avenir,Helvetica,Arial,sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-align:center;color:#2c3e50;margin-top:.8rem}
|
||||
1
hs-im-server/build/hd-glasses-app/dist/css/chunk-vendors.fda3ab26.css
vendored
Normal file
1
hs-im-server/build/hd-glasses-app/dist/css/chunk-vendors.fda3ab26.css
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
hs-im-server/build/hd-glasses-app/dist/favicon.ico
vendored
Normal file
BIN
hs-im-server/build/hd-glasses-app/dist/favicon.ico
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
1
hs-im-server/build/hd-glasses-app/dist/index.html
vendored
Normal file
1
hs-im-server/build/hd-glasses-app/dist/index.html
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no"><link rel="icon" href="/favicon.ico"><script src="srs/adapter-7.4.0.min.js"></script><script src="srs/srs.sdk.js"></script><script src="srs/srs.sig.js"></script><title>hd-glasses-app</title><script defer="defer" src="/js/chunk-vendors.fc919775.js"></script><script defer="defer" src="/js/app.147e4095.js"></script><link href="/css/chunk-vendors.fda3ab26.css" rel="stylesheet"><link href="/css/app.c4c80034.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but hd-glasses-app doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
|
||||
2
hs-im-server/build/hd-glasses-app/dist/js/10.bf685dc9.js
vendored
Normal file
2
hs-im-server/build/hd-glasses-app/dist/js/10.bf685dc9.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
hs-im-server/build/hd-glasses-app/dist/js/10.bf685dc9.js.map
vendored
Normal file
1
hs-im-server/build/hd-glasses-app/dist/js/10.bf685dc9.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
2
hs-im-server/build/hd-glasses-app/dist/js/618.c04067b7.js
vendored
Normal file
2
hs-im-server/build/hd-glasses-app/dist/js/618.c04067b7.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";(self["webpackChunkhd_glasses_app"]=self["webpackChunkhd_glasses_app"]||[]).push([[618],{3618:function(e,t,n){n.r(t),n.d(t,{default:function(){return u}});var r=function(){var e=this,t=e._self._c;return t("div",[t("h1",[e._v("call_room")]),t("video",{attrs:{id:"rtc_media_player",width:"310",autoplay:"",muted:"",controls:""},domProps:{muted:!0}})])},l=[],o={name:"call_room",data(){return{}},mounted(){let e=new SrsRtcPlayerAsync;var t="webrtc://192.168.2.180/live/test123";e.play(t).then((function(e){console.log(e)})).catch((function(e){console.error(e)}))},methods:{}},a=o,s=n(3736),c=(0,s.Z)(a,r,l,!1,null,"15949eed",null),u=c.exports}}]);
|
||||
//# sourceMappingURL=618.c04067b7.js.map
|
||||
1
hs-im-server/build/hd-glasses-app/dist/js/618.c04067b7.js.map
vendored
Normal file
1
hs-im-server/build/hd-glasses-app/dist/js/618.c04067b7.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"js/618.c04067b7.js","mappings":"wKAAA,IAAIA,EAAS,WAAkB,IAAIC,EAAIC,KAAKC,EAAGF,EAAIG,MAAMD,GAAG,OAAOA,EAAG,MAAM,CAACA,EAAG,KAAK,CAACF,EAAII,GAAG,eAAeF,EAAG,QAAQ,CAACG,MAAM,CAAC,GAAK,mBAAmB,MAAQ,MAAM,SAAW,GAAG,MAAQ,GAAG,SAAW,IAAIC,SAAS,CAAC,OAAQ,MAC/N,EACIC,EAAkB,GCMtB,GACAC,KAAA,YACAC,IAAAA,GACA,QACA,EACAC,OAAAA,GAEA,IAAAC,EAAA,IAAAC,kBACA,IAAAC,EAAA,sCAEAF,EAAAG,KAAAD,GAAAE,MAAA,SAAAC,GACAC,QAAAC,IAAAF,EAGA,IAAAG,OAAA,SAAAC,GAIAH,QAAAI,MAAAD,EACA,GAEA,EACAE,QAAA,IC9BuR,I,UCOnRC,GAAY,OACd,EACAxB,EACAQ,GACA,EACA,KACA,WACA,MAIF,EAAegB,EAAiB,O","sources":["webpack://hd-glasses-app/./src/pages/call_room.vue","webpack://hd-glasses-app/src/pages/call_room.vue","webpack://hd-glasses-app/./src/pages/call_room.vue?c4ef","webpack://hd-glasses-app/./src/pages/call_room.vue?15fd"],"sourcesContent":["var render = function render(){var _vm=this,_c=_vm._self._c;return _c('div',[_c('h1',[_vm._v(\"call_room\")]),_c('video',{attrs:{\"id\":\"rtc_media_player\",\"width\":\"310\",\"autoplay\":\"\",\"muted\":\"\",\"controls\":\"\"},domProps:{\"muted\":true}})])\n}\nvar staticRenderFns = []\n\nexport { render, staticRenderFns }","<template>\r\n <div>\r\n <h1>call_room</h1>\r\n <video id=\"rtc_media_player\" width=\"310\" autoplay muted controls></video>\r\n </div>\r\n</template>\r\n\r\n<script>\r\nexport default {\r\n name: \"call_room\",\r\n data() {\r\n return {};\r\n },\r\n mounted() {\r\n // eslint-disable-next-line no-undef\r\n let player = new SrsRtcPlayerAsync();\r\n var url = 'webrtc://192.168.2.180/live/test123';\r\n\r\n player.play(url).then(function(session){\r\n console.log(session);\r\n // ui.children('#peer').text('Peer: ' + url);\r\n // video.prop('muted', false);\r\n }).catch(function (reason) {\r\n\r\n // player.close();\r\n // video.hide();\r\n console.error(reason);\r\n });\r\n\r\n },\r\n methods: {}\r\n}\r\n</script>\r\n\r\n<style scoped>\r\n\r\n</style>\r\n","import mod from \"-!../../node_modules/thread-loader/dist/cjs.js!../../node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!../../node_modules/@vue/cli-service/node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./call_room.vue?vue&type=script&lang=js&\"; export default mod; export * from \"-!../../node_modules/thread-loader/dist/cjs.js!../../node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!../../node_modules/@vue/cli-service/node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./call_room.vue?vue&type=script&lang=js&\"","import { render, staticRenderFns } from \"./call_room.vue?vue&type=template&id=15949eed&scoped=true&\"\nimport script from \"./call_room.vue?vue&type=script&lang=js&\"\nexport * from \"./call_room.vue?vue&type=script&lang=js&\"\n\n\n/* normalize component */\nimport normalizer from \"!../../node_modules/@vue/cli-service/node_modules/@vue/vue-loader-v15/lib/runtime/componentNormalizer.js\"\nvar component = normalizer(\n script,\n render,\n staticRenderFns,\n false,\n null,\n \"15949eed\",\n null\n \n)\n\nexport default component.exports"],"names":["render","_vm","this","_c","_self","_v","attrs","domProps","staticRenderFns","name","data","mounted","player","SrsRtcPlayerAsync","url","play","then","session","console","log","catch","reason","error","methods","component"],"sourceRoot":""}
|
||||
2
hs-im-server/build/hd-glasses-app/dist/js/app.147e4095.js
vendored
Normal file
2
hs-im-server/build/hd-glasses-app/dist/js/app.147e4095.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
hs-im-server/build/hd-glasses-app/dist/js/app.147e4095.js.map
vendored
Normal file
1
hs-im-server/build/hd-glasses-app/dist/js/app.147e4095.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
2
hs-im-server/build/hd-glasses-app/dist/js/chunk-vendors.fc919775.js
vendored
Normal file
2
hs-im-server/build/hd-glasses-app/dist/js/chunk-vendors.fc919775.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
hs-im-server/build/hd-glasses-app/dist/js/chunk-vendors.fc919775.js.map
vendored
Normal file
1
hs-im-server/build/hd-glasses-app/dist/js/chunk-vendors.fc919775.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
1
hs-im-server/build/hd-glasses-app/dist/srs/adapter-7.4.0.min.js
vendored
Normal file
1
hs-im-server/build/hd-glasses-app/dist/srs/adapter-7.4.0.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
535
hs-im-server/build/hd-glasses-app/dist/srs/srs.sdk.js
vendored
Normal file
535
hs-im-server/build/hd-glasses-app/dist/srs/srs.sdk.js
vendored
Normal file
@@ -0,0 +1,535 @@
|
||||
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2013-2021 Winlin
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
// Depends on adapter-7.4.0.min.js from https://github.com/webrtc/adapter
|
||||
// Async-awat-prmise based SRS RTC Publisher.
|
||||
function SrsRtcPublisherAsync() {
|
||||
var self = {};
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia
|
||||
self.constraints = {
|
||||
audio: true,
|
||||
video: {
|
||||
width: {ideal: 320, max: 576}
|
||||
}
|
||||
};
|
||||
|
||||
// @see https://github.com/rtcdn/rtcdn-draft
|
||||
// @url The WebRTC url to play with, for example:
|
||||
// webrtc://r.ossrs.net/live/livestream
|
||||
// or specifies the API port:
|
||||
// webrtc://r.ossrs.net:11985/live/livestream
|
||||
// or autostart the publish:
|
||||
// webrtc://r.ossrs.net/live/livestream?autostart=true
|
||||
// or change the app from live to myapp:
|
||||
// webrtc://r.ossrs.net:11985/myapp/livestream
|
||||
// or change the stream from livestream to mystream:
|
||||
// webrtc://r.ossrs.net:11985/live/mystream
|
||||
// or set the api server to myapi.domain.com:
|
||||
// webrtc://myapi.domain.com/live/livestream
|
||||
// or set the candidate(ip) of answer:
|
||||
// webrtc://r.ossrs.net/live/livestream?eip=39.107.238.185
|
||||
// or force to access https API:
|
||||
// webrtc://r.ossrs.net/live/livestream?schema=https
|
||||
// or use plaintext, without SRTP:
|
||||
// webrtc://r.ossrs.net/live/livestream?encrypt=false
|
||||
// or any other information, will pass-by in the query:
|
||||
// webrtc://r.ossrs.net/live/livestream?vhost=xxx
|
||||
// webrtc://r.ossrs.net/live/livestream?token=xxx
|
||||
self.publish = async function (url) {
|
||||
var conf = self.__internal.prepareUrl(url);
|
||||
self.pc.addTransceiver("audio", {direction: "sendonly"});
|
||||
self.pc.addTransceiver("video", {direction: "sendonly"});
|
||||
|
||||
var stream = await navigator.mediaDevices.getUserMedia(self.constraints);
|
||||
|
||||
// @see https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/addStream#Migrating_to_addTrack
|
||||
stream.getTracks().forEach(function (track) {
|
||||
self.pc.addTrack(track);
|
||||
|
||||
// Notify about local track when stream is ok.
|
||||
self.ontrack && self.ontrack({track: track});
|
||||
});
|
||||
|
||||
var offer = await self.pc.createOffer();
|
||||
await self.pc.setLocalDescription(offer);
|
||||
var session = await new Promise(function (resolve, reject) {
|
||||
// @see https://github.com/rtcdn/rtcdn-draft
|
||||
var data = {
|
||||
api: conf.apiUrl, tid: conf.tid, streamurl: conf.streamUrl,
|
||||
clientip: null, sdp: offer.sdp
|
||||
};
|
||||
console.log("Generated offer: ", data);
|
||||
|
||||
$.ajax({
|
||||
type: "POST", url: conf.apiUrl, data: JSON.stringify(data),
|
||||
contentType: 'application/json', dataType: 'json'
|
||||
}).done(function (data) {
|
||||
console.log("Got answer: ", data);
|
||||
if (data.code) {
|
||||
reject(data);
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(data);
|
||||
}).fail(function (reason) {
|
||||
reject(reason);
|
||||
});
|
||||
});
|
||||
await self.pc.setRemoteDescription(
|
||||
new RTCSessionDescription({type: 'answer', sdp: session.sdp})
|
||||
);
|
||||
session.simulator = conf.schema + '//' + conf.urlObject.server + ':' + conf.port + '/rtc/v1/nack/';
|
||||
|
||||
return session;
|
||||
};
|
||||
|
||||
// Close the publisher.
|
||||
self.close = function () {
|
||||
self.pc && self.pc.close();
|
||||
self.pc = null;
|
||||
};
|
||||
|
||||
// The callback when got local stream.
|
||||
// @see https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/addStream#Migrating_to_addTrack
|
||||
self.ontrack = function (event) {
|
||||
// Add track to stream of SDK.
|
||||
self.stream.addTrack(event.track);
|
||||
};
|
||||
|
||||
// Internal APIs.
|
||||
self.__internal = {
|
||||
defaultPath: '/rtc/v1/publish/',
|
||||
prepareUrl: function (webrtcUrl) {
|
||||
var urlObject = self.__internal.parse(webrtcUrl);
|
||||
|
||||
// If user specifies the schema, use it as API schema.
|
||||
var schema = urlObject.user_query.schema;
|
||||
schema = schema ? schema + ':' : window.location.protocol;
|
||||
|
||||
var port = urlObject.port || 1985;
|
||||
if (schema === 'https:') {
|
||||
port = urlObject.port || 443;
|
||||
}
|
||||
|
||||
// @see https://github.com/rtcdn/rtcdn-draft
|
||||
var api = urlObject.user_query.play || self.__internal.defaultPath;
|
||||
if (api.lastIndexOf('/') !== api.length - 1) {
|
||||
api += '/';
|
||||
}
|
||||
|
||||
apiUrl = schema + '//' + urlObject.server + ':' + port + api;
|
||||
for (var key in urlObject.user_query) {
|
||||
if (key !== 'api' && key !== 'play') {
|
||||
apiUrl += '&' + key + '=' + urlObject.user_query[key];
|
||||
}
|
||||
}
|
||||
// Replace /rtc/v1/play/&k=v to /rtc/v1/play/?k=v
|
||||
var apiUrl = apiUrl.replace(api + '&', api + '?');
|
||||
|
||||
var streamUrl = urlObject.url;
|
||||
|
||||
return {
|
||||
apiUrl: apiUrl, streamUrl: streamUrl, schema: schema, urlObject: urlObject, port: port,
|
||||
tid: Number(parseInt(new Date().getTime()*Math.random()*100)).toString(16).slice(0, 7)
|
||||
};
|
||||
},
|
||||
parse: function (url) {
|
||||
// @see: http://stackoverflow.com/questions/10469575/how-to-use-location-object-to-parse-url-without-redirecting-the-page-in-javascri
|
||||
var a = document.createElement("a");
|
||||
a.href = url.replace("rtmp://", "http://")
|
||||
.replace("webrtc://", "http://")
|
||||
.replace("rtc://", "http://");
|
||||
|
||||
var vhost = a.hostname;
|
||||
var app = a.pathname.substring(1, a.pathname.lastIndexOf("/"));
|
||||
var stream = a.pathname.slice(a.pathname.lastIndexOf("/") + 1);
|
||||
|
||||
// parse the vhost in the params of app, that srs supports.
|
||||
app = app.replace("...vhost...", "?vhost=");
|
||||
if (app.indexOf("?") >= 0) {
|
||||
var params = app.slice(app.indexOf("?"));
|
||||
app = app.slice(0, app.indexOf("?"));
|
||||
|
||||
if (params.indexOf("vhost=") > 0) {
|
||||
vhost = params.slice(params.indexOf("vhost=") + "vhost=".length);
|
||||
if (vhost.indexOf("&") > 0) {
|
||||
vhost = vhost.slice(0, vhost.indexOf("&"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// when vhost equals to server, and server is ip,
|
||||
// the vhost is __defaultVhost__
|
||||
if (a.hostname === vhost) {
|
||||
var re = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;
|
||||
if (re.test(a.hostname)) {
|
||||
vhost = "__defaultVhost__";
|
||||
}
|
||||
}
|
||||
|
||||
// parse the schema
|
||||
var schema = "rtmp";
|
||||
if (url.indexOf("://") > 0) {
|
||||
schema = url.slice(0, url.indexOf("://"));
|
||||
}
|
||||
|
||||
var port = a.port;
|
||||
if (!port) {
|
||||
if (schema === 'http') {
|
||||
port = 80;
|
||||
} else if (schema === 'https') {
|
||||
port = 443;
|
||||
} else if (schema === 'rtmp') {
|
||||
port = 1935;
|
||||
}
|
||||
}
|
||||
|
||||
var ret = {
|
||||
url: url,
|
||||
schema: schema,
|
||||
server: a.hostname, port: port,
|
||||
vhost: vhost, app: app, stream: stream
|
||||
};
|
||||
self.__internal.fill_query(a.search, ret);
|
||||
|
||||
// For webrtc API, we use 443 if page is https, or schema specified it.
|
||||
if (!ret.port) {
|
||||
if (schema === 'webrtc' || schema === 'rtc') {
|
||||
if (ret.user_query.schema === 'https') {
|
||||
ret.port = 443;
|
||||
} else if (window.location.href.indexOf('https://') === 0) {
|
||||
ret.port = 443;
|
||||
} else {
|
||||
// For WebRTC, SRS use 1985 as default API port.
|
||||
ret.port = 1985;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
},
|
||||
fill_query: function (query_string, obj) {
|
||||
// pure user query object.
|
||||
obj.user_query = {};
|
||||
|
||||
if (query_string.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// split again for angularjs.
|
||||
if (query_string.indexOf("?") >= 0) {
|
||||
query_string = query_string.split("?")[1];
|
||||
}
|
||||
|
||||
var queries = query_string.split("&");
|
||||
for (var i = 0; i < queries.length; i++) {
|
||||
var elem = queries[i];
|
||||
|
||||
var query = elem.split("=");
|
||||
obj[query[0]] = query[1];
|
||||
obj.user_query[query[0]] = query[1];
|
||||
}
|
||||
|
||||
// alias domain for vhost.
|
||||
if (obj.domain) {
|
||||
obj.vhost = obj.domain;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
self.pc = new RTCPeerConnection(null);
|
||||
|
||||
// To keep api consistent between player and publisher.
|
||||
// @see https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/addStream#Migrating_to_addTrack
|
||||
// @see https://webrtc.org/getting-started/media-devices
|
||||
self.stream = new MediaStream();
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
// Depends on adapter-7.4.0.min.js from https://github.com/webrtc/adapter
|
||||
// Async-await-promise based SRS RTC Player.
|
||||
function SrsRtcPlayerAsync() {
|
||||
var self = {};
|
||||
|
||||
// @see https://github.com/rtcdn/rtcdn-draft
|
||||
// @url The WebRTC url to play with, for example:
|
||||
// webrtc://r.ossrs.net/live/livestream
|
||||
// or specifies the API port:
|
||||
// webrtc://r.ossrs.net:11985/live/livestream
|
||||
// or autostart the play:
|
||||
// webrtc://r.ossrs.net/live/livestream?autostart=true
|
||||
// or change the app from live to myapp:
|
||||
// webrtc://r.ossrs.net:11985/myapp/livestream
|
||||
// or change the stream from livestream to mystream:
|
||||
// webrtc://r.ossrs.net:11985/live/mystream
|
||||
// or set the api server to myapi.domain.com:
|
||||
// webrtc://myapi.domain.com/live/livestream
|
||||
// or set the candidate(ip) of answer:
|
||||
// webrtc://r.ossrs.net/live/livestream?eip=39.107.238.185
|
||||
// or force to access https API:
|
||||
// webrtc://r.ossrs.net/live/livestream?schema=https
|
||||
// or use plaintext, without SRTP:
|
||||
// webrtc://r.ossrs.net/live/livestream?encrypt=false
|
||||
// or any other information, will pass-by in the query:
|
||||
// webrtc://r.ossrs.net/live/livestream?vhost=xxx
|
||||
// webrtc://r.ossrs.net/live/livestream?token=xxx
|
||||
self.play = async function(url) {
|
||||
var conf = self.__internal.prepareUrl(url);
|
||||
self.pc.addTransceiver("audio", {direction: "recvonly"});
|
||||
self.pc.addTransceiver("video", {direction: "recvonly"});
|
||||
|
||||
var offer = await self.pc.createOffer();
|
||||
await self.pc.setLocalDescription(offer);
|
||||
var session = await new Promise(function(resolve, reject) {
|
||||
// @see https://github.com/rtcdn/rtcdn-draft
|
||||
var data = {
|
||||
api: conf.apiUrl, tid: conf.tid, streamurl: conf.streamUrl,
|
||||
clientip: null, sdp: offer.sdp
|
||||
};
|
||||
console.log("Generated offer: ", data);
|
||||
|
||||
$.ajax({
|
||||
type: "POST", url: conf.apiUrl, data: JSON.stringify(data),
|
||||
contentType:'application/json', dataType: 'json'
|
||||
}).done(function(data) {
|
||||
console.log("Got answer: ", data);
|
||||
if (data.code) {
|
||||
reject(data); return;
|
||||
}
|
||||
|
||||
resolve(data);
|
||||
}).fail(function(reason){
|
||||
reject(reason);
|
||||
});
|
||||
});
|
||||
await self.pc.setRemoteDescription(
|
||||
new RTCSessionDescription({type: 'answer', sdp: session.sdp})
|
||||
);
|
||||
session.simulator = conf.schema + '//' + conf.urlObject.server + ':' + conf.port + '/rtc/v1/nack/';
|
||||
return session;
|
||||
};
|
||||
|
||||
// Close the player.
|
||||
self.close = function() {
|
||||
self.pc && self.pc.close();
|
||||
self.pc = null;
|
||||
};
|
||||
|
||||
// The callback when got remote track.
|
||||
// Note that the onaddstream is deprecated, @see https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/onaddstream
|
||||
self.ontrack = function (event) {
|
||||
// https://webrtc.org/getting-started/remote-streams
|
||||
self.stream.addTrack(event.track);
|
||||
};
|
||||
|
||||
// Internal APIs.
|
||||
self.__internal = {
|
||||
defaultPath: '/rtc/v1/play/',
|
||||
prepareUrl: function (webrtcUrl) {
|
||||
var urlObject = self.__internal.parse(webrtcUrl);
|
||||
|
||||
// If user specifies the schema, use it as API schema.
|
||||
var schema = urlObject.user_query.schema;
|
||||
schema = schema ? schema + ':' : window.location.protocol;
|
||||
|
||||
var port = urlObject.port || 1985;
|
||||
if (schema === 'https:') {
|
||||
port = urlObject.port || 443;
|
||||
}
|
||||
|
||||
// @see https://github.com/rtcdn/rtcdn-draft
|
||||
var api = urlObject.user_query.play || self.__internal.defaultPath;
|
||||
if (api.lastIndexOf('/') !== api.length - 1) {
|
||||
api += '/';
|
||||
}
|
||||
|
||||
apiUrl = schema + '//' + urlObject.server + ':' + port + api;
|
||||
for (var key in urlObject.user_query) {
|
||||
if (key !== 'api' && key !== 'play') {
|
||||
apiUrl += '&' + key + '=' + urlObject.user_query[key];
|
||||
}
|
||||
}
|
||||
// Replace /rtc/v1/play/&k=v to /rtc/v1/play/?k=v
|
||||
var apiUrl = apiUrl.replace(api + '&', api + '?');
|
||||
|
||||
var streamUrl = urlObject.url;
|
||||
|
||||
return {
|
||||
apiUrl: apiUrl, streamUrl: streamUrl, schema: schema, urlObject: urlObject, port: port,
|
||||
tid: Number(parseInt(new Date().getTime()*Math.random()*100)).toString(16).slice(0, 7)
|
||||
};
|
||||
},
|
||||
parse: function (url) {
|
||||
// @see: http://stackoverflow.com/questions/10469575/how-to-use-location-object-to-parse-url-without-redirecting-the-page-in-javascri
|
||||
var a = document.createElement("a");
|
||||
a.href = url.replace("rtmp://", "http://")
|
||||
.replace("webrtc://", "http://")
|
||||
.replace("rtc://", "http://");
|
||||
|
||||
var vhost = a.hostname;
|
||||
var app = a.pathname.substring(1, a.pathname.lastIndexOf("/"));
|
||||
var stream = a.pathname.slice(a.pathname.lastIndexOf("/") + 1);
|
||||
|
||||
// parse the vhost in the params of app, that srs supports.
|
||||
app = app.replace("...vhost...", "?vhost=");
|
||||
if (app.indexOf("?") >= 0) {
|
||||
var params = app.slice(app.indexOf("?"));
|
||||
app = app.slice(0, app.indexOf("?"));
|
||||
|
||||
if (params.indexOf("vhost=") > 0) {
|
||||
vhost = params.slice(params.indexOf("vhost=") + "vhost=".length);
|
||||
if (vhost.indexOf("&") > 0) {
|
||||
vhost = vhost.slice(0, vhost.indexOf("&"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// when vhost equals to server, and server is ip,
|
||||
// the vhost is __defaultVhost__
|
||||
if (a.hostname === vhost) {
|
||||
var re = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;
|
||||
if (re.test(a.hostname)) {
|
||||
vhost = "__defaultVhost__";
|
||||
}
|
||||
}
|
||||
|
||||
// parse the schema
|
||||
var schema = "rtmp";
|
||||
if (url.indexOf("://") > 0) {
|
||||
schema = url.slice(0, url.indexOf("://"));
|
||||
}
|
||||
|
||||
var port = a.port;
|
||||
if (!port) {
|
||||
if (schema === 'http') {
|
||||
port = 80;
|
||||
} else if (schema === 'https') {
|
||||
port = 443;
|
||||
} else if (schema === 'rtmp') {
|
||||
port = 1935;
|
||||
}
|
||||
}
|
||||
|
||||
var ret = {
|
||||
url: url,
|
||||
schema: schema,
|
||||
server: a.hostname, port: port,
|
||||
vhost: vhost, app: app, stream: stream
|
||||
};
|
||||
self.__internal.fill_query(a.search, ret);
|
||||
|
||||
// For webrtc API, we use 443 if page is https, or schema specified it.
|
||||
if (!ret.port) {
|
||||
if (schema === 'webrtc' || schema === 'rtc') {
|
||||
if (ret.user_query.schema === 'https') {
|
||||
ret.port = 443;
|
||||
} else if (window.location.href.indexOf('https://') === 0) {
|
||||
ret.port = 443;
|
||||
} else {
|
||||
// For WebRTC, SRS use 1985 as default API port.
|
||||
ret.port = 1985;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
},
|
||||
fill_query: function (query_string, obj) {
|
||||
// pure user query object.
|
||||
obj.user_query = {};
|
||||
|
||||
if (query_string.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// split again for angularjs.
|
||||
if (query_string.indexOf("?") >= 0) {
|
||||
query_string = query_string.split("?")[1];
|
||||
}
|
||||
|
||||
var queries = query_string.split("&");
|
||||
for (var i = 0; i < queries.length; i++) {
|
||||
var elem = queries[i];
|
||||
|
||||
var query = elem.split("=");
|
||||
obj[query[0]] = query[1];
|
||||
obj.user_query[query[0]] = query[1];
|
||||
}
|
||||
|
||||
// alias domain for vhost.
|
||||
if (obj.domain) {
|
||||
obj.vhost = obj.domain;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
self.pc = new RTCPeerConnection(null);
|
||||
|
||||
// Create a stream to add track to the stream, @see https://webrtc.org/getting-started/remote-streams
|
||||
self.stream = new MediaStream();
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/ontrack
|
||||
self.pc.ontrack = function(event) {
|
||||
if (self.ontrack) {
|
||||
self.ontrack(event);
|
||||
}
|
||||
};
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
// Format the codec of RTCRtpSender, kind(audio/video) is optional filter.
|
||||
// https://developer.mozilla.org/en-US/docs/Web/Media/Formats/WebRTC_codecs#getting_the_supported_codecs
|
||||
function SrsRtcFormatSenders(senders, kind) {
|
||||
var codecs = [];
|
||||
senders.forEach(function (sender) {
|
||||
var params = sender.getParameters();
|
||||
params && params.codecs && params.codecs.forEach(function(c) {
|
||||
if (kind && sender.track.kind !== kind) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (c.mimeType.indexOf('/red') > 0 || c.mimeType.indexOf('/rtx') > 0 || c.mimeType.indexOf('/fec') > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
var s = '';
|
||||
|
||||
s += c.mimeType.replace('audio/', '').replace('video/', '');
|
||||
s += ', ' + c.clockRate + 'HZ';
|
||||
if (sender.track.kind === "audio") {
|
||||
s += ', channels: ' + c.channels;
|
||||
}
|
||||
s += ', pt: ' + c.payloadType;
|
||||
|
||||
codecs.push(s);
|
||||
});
|
||||
});
|
||||
return codecs.join(", ");
|
||||
}
|
||||
|
||||
148
hs-im-server/build/hd-glasses-app/dist/srs/srs.sig.js
vendored
Normal file
148
hs-im-server/build/hd-glasses-app/dist/srs/srs.sig.js
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2013-2021 Winlin
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
// Async-await-promise based SRS RTC Signaling.
|
||||
function SrsRtcSignalingAsync() {
|
||||
var self = {};
|
||||
|
||||
// The schema is ws or wss, host is ip or ip:port, display is nickname
|
||||
// of user to join the room.
|
||||
self.connect = async function (schema, host, room, display) {
|
||||
var url = schema + '://' + host + '/sig/v1/rtc';
|
||||
self.ws = new WebSocket(url + '?room=' + room + '&display=' + display);
|
||||
|
||||
self.ws.onmessage = function(event) {
|
||||
var r = JSON.parse(event.data);
|
||||
var promise = self._internals.msgs[r.tid];
|
||||
if (promise) {
|
||||
promise.resolve(r.msg);
|
||||
delete self._internals.msgs[r.tid];
|
||||
} else {
|
||||
self.onmessage(r.msg);
|
||||
}
|
||||
};
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
self.ws.onopen = function (event) {
|
||||
resolve(event);
|
||||
};
|
||||
|
||||
self.ws.onerror = function (event) {
|
||||
reject(event);
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
// The message is a json object.
|
||||
self.send = async function (message) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var r = {tid: Number(parseInt(new Date().getTime()*Math.random()*100)).toString(16).slice(0, 7), msg: message};
|
||||
self._internals.msgs[r.tid] = {resolve: resolve, reject: reject};
|
||||
self.ws.send(JSON.stringify(r));
|
||||
});
|
||||
};
|
||||
|
||||
self.close = function () {
|
||||
self.ws && self.ws.close();
|
||||
self.ws = null;
|
||||
|
||||
for (const tid in self._internals.msgs) {
|
||||
var promise = self._internals.msgs[tid];
|
||||
promise.reject('close');
|
||||
}
|
||||
};
|
||||
|
||||
// The callback when got messages from signaling server.
|
||||
self.onmessage = function (msg) {
|
||||
};
|
||||
|
||||
self._internals = {
|
||||
// Key is tid, value is object {resolve, reject, response}.
|
||||
msgs: {}
|
||||
};
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
// Parse params in query string.
|
||||
function SrsRtcSignalingParse(location) {
|
||||
let query = location.href.split('?')[1];
|
||||
query = query? '?' + query : null;
|
||||
|
||||
let wsSchema = location.href.split('wss=')[1];
|
||||
wsSchema = wsSchema? wsSchema.split('&')[0] : (location.protocol === 'http:'? 'ws' : 'wss');
|
||||
|
||||
let wsHost = location.href.split('wsh=')[1];
|
||||
wsHost = wsHost? wsHost.split('&')[0] : location.hostname;
|
||||
|
||||
let wsPort = location.href.split('wsp=')[1];
|
||||
wsPort = wsPort? wsPort.split('&')[0] : location.host.split(':')[1];
|
||||
|
||||
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] : Number(parseInt(new Date().getTime()*Math.random()*100)).toString(16).toString(16).slice(0, 7);
|
||||
|
||||
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.slice(0, query.length - 1);
|
||||
}
|
||||
if (query.lastIndexOf('&') === query.length - 1) {
|
||||
query = query.slice(0, query.length - 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Regenerate the host of websocket.
|
||||
wsHost = wsPort? wsHost.split(':')[0] + ':' + wsPort : wsHost;
|
||||
|
||||
return {
|
||||
query: query, rawQuery: rawQuery, wsSchema: wsSchema, wsHost: wsHost, host: host,
|
||||
room: room, display: display, autostart: autostart,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user