Skip to content

Commit 7a13fbe

Browse files
authored
Update react-native-webrtc-web-shim.web.js (#17)
1 parent 43d1247 commit 7a13fbe

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/react-native-webrtc-web-shim.web.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import RTCView from './RTCView';
22

3+
if (typeof window !== "undefined") {
4+
35
window.MediaStream.prototype.release = function release() {
46
this.getTracks().forEach((track) => track.stop());
57
};
@@ -8,6 +10,8 @@ window.MediaStreamTrack.prototype._switchCamera = function _switchCamera() {
810
console.warn('_switchCamera is not implemented on web.');
911
};
1012

13+
}
14+
1115
const {
1216
RTCPeerConnection,
1317
RTCIceCandidate,
@@ -18,13 +22,15 @@ const {
1822
RTCErrorEvent,
1923
MediaStream,
2024
MediaStreamTrack,
21-
} = window;
25+
} = typeof window !== "undefined" ? window : {};
2226

23-
const { mediaDevices, permissions } = navigator;
27+
const { mediaDevices, permissions } = typeof window !== "undefined" ? navigator : {};
2428

2529
function registerGlobals() {
26-
window.mediaDevices = navigator.mediaDevices;
27-
window.permissions = navigator.permissions;
30+
if (typeof window !== "undefined") {
31+
window.mediaDevices = navigator.mediaDevices;
32+
window.permissions = navigator.permissions;
33+
}
2834
}
2935

3036
export {

0 commit comments

Comments
 (0)