webrtc-streamer 0.8.3 → 0.8.4-2-g68e8d8e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/html/admin.html +1 -1
- package/html/styles.css +5 -0
- package/html/webrtcstreamer.html +8 -4
- package/html/webrtcstreamer.js +24 -7
- package/package.json +1 -1
package/html/admin.html
CHANGED
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
let streamid = "";
|
|
76
76
|
let frameHeight = 0;
|
|
77
77
|
let frameWidth = 0;
|
|
78
|
-
if (peerConnection && peerConnection.hasOwnProperty("streams")){
|
|
78
|
+
if (peerConnection && peerConnection.hasOwnProperty("streams") && peerConnection.streams){
|
|
79
79
|
streamid = Object.keys(peerConnection.streams)[0];
|
|
80
80
|
|
|
81
81
|
var stream = Object.values(peerConnection.streams)[0];
|
package/html/styles.css
CHANGED
package/html/webrtcstreamer.html
CHANGED
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
<script src="webrtcstreamer.js" ></script>
|
|
7
7
|
<script>
|
|
8
8
|
if (location.search.slice(1)) {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
let url = { video:location.search.slice(1) };
|
|
10
|
+
let options = webrtcConfig.options;
|
|
11
|
+
let codec = webrtcConfig.codec;
|
|
11
12
|
if (typeof URLSearchParams != 'undefined') {
|
|
12
13
|
var params = new URLSearchParams(location.search);
|
|
13
14
|
if (params.has("video") || params.has("audio")) {
|
|
@@ -16,11 +17,14 @@
|
|
|
16
17
|
if (params.has("options")) {
|
|
17
18
|
options = params.get("options");
|
|
18
19
|
}
|
|
20
|
+
if (params.has("codec")) {
|
|
21
|
+
codec = params.get("codec");
|
|
22
|
+
}
|
|
19
23
|
}
|
|
20
24
|
window.onload = function() {
|
|
21
25
|
this.webRtcServer = new WebRtcStreamer("video", webrtcConfig.url);
|
|
22
|
-
document.getElementById("title").
|
|
23
|
-
webRtcServer.connect(url.video,url.audio,options);
|
|
26
|
+
document.getElementById("title").innerText = url.video;
|
|
27
|
+
webRtcServer.connect(url.video, url.audio, options, undefined, codec);
|
|
24
28
|
fetch(webrtcConfig.url + "/api/version").then(r => r.text()).then( (response) => {
|
|
25
29
|
document.getElementById("footer").innerHTML = "<p><a href='https://github.com/mpromonet/webrtc-streamer'>WebRTC-Streamer</a> " + response.split(" ")[0] + "</p>";
|
|
26
30
|
});
|
package/html/webrtcstreamer.js
CHANGED
|
@@ -32,10 +32,11 @@ WebRtcStreamer.prototype._handleHttpErrors = function (response) {
|
|
|
32
32
|
* Connect a WebRTC Stream to videoElement
|
|
33
33
|
* @param {string} videourl - id of WebRTC video stream
|
|
34
34
|
* @param {string} audiourl - id of WebRTC audio stream
|
|
35
|
-
* @param {string} options
|
|
36
|
-
* @param {string} stream
|
|
35
|
+
* @param {string} options - options of WebRTC call
|
|
36
|
+
* @param {string} stream - local stream to send
|
|
37
|
+
* @param {string} prefmime - prefered mime
|
|
37
38
|
*/
|
|
38
|
-
WebRtcStreamer.prototype.connect = function(videourl, audiourl, options, localstream) {
|
|
39
|
+
WebRtcStreamer.prototype.connect = function(videourl, audiourl, options, localstream, prefmime) {
|
|
39
40
|
this.disconnect();
|
|
40
41
|
|
|
41
42
|
// getIceServers is not already received
|
|
@@ -45,11 +46,11 @@ WebRtcStreamer.prototype.connect = function(videourl, audiourl, options, localst
|
|
|
45
46
|
fetch(this.srvurl + "/api/getIceServers")
|
|
46
47
|
.then(this._handleHttpErrors)
|
|
47
48
|
.then( (response) => (response.json()) )
|
|
48
|
-
.then( (response) => this.onReceiveGetIceServers(response, videourl, audiourl, options, localstream))
|
|
49
|
+
.then( (response) => this.onReceiveGetIceServers(response, videourl, audiourl, options, localstream, prefmime))
|
|
49
50
|
.catch( (error) => this.onError("getIceServers " + error ))
|
|
50
51
|
|
|
51
52
|
} else {
|
|
52
|
-
this.onReceiveGetIceServers(this.iceServers, videourl, audiourl, options, localstream);
|
|
53
|
+
this.onReceiveGetIceServers(this.iceServers, videourl, audiourl, options, localstream, prefmime);
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
|
|
@@ -82,7 +83,7 @@ WebRtcStreamer.prototype.disconnect = function() {
|
|
|
82
83
|
/*
|
|
83
84
|
* GetIceServers callback
|
|
84
85
|
*/
|
|
85
|
-
WebRtcStreamer.prototype.onReceiveGetIceServers = function(iceServers, videourl, audiourl, options, stream) {
|
|
86
|
+
WebRtcStreamer.prototype.onReceiveGetIceServers = function(iceServers, videourl, audiourl, options, stream, prefmime) {
|
|
86
87
|
this.iceServers = iceServers;
|
|
87
88
|
this.pcConfig = iceServers || {"iceServers": [] };
|
|
88
89
|
try {
|
|
@@ -106,6 +107,22 @@ WebRtcStreamer.prototype.onReceiveGetIceServers = function(iceServers, videourl,
|
|
|
106
107
|
// create Offer
|
|
107
108
|
this.pc.createOffer(this.mediaConstraints).then((sessionDescription) => {
|
|
108
109
|
console.log("Create offer:" + JSON.stringify(sessionDescription));
|
|
110
|
+
|
|
111
|
+
if (prefmime != undefined) {
|
|
112
|
+
//set prefered codec
|
|
113
|
+
let [prefkind] = prefmime.split('/');
|
|
114
|
+
let codecs = RTCRtpReceiver.getCapabilities(prefkind).codecs;
|
|
115
|
+
console.log(`codecs:${JSON.stringify(codecs)}`)
|
|
116
|
+
let preferedCodecs = codecs.filter(codec => codec.mimeType === prefmime);
|
|
117
|
+
|
|
118
|
+
console.log(`preferedCodecs:${JSON.stringify(preferedCodecs)}`);
|
|
119
|
+
this.pc.getTransceivers().filter(transceiver => transceiver.receiver.track.kind === prefkind).forEach(tcvr => {
|
|
120
|
+
if(tcvr.setCodecPreferences != undefined) {
|
|
121
|
+
tcvr.setCodecPreferences(preferedCodecs);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
109
126
|
|
|
110
127
|
this.pc.setLocalDescription(sessionDescription)
|
|
111
128
|
.then(() => {
|
|
@@ -146,7 +163,7 @@ WebRtcStreamer.prototype.createPeerConnection = function() {
|
|
|
146
163
|
console.log("createPeerConnection config: " + JSON.stringify(this.pcConfig));
|
|
147
164
|
this.pc = new RTCPeerConnection(this.pcConfig);
|
|
148
165
|
var pc = this.pc;
|
|
149
|
-
pc.peerid = Math.random();
|
|
166
|
+
pc.peerid = Math.random();
|
|
150
167
|
|
|
151
168
|
pc.onicecandidate = (evt) => this.onIceCandidate(evt);
|
|
152
169
|
pc.onaddstream = (evt) => this.onAddStream(evt);
|