Reuse existing WebRTC connection if available
This commit is contained in:
1 parent
0f398328ad
commit
4e92516d78
3 files changed
+27
-2
No files matched your search
@@ -1686,4 +1686,5 @@ var startWebRTC = function (videoElement, streamUrl) {
|
||||
});
|
||||
|
||||
negotiateWebRTC(streamUrl);
|
||||
return pc;
|
||||
};
|
||||
@@ -43,6 +43,7 @@ $(function () {
|
||||
self.webcamHlsEnabled = ko.observable(false);
|
||||
self.webcamWebRTCEnabled = ko.observable(false);
|
||||
self.webcamError = ko.observable(false);
|
||||
self.webRTCPeerConnection = null;
|
||||
|
||||
self.keycontrolActive = ko.observable(false);
|
||||
self.keycontrolHelpActive = ko.observable(false);
|
||||
@@ -739,7 +740,22 @@ $(function () {
|
||||
self._switchToWebRTCWebcam = function () {
|
||||
var video = document.getElementById("webcam_webrtc");
|
||||
|
||||
startWebRTC(video, self.settings.webcam_streamUrl());
|
||||
// Close any existing, disconnected connection
|
||||
if (
|
||||
self.webRTCPeerConnection != null &&
|
||||
self.webRTCPeerConnection.connectionState != "connected"
|
||||
) {
|
||||
self.webRTCPeerConnection.close();
|
||||
self.webRTCPeerConnection = null;
|
||||
}
|
||||
|
||||
// Open a new connection if necessary
|
||||
if (self.webRTCPeerConnection == null) {
|
||||
self.webRTCPeerConnection = startWebRTC(
|
||||
video,
|
||||
self.settings.webcam_streamUrl()
|
||||
);
|
||||
}
|
||||
|
||||
self.webcamMjpgEnabled(false);
|
||||
self.webcamHlsEnabled(false);
|
||||
|
||||
@@ -439,6 +439,7 @@ $(function () {
|
||||
);
|
||||
var streamType = determineWebcamStreamType(self.webcam_streamUrl());
|
||||
var webcam_element;
|
||||
var webrtc_peer_connection;
|
||||
if (streamType == "mjpg") {
|
||||
webcam_element = $('<img src="' + self.webcam_streamUrl() + '">');
|
||||
} else if (streamType == "hls") {
|
||||
@@ -459,7 +460,10 @@ $(function () {
|
||||
);
|
||||
video_element = webcam_element[0];
|
||||
|
||||
startWebRTC(video_element, self.webcam_streamUrl());
|
||||
webrtc_peer_connection = startWebRTC(
|
||||
video_element,
|
||||
self.webcam_streamUrl()
|
||||
);
|
||||
} else {
|
||||
throw "Unknown stream type " + streamType;
|
||||
}
|
||||
@@ -475,6 +479,10 @@ $(function () {
|
||||
message: message,
|
||||
onclose: function () {
|
||||
self.testWebcamStreamUrlBusy(false);
|
||||
if (webrtc_peer_connection != null) {
|
||||
webrtc_peer_connection.close();
|
||||
webrtc_peer_connection = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user