react-native-webrtc 111.0.2 → 111.0.4
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/README.md +13 -10
- package/android/src/main/java/com/oney/WebRTCModule/PeerConnectionObserver.java +18 -0
- package/android/src/main/java/com/oney/WebRTCModule/SerializeUtils.java +1 -1
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +13 -26
- package/ios/RCTWebRTC/CaptureController.m +4 -0
- package/ios/RCTWebRTC/ScreenCaptureController.m +4 -0
- package/ios/RCTWebRTC/ScreenCapturePickerViewManager.m +2 -2
- package/ios/RCTWebRTC/ScreenCapturer.m +4 -0
- package/ios/RCTWebRTC/SerializeUtils.m +12 -10
- package/ios/RCTWebRTC/TrackCapturerEventsEmitter.m +1 -1
- package/ios/RCTWebRTC/VideoCaptureController.h +2 -1
- package/ios/RCTWebRTC/VideoCaptureController.m +3 -0
- package/ios/RCTWebRTC/WebRTCModule+Permissions.m +10 -1
- package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.h +1 -1
- package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m +40 -3
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +30 -19
- package/ios/RCTWebRTC/WebRTCModule.m +3 -1
- package/ios/RCTWebRTC/WebRTCModuleOptions.h +1 -0
- package/ios/RCTWebRTC/WebRTCModuleOptions.m +1 -0
- package/ios/RCTWebRTC.xcodeproj/project.pbxproj +1 -0
- package/lib/commonjs/EventEmitter.js +4 -16
- package/lib/commonjs/EventEmitter.js.map +1 -1
- package/lib/commonjs/Logger.js +2 -26
- package/lib/commonjs/Logger.js.map +1 -1
- package/lib/commonjs/MediaDevices.js +2 -14
- package/lib/commonjs/MediaDevices.js.map +1 -1
- package/lib/commonjs/MediaStream.js +8 -45
- package/lib/commonjs/MediaStream.js.map +1 -1
- package/lib/commonjs/MediaStreamError.js +0 -11
- package/lib/commonjs/MediaStreamError.js.map +1 -1
- package/lib/commonjs/MediaStreamErrorEvent.js +0 -9
- package/lib/commonjs/MediaStreamErrorEvent.js.map +1 -1
- package/lib/commonjs/MediaStreamEvent.js +0 -9
- package/lib/commonjs/MediaStreamEvent.js.map +1 -1
- package/lib/commonjs/MediaStreamTrack.js +6 -65
- package/lib/commonjs/MediaStreamTrack.js.map +1 -1
- package/lib/commonjs/MediaStreamTrackEvent.js +11 -10
- package/lib/commonjs/MediaStreamTrackEvent.js.map +1 -1
- package/lib/commonjs/MessageEvent.js +12 -10
- package/lib/commonjs/MessageEvent.js.map +1 -1
- package/lib/commonjs/Permissions.js +19 -29
- package/lib/commonjs/Permissions.js.map +1 -1
- package/lib/commonjs/RTCDataChannel.js +8 -78
- package/lib/commonjs/RTCDataChannel.js.map +1 -1
- package/lib/commonjs/RTCDataChannelEvent.js +11 -10
- package/lib/commonjs/RTCDataChannelEvent.js.map +1 -1
- package/lib/commonjs/RTCErrorEvent.js +2 -15
- package/lib/commonjs/RTCErrorEvent.js.map +1 -1
- package/lib/commonjs/RTCEvent.js +13 -10
- package/lib/commonjs/RTCEvent.js.map +1 -1
- package/lib/commonjs/RTCIceCandidate.js +0 -14
- package/lib/commonjs/RTCIceCandidate.js.map +1 -1
- package/lib/commonjs/RTCIceCandidateEvent.js +13 -13
- package/lib/commonjs/RTCIceCandidateEvent.js.map +1 -1
- package/lib/commonjs/RTCPeerConnection.js +175 -255
- package/lib/commonjs/RTCPeerConnection.js.map +1 -1
- package/lib/commonjs/RTCRtcpParameters.js +0 -10
- package/lib/commonjs/RTCRtcpParameters.js.map +1 -1
- package/lib/commonjs/RTCRtpCapabilities.js +5 -22
- package/lib/commonjs/RTCRtpCapabilities.js.map +1 -1
- package/lib/commonjs/RTCRtpCodecCapability.js +0 -8
- package/lib/commonjs/RTCRtpCodecCapability.js.map +1 -1
- package/lib/commonjs/RTCRtpCodecParameters.js +0 -19
- package/lib/commonjs/RTCRtpCodecParameters.js.map +1 -1
- package/lib/commonjs/RTCRtpEncodingParameters.js +4 -34
- package/lib/commonjs/RTCRtpEncodingParameters.js.map +1 -1
- package/lib/commonjs/RTCRtpHeaderExtension.js +0 -12
- package/lib/commonjs/RTCRtpHeaderExtension.js.map +1 -1
- package/lib/commonjs/RTCRtpParameters.js +2 -18
- package/lib/commonjs/RTCRtpParameters.js.map +1 -1
- package/lib/commonjs/RTCRtpReceiveParameters.js +0 -5
- package/lib/commonjs/RTCRtpReceiveParameters.js.map +1 -1
- package/lib/commonjs/RTCRtpReceiver.js +1 -26
- package/lib/commonjs/RTCRtpReceiver.js.map +1 -1
- package/lib/commonjs/RTCRtpSendParameters.js +0 -22
- package/lib/commonjs/RTCRtpSendParameters.js.map +1 -1
- package/lib/commonjs/RTCRtpSender.js +1 -30
- package/lib/commonjs/RTCRtpSender.js.map +1 -1
- package/lib/commonjs/RTCRtpTransceiver.js +3 -38
- package/lib/commonjs/RTCRtpTransceiver.js.map +1 -1
- package/lib/commonjs/RTCSessionDescription.js +0 -13
- package/lib/commonjs/RTCSessionDescription.js.map +1 -1
- package/lib/commonjs/RTCTrackEvent.js +16 -14
- package/lib/commonjs/RTCTrackEvent.js.map +1 -1
- package/lib/commonjs/RTCUtil.js +9 -36
- package/lib/commonjs/RTCUtil.js.map +1 -1
- package/lib/commonjs/RTCView.js +6 -3
- package/lib/commonjs/RTCView.js.map +1 -1
- package/lib/commonjs/ScreenCapturePickerView.js +0 -3
- package/lib/commonjs/ScreenCapturePickerView.js.map +1 -1
- package/lib/commonjs/getDisplayMedia.js +0 -6
- package/lib/commonjs/getDisplayMedia.js.map +1 -1
- package/lib/commonjs/getUserMedia.js +7 -28
- package/lib/commonjs/getUserMedia.js.map +1 -1
- package/lib/commonjs/index.js +1 -26
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/EventEmitter.js +5 -12
- package/lib/module/EventEmitter.js.map +1 -1
- package/lib/module/Logger.js +2 -22
- package/lib/module/Logger.js.map +1 -1
- package/lib/module/MediaDevices.js +2 -7
- package/lib/module/MediaDevices.js.map +1 -1
- package/lib/module/MediaStream.js +9 -38
- package/lib/module/MediaStream.js.map +1 -1
- package/lib/module/MediaStreamError.js +0 -9
- package/lib/module/MediaStreamError.js.map +1 -1
- package/lib/module/MediaStreamErrorEvent.js +0 -7
- package/lib/module/MediaStreamErrorEvent.js.map +1 -1
- package/lib/module/MediaStreamEvent.js +0 -7
- package/lib/module/MediaStreamEvent.js.map +1 -1
- package/lib/module/MediaStreamTrack.js +6 -58
- package/lib/module/MediaStreamTrack.js.map +1 -1
- package/lib/module/MediaStreamTrackEvent.js +11 -8
- package/lib/module/MediaStreamTrackEvent.js.map +1 -1
- package/lib/module/MessageEvent.js +12 -8
- package/lib/module/MessageEvent.js.map +1 -1
- package/lib/module/Permissions.js +19 -26
- package/lib/module/Permissions.js.map +1 -1
- package/lib/module/RTCDataChannel.js +9 -67
- package/lib/module/RTCDataChannel.js.map +1 -1
- package/lib/module/RTCDataChannelEvent.js +11 -8
- package/lib/module/RTCDataChannelEvent.js.map +1 -1
- package/lib/module/RTCErrorEvent.js +2 -11
- package/lib/module/RTCErrorEvent.js.map +1 -1
- package/lib/module/RTCEvent.js +13 -7
- package/lib/module/RTCEvent.js.map +1 -1
- package/lib/module/RTCIceCandidate.js +0 -12
- package/lib/module/RTCIceCandidate.js.map +1 -1
- package/lib/module/RTCIceCandidateEvent.js +13 -11
- package/lib/module/RTCIceCandidateEvent.js.map +1 -1
- package/lib/module/RTCPeerConnection.js +176 -230
- package/lib/module/RTCPeerConnection.js.map +1 -1
- package/lib/module/RTCRtcpParameters.js +0 -8
- package/lib/module/RTCRtcpParameters.js.map +1 -1
- package/lib/module/RTCRtpCapabilities.js +5 -17
- package/lib/module/RTCRtpCapabilities.js.map +1 -1
- package/lib/module/RTCRtpCodecCapability.js +0 -6
- package/lib/module/RTCRtpCodecCapability.js.map +1 -1
- package/lib/module/RTCRtpCodecParameters.js +0 -17
- package/lib/module/RTCRtpCodecParameters.js.map +1 -1
- package/lib/module/RTCRtpEncodingParameters.js +4 -32
- package/lib/module/RTCRtpEncodingParameters.js.map +1 -1
- package/lib/module/RTCRtpHeaderExtension.js +0 -10
- package/lib/module/RTCRtpHeaderExtension.js.map +1 -1
- package/lib/module/RTCRtpParameters.js +2 -12
- package/lib/module/RTCRtpParameters.js.map +1 -1
- package/lib/module/RTCRtpReceiveParameters.js +0 -1
- package/lib/module/RTCRtpReceiveParameters.js.map +1 -1
- package/lib/module/RTCRtpReceiver.js +1 -19
- package/lib/module/RTCRtpReceiver.js.map +1 -1
- package/lib/module/RTCRtpSendParameters.js +0 -18
- package/lib/module/RTCRtpSendParameters.js.map +1 -1
- package/lib/module/RTCRtpSender.js +1 -23
- package/lib/module/RTCRtpSender.js.map +1 -1
- package/lib/module/RTCRtpTransceiver.js +3 -34
- package/lib/module/RTCRtpTransceiver.js.map +1 -1
- package/lib/module/RTCSessionDescription.js +0 -11
- package/lib/module/RTCSessionDescription.js.map +1 -1
- package/lib/module/RTCTrackEvent.js +16 -12
- package/lib/module/RTCTrackEvent.js.map +1 -1
- package/lib/module/RTCUtil.js +9 -32
- package/lib/module/RTCUtil.js.map +1 -1
- package/lib/module/RTCView.js +1 -0
- package/lib/module/RTCView.js.map +1 -1
- package/lib/module/ScreenCapturePickerView.js.map +1 -1
- package/lib/module/getDisplayMedia.js.map +1 -1
- package/lib/module/getUserMedia.js +7 -18
- package/lib/module/getUserMedia.js.map +1 -1
- package/lib/module/index.js +2 -7
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/EventEmitter.d.ts +3 -2
- package/lib/typescript/EventEmitter.d.ts.map +1 -0
- package/lib/typescript/Logger.d.ts +1 -0
- package/lib/typescript/Logger.d.ts.map +1 -0
- package/lib/typescript/MediaDevices.d.ts +1 -0
- package/lib/typescript/MediaDevices.d.ts.map +1 -0
- package/lib/typescript/MediaStream.d.ts +15 -4
- package/lib/typescript/MediaStream.d.ts.map +1 -0
- package/lib/typescript/MediaStreamError.d.ts +1 -0
- package/lib/typescript/MediaStreamError.d.ts.map +1 -0
- package/lib/typescript/MediaStreamErrorEvent.d.ts +1 -0
- package/lib/typescript/MediaStreamErrorEvent.d.ts.map +1 -0
- package/lib/typescript/MediaStreamEvent.d.ts +1 -0
- package/lib/typescript/MediaStreamEvent.d.ts.map +1 -0
- package/lib/typescript/MediaStreamTrack.d.ts +2 -1
- package/lib/typescript/MediaStreamTrack.d.ts.map +1 -0
- package/lib/typescript/MediaStreamTrackEvent.d.ts +17 -5
- package/lib/typescript/MediaStreamTrackEvent.d.ts.map +1 -0
- package/lib/typescript/MessageEvent.d.ts +19 -6
- package/lib/typescript/MessageEvent.d.ts.map +1 -0
- package/lib/typescript/Permissions.d.ts +2 -1
- package/lib/typescript/Permissions.d.ts.map +1 -0
- package/lib/typescript/RTCDataChannel.d.ts +14 -4
- package/lib/typescript/RTCDataChannel.d.ts.map +1 -0
- package/lib/typescript/RTCDataChannelEvent.d.ts +17 -5
- package/lib/typescript/RTCDataChannelEvent.d.ts.map +1 -0
- package/lib/typescript/RTCErrorEvent.d.ts +5 -4
- package/lib/typescript/RTCErrorEvent.d.ts.map +1 -0
- package/lib/typescript/RTCEvent.d.ts +13 -3
- package/lib/typescript/RTCEvent.d.ts.map +1 -0
- package/lib/typescript/RTCIceCandidate.d.ts +8 -5
- package/lib/typescript/RTCIceCandidate.d.ts.map +1 -0
- package/lib/typescript/RTCIceCandidateEvent.d.ts +18 -3
- package/lib/typescript/RTCIceCandidateEvent.d.ts.map +1 -0
- package/lib/typescript/RTCPeerConnection.d.ts +34 -10
- package/lib/typescript/RTCPeerConnection.d.ts.map +1 -0
- package/lib/typescript/RTCRtcpParameters.d.ts +1 -0
- package/lib/typescript/RTCRtcpParameters.d.ts.map +1 -0
- package/lib/typescript/RTCRtpCapabilities.d.ts +1 -0
- package/lib/typescript/RTCRtpCapabilities.d.ts.map +1 -0
- package/lib/typescript/RTCRtpCodecCapability.d.ts +1 -0
- package/lib/typescript/RTCRtpCodecCapability.d.ts.map +1 -0
- package/lib/typescript/RTCRtpCodecParameters.d.ts +1 -0
- package/lib/typescript/RTCRtpCodecParameters.d.ts.map +1 -0
- package/lib/typescript/RTCRtpEncodingParameters.d.ts +1 -0
- package/lib/typescript/RTCRtpEncodingParameters.d.ts.map +1 -0
- package/lib/typescript/RTCRtpHeaderExtension.d.ts +1 -0
- package/lib/typescript/RTCRtpHeaderExtension.d.ts.map +1 -0
- package/lib/typescript/RTCRtpParameters.d.ts +1 -0
- package/lib/typescript/RTCRtpParameters.d.ts.map +1 -0
- package/lib/typescript/RTCRtpReceiveParameters.d.ts +1 -0
- package/lib/typescript/RTCRtpReceiveParameters.d.ts.map +1 -0
- package/lib/typescript/RTCRtpReceiver.d.ts +1 -0
- package/lib/typescript/RTCRtpReceiver.d.ts.map +1 -0
- package/lib/typescript/RTCRtpSendParameters.d.ts +2 -1
- package/lib/typescript/RTCRtpSendParameters.d.ts.map +1 -0
- package/lib/typescript/RTCRtpSender.d.ts +1 -0
- package/lib/typescript/RTCRtpSender.d.ts.map +1 -0
- package/lib/typescript/RTCRtpTransceiver.d.ts +1 -0
- package/lib/typescript/RTCRtpTransceiver.d.ts.map +1 -0
- package/lib/typescript/RTCSessionDescription.d.ts +1 -0
- package/lib/typescript/RTCSessionDescription.d.ts.map +1 -0
- package/lib/typescript/RTCTrackEvent.d.ts +21 -6
- package/lib/typescript/RTCTrackEvent.d.ts.map +1 -0
- package/lib/typescript/RTCUtil.d.ts +1 -0
- package/lib/typescript/RTCUtil.d.ts.map +1 -0
- package/lib/typescript/RTCView.d.ts +1 -0
- package/lib/typescript/RTCView.d.ts.map +1 -0
- package/lib/typescript/ScreenCapturePickerView.d.ts +1 -0
- package/lib/typescript/ScreenCapturePickerView.d.ts.map +1 -0
- package/lib/typescript/getDisplayMedia.d.ts +1 -0
- package/lib/typescript/getDisplayMedia.d.ts.map +1 -0
- package/lib/typescript/getUserMedia.d.ts +1 -0
- package/lib/typescript/getUserMedia.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/package.json +2 -4
- package/react-native-webrtc.podspec +1 -1
- package/src/MediaStream.ts +14 -4
- package/src/MediaStreamTrackEvent.ts +18 -4
- package/src/MessageEvent.ts +19 -5
- package/src/RTCDataChannel.ts +10 -8
- package/src/RTCDataChannelEvent.ts +21 -4
- package/src/RTCErrorEvent.ts +3 -3
- package/src/RTCEvent.ts +18 -4
- package/src/RTCIceCandidate.ts +7 -1
- package/src/RTCIceCandidateEvent.ts +19 -4
- package/src/RTCPeerConnection.ts +114 -52
- package/src/RTCTrackEvent.ts +25 -4
- package/src/index.ts +1 -2
|
@@ -4,97 +4,73 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _eventTargetShim = require("event-target-shim");
|
|
9
|
-
|
|
10
8
|
var _reactNative = require("react-native");
|
|
11
|
-
|
|
12
9
|
var _EventEmitter = require("./EventEmitter");
|
|
13
|
-
|
|
14
10
|
var _Logger = _interopRequireDefault(require("./Logger"));
|
|
15
|
-
|
|
16
11
|
var _MediaStream = _interopRequireDefault(require("./MediaStream"));
|
|
17
|
-
|
|
18
12
|
var _MediaStreamTrack = _interopRequireDefault(require("./MediaStreamTrack"));
|
|
19
|
-
|
|
20
13
|
var _MediaStreamTrackEvent = _interopRequireDefault(require("./MediaStreamTrackEvent"));
|
|
21
|
-
|
|
22
14
|
var _RTCDataChannel = _interopRequireDefault(require("./RTCDataChannel"));
|
|
23
|
-
|
|
24
15
|
var _RTCDataChannelEvent = _interopRequireDefault(require("./RTCDataChannelEvent"));
|
|
25
|
-
|
|
26
16
|
var _RTCEvent = _interopRequireDefault(require("./RTCEvent"));
|
|
27
|
-
|
|
28
17
|
var _RTCIceCandidate = _interopRequireDefault(require("./RTCIceCandidate"));
|
|
29
|
-
|
|
30
18
|
var _RTCIceCandidateEvent = _interopRequireDefault(require("./RTCIceCandidateEvent"));
|
|
31
|
-
|
|
32
19
|
var _RTCRtpReceiveParameters = _interopRequireDefault(require("./RTCRtpReceiveParameters"));
|
|
33
|
-
|
|
34
20
|
var _RTCRtpReceiver = _interopRequireDefault(require("./RTCRtpReceiver"));
|
|
35
|
-
|
|
36
21
|
var _RTCRtpSendParameters = _interopRequireDefault(require("./RTCRtpSendParameters"));
|
|
37
|
-
|
|
38
22
|
var _RTCRtpSender = _interopRequireDefault(require("./RTCRtpSender"));
|
|
39
|
-
|
|
40
23
|
var _RTCRtpTransceiver = _interopRequireDefault(require("./RTCRtpTransceiver"));
|
|
41
|
-
|
|
42
24
|
var _RTCSessionDescription = _interopRequireDefault(require("./RTCSessionDescription"));
|
|
43
|
-
|
|
44
25
|
var _RTCTrackEvent = _interopRequireDefault(require("./RTCTrackEvent"));
|
|
45
|
-
|
|
46
26
|
var RTCUtil = _interopRequireWildcard(require("./RTCUtil"));
|
|
47
|
-
|
|
48
27
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
49
|
-
|
|
50
28
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
51
|
-
|
|
52
29
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
53
|
-
|
|
54
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
55
|
-
|
|
56
30
|
const log = new _Logger.default('pc');
|
|
57
31
|
const {
|
|
58
32
|
WebRTCModule
|
|
59
33
|
} = _reactNative.NativeModules;
|
|
60
|
-
const PEER_CONNECTION_EVENTS = ['connectionstatechange', 'icecandidate', 'icecandidateerror', 'iceconnectionstatechange', 'icegatheringstatechange', 'negotiationneeded', 'signalingstatechange', 'datachannel', 'track', 'error'];
|
|
61
34
|
let nextPeerConnectionId = 0;
|
|
62
|
-
|
|
63
|
-
|
|
35
|
+
class RTCPeerConnection extends _eventTargetShim.EventTarget {
|
|
36
|
+
signalingState = 'stable';
|
|
37
|
+
iceGatheringState = 'new';
|
|
38
|
+
connectionState = 'new';
|
|
39
|
+
iceConnectionState = 'new';
|
|
40
|
+
_currentLocalDescription = null;
|
|
41
|
+
_pendingLocalDescription = null;
|
|
42
|
+
_currentRemoteDescription = null;
|
|
43
|
+
_pendingRemoteDescription = null;
|
|
64
44
|
constructor(configuration) {
|
|
65
45
|
super();
|
|
66
|
-
|
|
67
|
-
_defineProperty(this, "localDescription", null);
|
|
68
|
-
|
|
69
|
-
_defineProperty(this, "remoteDescription", null);
|
|
70
|
-
|
|
71
|
-
_defineProperty(this, "signalingState", 'stable');
|
|
72
|
-
|
|
73
|
-
_defineProperty(this, "iceGatheringState", 'new');
|
|
74
|
-
|
|
75
|
-
_defineProperty(this, "connectionState", 'new');
|
|
76
|
-
|
|
77
|
-
_defineProperty(this, "iceConnectionState", 'new');
|
|
78
|
-
|
|
79
|
-
_defineProperty(this, "_pcId", void 0);
|
|
80
|
-
|
|
81
|
-
_defineProperty(this, "_transceivers", void 0);
|
|
82
|
-
|
|
83
|
-
_defineProperty(this, "_remoteStreams", void 0);
|
|
84
|
-
|
|
85
|
-
_defineProperty(this, "_pendingTrackEvents", void 0);
|
|
86
|
-
|
|
87
46
|
this._pcId = nextPeerConnectionId++;
|
|
88
|
-
WebRTCModule.peerConnectionInit(configuration, this._pcId)
|
|
47
|
+
if (!WebRTCModule.peerConnectionInit(configuration, this._pcId)) {
|
|
48
|
+
throw new Error('Failed to initialize PeerConnection, check the native logs!');
|
|
49
|
+
}
|
|
89
50
|
this._transceivers = [];
|
|
90
51
|
this._remoteStreams = new Map();
|
|
91
52
|
this._pendingTrackEvents = [];
|
|
92
|
-
|
|
93
53
|
this._registerEvents();
|
|
94
|
-
|
|
95
54
|
log.debug(`${this._pcId} ctor`);
|
|
96
55
|
}
|
|
97
|
-
|
|
56
|
+
get currentLocalDescription() {
|
|
57
|
+
return this._currentLocalDescription;
|
|
58
|
+
}
|
|
59
|
+
get pendingLocalDescription() {
|
|
60
|
+
return this._pendingLocalDescription;
|
|
61
|
+
}
|
|
62
|
+
get localDescription() {
|
|
63
|
+
return this._pendingLocalDescription || this._currentLocalDescription;
|
|
64
|
+
}
|
|
65
|
+
get currentRemoteDescription() {
|
|
66
|
+
return this._currentRemoteDescription;
|
|
67
|
+
}
|
|
68
|
+
get pendingRemoteDescription() {
|
|
69
|
+
return this._pendingRemoteDescription;
|
|
70
|
+
}
|
|
71
|
+
get remoteDescription() {
|
|
72
|
+
return this._pendingRemoteDescription || this._currentRemoteDescription;
|
|
73
|
+
}
|
|
98
74
|
async createOffer(options) {
|
|
99
75
|
log.debug(`${this._pcId} createOffer`);
|
|
100
76
|
const {
|
|
@@ -108,150 +84,114 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
108
84
|
transceiverOrder,
|
|
109
85
|
transceiver
|
|
110
86
|
} = t;
|
|
111
|
-
const newSender = new _RTCRtpSender.default({
|
|
87
|
+
const newSender = new _RTCRtpSender.default({
|
|
88
|
+
...transceiver.sender,
|
|
112
89
|
track: null
|
|
113
90
|
});
|
|
114
91
|
const remoteTrack = transceiver.receiver.track ? new _MediaStreamTrack.default(transceiver.receiver.track) : null;
|
|
115
|
-
const newReceiver = new _RTCRtpReceiver.default({
|
|
92
|
+
const newReceiver = new _RTCRtpReceiver.default({
|
|
93
|
+
...transceiver.receiver,
|
|
116
94
|
track: remoteTrack
|
|
117
95
|
});
|
|
118
|
-
const newTransceiver = new _RTCRtpTransceiver.default({
|
|
96
|
+
const newTransceiver = new _RTCRtpTransceiver.default({
|
|
97
|
+
...transceiver,
|
|
119
98
|
sender: newSender,
|
|
120
99
|
receiver: newReceiver
|
|
121
100
|
});
|
|
122
|
-
|
|
123
101
|
this._insertTransceiverSorted(transceiverOrder, newTransceiver);
|
|
124
102
|
});
|
|
125
|
-
|
|
126
103
|
this._updateTransceivers(transceiversInfo);
|
|
127
|
-
|
|
128
104
|
return sdpInfo;
|
|
129
105
|
}
|
|
130
|
-
|
|
131
106
|
async createAnswer() {
|
|
132
107
|
log.debug(`${this._pcId} createAnswer`);
|
|
133
108
|
const {
|
|
134
109
|
sdpInfo,
|
|
135
110
|
transceiversInfo
|
|
136
111
|
} = await WebRTCModule.peerConnectionCreateAnswer(this._pcId, {});
|
|
137
|
-
|
|
138
112
|
this._updateTransceivers(transceiversInfo);
|
|
139
|
-
|
|
140
113
|
return sdpInfo;
|
|
141
114
|
}
|
|
142
|
-
|
|
143
115
|
setConfiguration(configuration) {
|
|
144
116
|
WebRTCModule.peerConnectionSetConfiguration(configuration, this._pcId);
|
|
145
117
|
}
|
|
146
|
-
|
|
147
118
|
async setLocalDescription(sessionDescription) {
|
|
148
119
|
var _desc;
|
|
149
|
-
|
|
150
120
|
log.debug(`${this._pcId} setLocalDescription`);
|
|
151
121
|
let desc;
|
|
152
|
-
|
|
153
122
|
if (sessionDescription) {
|
|
154
|
-
var _sessionDescription$s;
|
|
155
|
-
|
|
156
123
|
desc = {
|
|
157
124
|
type: sessionDescription.type,
|
|
158
|
-
sdp:
|
|
125
|
+
sdp: sessionDescription.sdp ?? ''
|
|
159
126
|
};
|
|
160
|
-
|
|
161
127
|
if (!RTCUtil.isSdpTypeValid(desc.type)) {
|
|
162
128
|
throw new Error(`Invalid session description: invalid type: ${desc.type}`);
|
|
163
129
|
}
|
|
164
130
|
} else {
|
|
165
131
|
desc = null;
|
|
166
132
|
}
|
|
167
|
-
|
|
168
133
|
const {
|
|
169
|
-
sdpInfo,
|
|
170
134
|
transceiversInfo
|
|
171
135
|
} = await WebRTCModule.peerConnectionSetLocalDescription(this._pcId, desc);
|
|
172
|
-
|
|
173
|
-
if (sdpInfo.type && sdpInfo.sdp) {
|
|
174
|
-
this.localDescription = new _RTCSessionDescription.default(sdpInfo);
|
|
175
|
-
} else {
|
|
176
|
-
this.localDescription = null;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
this._updateTransceivers(transceiversInfo,
|
|
180
|
-
/* removeStopped */
|
|
181
|
-
((_desc = desc) === null || _desc === void 0 ? void 0 : _desc.type) === 'answer');
|
|
182
|
-
|
|
136
|
+
this._updateTransceivers(transceiversInfo, /* removeStopped */((_desc = desc) === null || _desc === void 0 ? void 0 : _desc.type) === 'answer');
|
|
183
137
|
log.debug(`${this._pcId} setLocalDescription OK`);
|
|
184
138
|
}
|
|
185
|
-
|
|
186
139
|
async setRemoteDescription(sessionDescription) {
|
|
187
|
-
var _sessionDescription$s2, _desc$type;
|
|
188
|
-
|
|
189
140
|
log.debug(`${this._pcId} setRemoteDescription`);
|
|
190
|
-
|
|
191
141
|
if (!sessionDescription) {
|
|
192
142
|
return Promise.reject(new Error('No session description provided'));
|
|
193
143
|
}
|
|
194
|
-
|
|
195
144
|
const desc = {
|
|
196
145
|
type: sessionDescription.type,
|
|
197
|
-
sdp:
|
|
146
|
+
sdp: sessionDescription.sdp ?? ''
|
|
198
147
|
};
|
|
199
|
-
|
|
200
|
-
if (!RTCUtil.isSdpTypeValid((_desc$type = desc.type) !== null && _desc$type !== void 0 ? _desc$type : '')) {
|
|
148
|
+
if (!RTCUtil.isSdpTypeValid(desc.type ?? '')) {
|
|
201
149
|
throw new Error(`Invalid session description: invalid type: ${desc.type}`);
|
|
202
150
|
}
|
|
203
|
-
|
|
204
151
|
const {
|
|
205
|
-
sdpInfo,
|
|
206
152
|
newTransceivers,
|
|
207
153
|
transceiversInfo
|
|
208
154
|
} = await WebRTCModule.peerConnectionSetRemoteDescription(this._pcId, desc);
|
|
209
|
-
|
|
210
|
-
if (sdpInfo.type && sdpInfo.sdp) {
|
|
211
|
-
this.remoteDescription = new _RTCSessionDescription.default(sdpInfo);
|
|
212
|
-
} else {
|
|
213
|
-
this.remoteDescription = null;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
155
|
newTransceivers === null || newTransceivers === void 0 ? void 0 : newTransceivers.forEach(t => {
|
|
217
156
|
const {
|
|
218
157
|
transceiverOrder,
|
|
219
158
|
transceiver
|
|
220
159
|
} = t;
|
|
221
|
-
const newSender = new _RTCRtpSender.default({
|
|
160
|
+
const newSender = new _RTCRtpSender.default({
|
|
161
|
+
...transceiver.sender,
|
|
222
162
|
track: null
|
|
223
163
|
});
|
|
224
164
|
const remoteTrack = transceiver.receiver.track ? new _MediaStreamTrack.default(transceiver.receiver.track) : null;
|
|
225
|
-
const newReceiver = new _RTCRtpReceiver.default({
|
|
165
|
+
const newReceiver = new _RTCRtpReceiver.default({
|
|
166
|
+
...transceiver.receiver,
|
|
226
167
|
track: remoteTrack
|
|
227
168
|
});
|
|
228
|
-
const newTransceiver = new _RTCRtpTransceiver.default({
|
|
169
|
+
const newTransceiver = new _RTCRtpTransceiver.default({
|
|
170
|
+
...transceiver,
|
|
229
171
|
sender: newSender,
|
|
230
172
|
receiver: newReceiver
|
|
231
173
|
});
|
|
232
|
-
|
|
233
174
|
this._insertTransceiverSorted(transceiverOrder, newTransceiver);
|
|
234
175
|
});
|
|
176
|
+
this._updateTransceivers(transceiversInfo, /* removeStopped */desc.type === 'answer');
|
|
235
177
|
|
|
236
|
-
|
|
237
|
-
/* removeStopped */
|
|
238
|
-
desc.type === 'answer'); // Fire track events. They must fire before sRD resolves.
|
|
239
|
-
|
|
240
|
-
|
|
178
|
+
// Fire track events. They must fire before sRD resolves.
|
|
241
179
|
const pendingTrackEvents = this._pendingTrackEvents;
|
|
242
180
|
this._pendingTrackEvents = [];
|
|
243
|
-
|
|
244
181
|
for (const ev of pendingTrackEvents) {
|
|
245
|
-
const [transceiver] = this.getTransceivers().filter(t => t.receiver.id === ev.receiver.id);
|
|
182
|
+
const [transceiver] = this.getTransceivers().filter(t => t.receiver.id === ev.receiver.id);
|
|
183
|
+
|
|
184
|
+
// We need to fire this event for an existing track sometimes, like
|
|
246
185
|
// when the transceiver direction (on the sending side) switches from
|
|
247
186
|
// sendrecv to recvonly and then back.
|
|
248
|
-
// @ts-ignore
|
|
249
187
|
|
|
188
|
+
// @ts-ignore
|
|
250
189
|
const track = transceiver.receiver.track;
|
|
251
190
|
transceiver._mid = ev.transceiver.mid;
|
|
252
191
|
transceiver._currentDirection = ev.transceiver.currentDirection;
|
|
253
|
-
transceiver._direction = ev.transceiver.direction;
|
|
192
|
+
transceiver._direction = ev.transceiver.direction;
|
|
254
193
|
|
|
194
|
+
// Get the stream object from the event. Create if necessary.
|
|
255
195
|
const streams = ev.streams.map(streamInfo => {
|
|
256
196
|
// Here we are making sure that we don't create stream objects that already exist
|
|
257
197
|
// So that event listeners do get the same object if it has been created before.
|
|
@@ -261,16 +201,12 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
261
201
|
streamReactTag: streamInfo.streamReactTag,
|
|
262
202
|
tracks: []
|
|
263
203
|
});
|
|
264
|
-
|
|
265
204
|
this._remoteStreams.set(streamInfo.streamId, stream);
|
|
266
205
|
}
|
|
267
|
-
|
|
268
206
|
const stream = this._remoteStreams.get(streamInfo.streamId);
|
|
269
|
-
|
|
270
207
|
if (!(stream !== null && stream !== void 0 && stream._tracks.includes(track))) {
|
|
271
208
|
stream === null || stream === void 0 ? void 0 : stream._tracks.push(track);
|
|
272
209
|
}
|
|
273
|
-
|
|
274
210
|
return stream;
|
|
275
211
|
});
|
|
276
212
|
const eventData = {
|
|
@@ -278,37 +214,38 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
278
214
|
transceiver,
|
|
279
215
|
track,
|
|
280
216
|
receiver: transceiver.receiver
|
|
281
|
-
};
|
|
282
|
-
|
|
217
|
+
};
|
|
283
218
|
this.dispatchEvent(new _RTCTrackEvent.default('track', eventData));
|
|
284
219
|
streams.forEach(stream => {
|
|
285
|
-
// @ts-ignore
|
|
286
220
|
stream.dispatchEvent(new _MediaStreamTrackEvent.default('addtrack', {
|
|
287
221
|
track
|
|
288
222
|
}));
|
|
289
|
-
});
|
|
223
|
+
});
|
|
290
224
|
|
|
225
|
+
// Dispatch an unmute event for the track.
|
|
291
226
|
track._setMutedInternal(false);
|
|
292
227
|
}
|
|
293
|
-
|
|
294
228
|
log.debug(`${this._pcId} setRemoteDescription OK`);
|
|
295
229
|
}
|
|
296
|
-
|
|
297
230
|
async addIceCandidate(candidate) {
|
|
298
231
|
log.debug(`${this._pcId} addIceCandidate`);
|
|
299
|
-
|
|
300
232
|
if (!candidate || !candidate.candidate) {
|
|
301
233
|
// XXX end-of candidates is not implemented: https://bugs.chromium.org/p/webrtc/issues/detail?id=9218
|
|
302
234
|
return;
|
|
303
235
|
}
|
|
304
|
-
|
|
305
236
|
if (candidate.sdpMLineIndex === null || candidate.sdpMLineIndex === undefined || candidate.sdpMid === null || candidate.sdpMid === undefined) {
|
|
306
237
|
throw new TypeError('`sdpMLineIndex` and `sdpMid` must not null or undefined');
|
|
307
238
|
}
|
|
308
|
-
|
|
309
239
|
const newSdp = await WebRTCModule.peerConnectionAddICECandidate(this._pcId, candidate.toJSON ? candidate.toJSON() : candidate);
|
|
310
|
-
this.
|
|
240
|
+
if (this.signalingState === 'stable') {
|
|
241
|
+
this._currentRemoteDescription = new _RTCSessionDescription.default(newSdp);
|
|
242
|
+
this._pendingRemoteDescription = null;
|
|
243
|
+
} else {
|
|
244
|
+
this._currentRemoteDescription = null;
|
|
245
|
+
this._pendingRemoteDescription = new _RTCSessionDescription.default(newSdp);
|
|
246
|
+
}
|
|
311
247
|
}
|
|
248
|
+
|
|
312
249
|
/**
|
|
313
250
|
* @brief Adds a new track to the {@link RTCPeerConnection},
|
|
314
251
|
* and indicates that it is contained in the specified {@link MediaStream}s.
|
|
@@ -317,73 +254,65 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
317
254
|
* @param {...MediaStream} streams One or more {@link MediaStream}s the track needs to be added to
|
|
318
255
|
* https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtrack
|
|
319
256
|
*/
|
|
320
|
-
|
|
321
|
-
|
|
322
257
|
addTrack(track) {
|
|
323
258
|
log.debug(`${this._pcId} addTrack`);
|
|
324
|
-
|
|
325
259
|
if (this.connectionState === 'closed') {
|
|
326
260
|
throw new Error('Peer Connection is closed');
|
|
327
261
|
}
|
|
328
|
-
|
|
329
262
|
if (this._trackExists(track)) {
|
|
330
263
|
throw new Error('Track already exists in a sender');
|
|
331
264
|
}
|
|
332
|
-
|
|
333
265
|
for (var _len = arguments.length, streams = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
334
266
|
streams[_key - 1] = arguments[_key];
|
|
335
267
|
}
|
|
336
|
-
|
|
337
268
|
const streamIds = streams.map(s => s.id);
|
|
338
269
|
const result = WebRTCModule.peerConnectionAddTrack(this._pcId, track.id, {
|
|
339
270
|
streamIds
|
|
340
271
|
});
|
|
341
|
-
|
|
342
272
|
if (result === null) {
|
|
343
273
|
throw new Error('Could not add sender');
|
|
344
274
|
}
|
|
345
|
-
|
|
346
275
|
const {
|
|
347
276
|
transceiverOrder,
|
|
348
277
|
transceiver,
|
|
349
278
|
sender
|
|
350
|
-
} = result;
|
|
351
|
-
// so we check if that is the case, and update accordingly.
|
|
279
|
+
} = result;
|
|
352
280
|
|
|
281
|
+
// According to the W3C docs, the sender could have been reused, and
|
|
282
|
+
// so we check if that is the case, and update accordingly.
|
|
353
283
|
const [existingSender] = this.getSenders().filter(s => s.id === sender.id);
|
|
354
|
-
|
|
355
284
|
if (existingSender) {
|
|
356
285
|
// Update sender
|
|
357
|
-
existingSender._track = track;
|
|
286
|
+
existingSender._track = track;
|
|
358
287
|
|
|
288
|
+
// Update the corresponding transceiver as well
|
|
359
289
|
const [existingTransceiver] = this.getTransceivers().filter(t => t.sender.id === existingSender.id);
|
|
360
290
|
existingTransceiver._direction = transceiver.direction;
|
|
361
291
|
existingTransceiver._currentDirection = transceiver.currentDirection;
|
|
362
292
|
return existingSender;
|
|
363
|
-
}
|
|
364
|
-
|
|
293
|
+
}
|
|
365
294
|
|
|
366
|
-
|
|
295
|
+
// This is a new transceiver, should create a transceiver for it and add it
|
|
296
|
+
const newSender = new _RTCRtpSender.default({
|
|
297
|
+
...transceiver.sender,
|
|
367
298
|
track
|
|
368
299
|
});
|
|
369
300
|
const remoteTrack = transceiver.receiver.track ? new _MediaStreamTrack.default(transceiver.receiver.track) : null;
|
|
370
|
-
const newReceiver = new _RTCRtpReceiver.default({
|
|
301
|
+
const newReceiver = new _RTCRtpReceiver.default({
|
|
302
|
+
...transceiver.receiver,
|
|
371
303
|
track: remoteTrack
|
|
372
304
|
});
|
|
373
|
-
const newTransceiver = new _RTCRtpTransceiver.default({
|
|
305
|
+
const newTransceiver = new _RTCRtpTransceiver.default({
|
|
306
|
+
...transceiver,
|
|
374
307
|
sender: newSender,
|
|
375
308
|
receiver: newReceiver
|
|
376
309
|
});
|
|
377
|
-
|
|
378
310
|
this._insertTransceiverSorted(transceiverOrder, newTransceiver);
|
|
379
|
-
|
|
380
311
|
return newSender;
|
|
381
312
|
}
|
|
382
|
-
|
|
383
313
|
addTransceiver(source, init) {
|
|
384
314
|
log.debug(`${this._pcId} addTransceiver`);
|
|
385
315
|
let src = {};
|
|
386
|
-
|
|
387
316
|
if (source === 'audio') {
|
|
388
317
|
src = {
|
|
389
318
|
type: 'audio'
|
|
@@ -396,25 +325,23 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
396
325
|
src = {
|
|
397
326
|
trackId: source.id
|
|
398
327
|
};
|
|
399
|
-
}
|
|
400
|
-
|
|
328
|
+
}
|
|
401
329
|
|
|
330
|
+
// Extract the stream ids
|
|
402
331
|
if (init && init.streams) {
|
|
403
332
|
init.streamIds = init.streams.map(stream => stream.id);
|
|
404
333
|
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
init: {
|
|
334
|
+
const result = WebRTCModule.peerConnectionAddTransceiver(this._pcId, {
|
|
335
|
+
...src,
|
|
336
|
+
init: {
|
|
337
|
+
...init
|
|
408
338
|
}
|
|
409
339
|
});
|
|
410
|
-
|
|
411
340
|
if (result === null) {
|
|
412
341
|
throw new Error('Transceiver could not be added');
|
|
413
342
|
}
|
|
414
|
-
|
|
415
343
|
const t = result.transceiver;
|
|
416
344
|
let track = null;
|
|
417
|
-
|
|
418
345
|
if (typeof source === 'string') {
|
|
419
346
|
if (t.sender.track) {
|
|
420
347
|
track = new _MediaStreamTrack.default(t.sender.track);
|
|
@@ -423,57 +350,50 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
423
350
|
// 'source' is a MediaStreamTrack
|
|
424
351
|
track = source;
|
|
425
352
|
}
|
|
426
|
-
|
|
427
|
-
|
|
353
|
+
const sender = new _RTCRtpSender.default({
|
|
354
|
+
...t.sender,
|
|
428
355
|
track
|
|
429
356
|
});
|
|
430
357
|
const remoteTrack = t.receiver.track ? new _MediaStreamTrack.default(t.receiver.track) : null;
|
|
431
|
-
const receiver = new _RTCRtpReceiver.default({
|
|
358
|
+
const receiver = new _RTCRtpReceiver.default({
|
|
359
|
+
...t.receiver,
|
|
432
360
|
track: remoteTrack
|
|
433
361
|
});
|
|
434
|
-
const transceiver = new _RTCRtpTransceiver.default({
|
|
362
|
+
const transceiver = new _RTCRtpTransceiver.default({
|
|
363
|
+
...result.transceiver,
|
|
435
364
|
sender,
|
|
436
365
|
receiver
|
|
437
366
|
});
|
|
438
|
-
|
|
439
367
|
this._insertTransceiverSorted(result.transceiverOrder, transceiver);
|
|
440
|
-
|
|
441
368
|
return transceiver;
|
|
442
369
|
}
|
|
443
|
-
|
|
444
370
|
removeTrack(sender) {
|
|
445
371
|
log.debug(`${this._pcId} removeTrack`);
|
|
446
|
-
|
|
447
372
|
if (this._pcId !== sender._peerConnectionId) {
|
|
448
373
|
throw new Error('Sender does not belong to this peer connection');
|
|
449
374
|
}
|
|
450
|
-
|
|
451
375
|
if (this.connectionState === 'closed') {
|
|
452
376
|
throw new Error('Peer Connection is closed');
|
|
453
377
|
}
|
|
454
|
-
|
|
455
378
|
const existingSender = this.getSenders().find(s => s === sender);
|
|
456
|
-
|
|
457
379
|
if (!existingSender) {
|
|
458
380
|
throw new Error('Sender does not exist');
|
|
459
381
|
}
|
|
460
|
-
|
|
461
382
|
if (existingSender.track === null) {
|
|
462
383
|
return;
|
|
463
|
-
}
|
|
464
|
-
|
|
384
|
+
}
|
|
465
385
|
|
|
386
|
+
// Blocking!
|
|
466
387
|
WebRTCModule.peerConnectionRemoveTrack(this._pcId, sender.id);
|
|
467
388
|
existingSender._track = null;
|
|
468
389
|
const [existingTransceiver] = this.getTransceivers().filter(t => t.sender.id === existingSender.id);
|
|
469
390
|
existingTransceiver._direction = existingTransceiver.direction === 'sendrecv' ? 'recvonly' : 'inactive';
|
|
470
391
|
}
|
|
471
|
-
|
|
472
392
|
async getStats(selector) {
|
|
473
393
|
log.debug(`${this._pcId} getStats`);
|
|
474
|
-
|
|
475
394
|
if (!selector) {
|
|
476
395
|
const data = await WebRTCModule.peerConnectionGetStats(this._pcId);
|
|
396
|
+
|
|
477
397
|
/**
|
|
478
398
|
* On both Android and iOS it is faster to construct a single
|
|
479
399
|
* JSON string representing the Map of StatsReports and have it
|
|
@@ -483,13 +403,11 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
483
403
|
* Native bridge which is a bottleneck that tends to be visible in
|
|
484
404
|
* the UI when there is congestion involving UI-related passing.
|
|
485
405
|
*/
|
|
486
|
-
|
|
487
406
|
return new Map(JSON.parse(data));
|
|
488
407
|
} else {
|
|
489
408
|
const senders = this.getSenders().filter(s => s.track === selector);
|
|
490
409
|
const receivers = this.getReceivers().filter(r => r.track === selector);
|
|
491
410
|
const matches = senders.length + receivers.length;
|
|
492
|
-
|
|
493
411
|
if (matches === 0) {
|
|
494
412
|
throw new Error('Invalid selector: could not find matching sender / receiver');
|
|
495
413
|
} else if (matches > 1) {
|
|
@@ -500,70 +418,55 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
500
418
|
}
|
|
501
419
|
}
|
|
502
420
|
}
|
|
503
|
-
|
|
504
421
|
getTransceivers() {
|
|
505
422
|
return this._transceivers.map(e => e.transceiver);
|
|
506
423
|
}
|
|
507
|
-
|
|
508
424
|
getSenders() {
|
|
509
425
|
// @ts-ignore
|
|
510
426
|
return this._transceivers.map(e => !e.transceiver.stopped && e.transceiver.sender).filter(Boolean);
|
|
511
427
|
}
|
|
512
|
-
|
|
513
428
|
getReceivers() {
|
|
514
429
|
// @ts-ignore
|
|
515
430
|
return this._transceivers.map(e => !e.transceiver.stopped && e.transceiver.receiver).filter(Boolean);
|
|
516
431
|
}
|
|
517
|
-
|
|
518
432
|
close() {
|
|
519
433
|
log.debug(`${this._pcId} close`);
|
|
520
|
-
|
|
521
434
|
if (this.connectionState === 'closed') {
|
|
522
435
|
return;
|
|
523
436
|
}
|
|
437
|
+
WebRTCModule.peerConnectionClose(this._pcId);
|
|
524
438
|
|
|
525
|
-
|
|
526
|
-
|
|
439
|
+
// Mark transceivers as stopped.
|
|
527
440
|
this._transceivers.forEach(_ref => {
|
|
528
441
|
let {
|
|
529
442
|
transceiver
|
|
530
443
|
} = _ref;
|
|
531
|
-
|
|
532
444
|
transceiver._setStopped();
|
|
533
445
|
});
|
|
534
446
|
}
|
|
535
|
-
|
|
536
447
|
restartIce() {
|
|
537
448
|
WebRTCModule.peerConnectionRestartIce(this._pcId);
|
|
538
449
|
}
|
|
539
|
-
|
|
540
450
|
_registerEvents() {
|
|
541
451
|
(0, _EventEmitter.addListener)(this, 'peerConnectionOnRenegotiationNeeded', ev => {
|
|
542
452
|
if (ev.pcId !== this._pcId) {
|
|
543
453
|
return;
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
|
|
454
|
+
}
|
|
547
455
|
this.dispatchEvent(new _RTCEvent.default('negotiationneeded'));
|
|
548
456
|
});
|
|
549
457
|
(0, _EventEmitter.addListener)(this, 'peerConnectionIceConnectionChanged', ev => {
|
|
550
458
|
if (ev.pcId !== this._pcId) {
|
|
551
459
|
return;
|
|
552
460
|
}
|
|
553
|
-
|
|
554
|
-
this.iceConnectionState = ev.iceConnectionState; // @ts-ignore
|
|
555
|
-
|
|
461
|
+
this.iceConnectionState = ev.iceConnectionState;
|
|
556
462
|
this.dispatchEvent(new _RTCEvent.default('iceconnectionstatechange'));
|
|
557
463
|
});
|
|
558
464
|
(0, _EventEmitter.addListener)(this, 'peerConnectionStateChanged', ev => {
|
|
559
465
|
if (ev.pcId !== this._pcId) {
|
|
560
466
|
return;
|
|
561
467
|
}
|
|
562
|
-
|
|
563
|
-
this.connectionState = ev.connectionState; // @ts-ignore
|
|
564
|
-
|
|
468
|
+
this.connectionState = ev.connectionState;
|
|
565
469
|
this.dispatchEvent(new _RTCEvent.default('connectionstatechange'));
|
|
566
|
-
|
|
567
470
|
if (ev.connectionState === 'closed') {
|
|
568
471
|
// This PeerConnection is done, clean up.
|
|
569
472
|
(0, _EventEmitter.removeListener)(this);
|
|
@@ -574,32 +477,65 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
574
477
|
if (ev.pcId !== this._pcId) {
|
|
575
478
|
return;
|
|
576
479
|
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
480
|
+
this.signalingState = ev.signalingState;
|
|
481
|
+
const {
|
|
482
|
+
localSdp,
|
|
483
|
+
remoteSdp
|
|
484
|
+
} = ev;
|
|
485
|
+
if (localSdp.type && localSdp.sdp) {
|
|
486
|
+
switch (this.signalingState) {
|
|
487
|
+
case 'stable':
|
|
488
|
+
this._currentLocalDescription = new _RTCSessionDescription.default(localSdp);
|
|
489
|
+
this._pendingLocalDescription = null;
|
|
490
|
+
break;
|
|
491
|
+
case 'have-local-offer':
|
|
492
|
+
case 'have-local-pranswer':
|
|
493
|
+
this._currentLocalDescription = null;
|
|
494
|
+
this._pendingLocalDescription = new _RTCSessionDescription.default(localSdp);
|
|
495
|
+
break;
|
|
496
|
+
}
|
|
497
|
+
} else {
|
|
498
|
+
this._currentLocalDescription = null;
|
|
499
|
+
this._pendingLocalDescription = null;
|
|
500
|
+
}
|
|
501
|
+
if (remoteSdp.type && remoteSdp.sdp) {
|
|
502
|
+
switch (this.signalingState) {
|
|
503
|
+
case 'stable':
|
|
504
|
+
this._currentRemoteDescription = new _RTCSessionDescription.default(remoteSdp);
|
|
505
|
+
this._pendingRemoteDescription = null;
|
|
506
|
+
break;
|
|
507
|
+
case 'have-remote-offer':
|
|
508
|
+
case 'have-remote-pranswer':
|
|
509
|
+
this._currentRemoteDescription = null;
|
|
510
|
+
this._pendingRemoteDescription = new _RTCSessionDescription.default(remoteSdp);
|
|
511
|
+
break;
|
|
512
|
+
}
|
|
513
|
+
} else {
|
|
514
|
+
this._currentRemoteDescription = null;
|
|
515
|
+
this._pendingRemoteDescription = null;
|
|
516
|
+
}
|
|
580
517
|
this.dispatchEvent(new _RTCEvent.default('signalingstatechange'));
|
|
581
|
-
});
|
|
518
|
+
});
|
|
582
519
|
|
|
520
|
+
// Consider moving away from this event: https://github.com/WebKit/WebKit/pull/3953
|
|
583
521
|
(0, _EventEmitter.addListener)(this, 'peerConnectionOnTrack', ev => {
|
|
584
522
|
if (ev.pcId !== this._pcId) {
|
|
585
523
|
return;
|
|
586
524
|
}
|
|
525
|
+
log.debug(`${this._pcId} ontrack`);
|
|
587
526
|
|
|
588
|
-
|
|
527
|
+
// NOTE: We need to make sure the track event fires right before sRD completes,
|
|
589
528
|
// so we queue them up here and dispatch the events when sRD fires, but before completing it.
|
|
590
529
|
// In the future we should probably implement out own logic and drop this event altogether.
|
|
591
|
-
|
|
592
530
|
this._pendingTrackEvents.push(ev);
|
|
593
531
|
});
|
|
594
532
|
(0, _EventEmitter.addListener)(this, 'peerConnectionOnRemoveTrack', ev => {
|
|
595
533
|
if (ev.pcId !== this._pcId) {
|
|
596
534
|
return;
|
|
597
535
|
}
|
|
598
|
-
|
|
599
536
|
log.debug(`${this._pcId} onremovetrack ${ev.receiverId}`);
|
|
600
537
|
const receiver = this.getReceivers().find(r => r.id === ev.receiverId);
|
|
601
538
|
const track = receiver === null || receiver === void 0 ? void 0 : receiver.track;
|
|
602
|
-
|
|
603
539
|
if (receiver && track) {
|
|
604
540
|
// As per the spec:
|
|
605
541
|
// - Remove the track from any media streams that were previously passed to the `track` event.
|
|
@@ -609,16 +545,13 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
609
545
|
for (const stream of this._remoteStreams.values()) {
|
|
610
546
|
if (stream._tracks.includes(track)) {
|
|
611
547
|
const trackIdx = stream._tracks.indexOf(track);
|
|
612
|
-
|
|
613
548
|
log.debug(`${this._pcId} removetrack ${track.id}`);
|
|
614
|
-
|
|
615
|
-
stream._tracks.splice(trackIdx, 1); // @ts-ignore
|
|
616
|
-
|
|
617
|
-
|
|
549
|
+
stream._tracks.splice(trackIdx, 1);
|
|
618
550
|
stream.dispatchEvent(new _MediaStreamTrackEvent.default('removetrack', {
|
|
619
551
|
track
|
|
620
|
-
}));
|
|
552
|
+
}));
|
|
621
553
|
|
|
554
|
+
// Dispatch a mute event for the track.
|
|
622
555
|
track._setMutedInternal(true);
|
|
623
556
|
}
|
|
624
557
|
}
|
|
@@ -628,17 +561,22 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
628
561
|
if (ev.pcId !== this._pcId) {
|
|
629
562
|
return;
|
|
630
563
|
}
|
|
564
|
+
const sdpInfo = ev.sdp;
|
|
631
565
|
|
|
632
|
-
|
|
633
|
-
|
|
566
|
+
// Can happen when doing a rollback.
|
|
634
567
|
if (sdpInfo.type && sdpInfo.sdp) {
|
|
635
|
-
this.
|
|
568
|
+
if (this.signalingState === 'stable') {
|
|
569
|
+
this._currentLocalDescription = new _RTCSessionDescription.default(sdpInfo);
|
|
570
|
+
this._pendingLocalDescription = null;
|
|
571
|
+
} else {
|
|
572
|
+
this._currentLocalDescription = null;
|
|
573
|
+
this._pendingLocalDescription = new _RTCSessionDescription.default(sdpInfo);
|
|
574
|
+
}
|
|
636
575
|
} else {
|
|
637
|
-
this.
|
|
576
|
+
this._currentLocalDescription = null;
|
|
577
|
+
this._pendingLocalDescription = null;
|
|
638
578
|
}
|
|
639
|
-
|
|
640
|
-
const candidate = new _RTCIceCandidate.default(ev.candidate); // @ts-ignore
|
|
641
|
-
|
|
579
|
+
const candidate = new _RTCIceCandidate.default(ev.candidate);
|
|
642
580
|
this.dispatchEvent(new _RTCIceCandidateEvent.default('icecandidate', {
|
|
643
581
|
candidate
|
|
644
582
|
}));
|
|
@@ -647,34 +585,34 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
647
585
|
if (ev.pcId !== this._pcId) {
|
|
648
586
|
return;
|
|
649
587
|
}
|
|
650
|
-
|
|
651
588
|
this.iceGatheringState = ev.iceGatheringState;
|
|
652
|
-
|
|
653
589
|
if (this.iceGatheringState === 'complete') {
|
|
654
|
-
const sdpInfo = ev.sdp;
|
|
590
|
+
const sdpInfo = ev.sdp;
|
|
655
591
|
|
|
592
|
+
// Can happen when doing a rollback.
|
|
656
593
|
if (sdpInfo.type && sdpInfo.sdp) {
|
|
657
|
-
this.
|
|
594
|
+
if (this.signalingState === 'stable') {
|
|
595
|
+
this._currentLocalDescription = new _RTCSessionDescription.default(sdpInfo);
|
|
596
|
+
this._pendingLocalDescription = null;
|
|
597
|
+
} else {
|
|
598
|
+
this._currentLocalDescription = null;
|
|
599
|
+
this._pendingLocalDescription = new _RTCSessionDescription.default(sdpInfo);
|
|
600
|
+
}
|
|
658
601
|
} else {
|
|
659
|
-
this.
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
602
|
+
this._currentLocalDescription = null;
|
|
603
|
+
this._pendingLocalDescription = null;
|
|
604
|
+
}
|
|
663
605
|
this.dispatchEvent(new _RTCIceCandidateEvent.default('icecandidate', {
|
|
664
606
|
candidate: null
|
|
665
607
|
}));
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
|
|
608
|
+
}
|
|
669
609
|
this.dispatchEvent(new _RTCEvent.default('icegatheringstatechange'));
|
|
670
610
|
});
|
|
671
611
|
(0, _EventEmitter.addListener)(this, 'peerConnectionDidOpenDataChannel', ev => {
|
|
672
612
|
if (ev.pcId !== this._pcId) {
|
|
673
613
|
return;
|
|
674
614
|
}
|
|
675
|
-
|
|
676
|
-
const channel = new _RTCDataChannel.default(ev.dataChannel); // @ts-ignore
|
|
677
|
-
|
|
615
|
+
const channel = new _RTCDataChannel.default(ev.dataChannel);
|
|
678
616
|
this.dispatchEvent(new _RTCDataChannelEvent.default('datachannel', {
|
|
679
617
|
channel
|
|
680
618
|
}));
|
|
@@ -683,14 +621,13 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
683
621
|
if (ev.pcId !== this._pcId) {
|
|
684
622
|
return;
|
|
685
623
|
}
|
|
686
|
-
|
|
687
624
|
const [track] = this.getReceivers().map(r => r.track).filter(t => (t === null || t === void 0 ? void 0 : t.id) === ev.trackId);
|
|
688
|
-
|
|
689
625
|
if (track) {
|
|
690
626
|
track._setMutedInternal(ev.muted);
|
|
691
627
|
}
|
|
692
628
|
});
|
|
693
629
|
}
|
|
630
|
+
|
|
694
631
|
/**
|
|
695
632
|
* Creates a new RTCDataChannel object with the given label. The
|
|
696
633
|
* RTCDataChannelInit dictionary can be used to configure properties of the
|
|
@@ -702,86 +639,69 @@ class RTCPeerConnection extends (0, _eventTargetShim.defineCustomEventTarget)(..
|
|
|
702
639
|
* values with which to initialize corresponding attributes of the new
|
|
703
640
|
* instance such as id
|
|
704
641
|
*/
|
|
705
|
-
|
|
706
|
-
|
|
707
642
|
createDataChannel(label, dataChannelDict) {
|
|
708
643
|
if (dataChannelDict && 'id' in dataChannelDict) {
|
|
709
644
|
const id = dataChannelDict.id;
|
|
710
|
-
|
|
711
645
|
if (typeof id !== 'number') {
|
|
712
646
|
throw new TypeError('DataChannel id must be a number: ' + id);
|
|
713
647
|
}
|
|
714
648
|
}
|
|
715
|
-
|
|
716
649
|
const channelInfo = WebRTCModule.createDataChannel(this._pcId, label, dataChannelDict);
|
|
717
|
-
|
|
718
650
|
if (channelInfo === null) {
|
|
719
651
|
throw new TypeError('Failed to create new DataChannel');
|
|
720
652
|
}
|
|
721
|
-
|
|
722
653
|
return new _RTCDataChannel.default(channelInfo);
|
|
723
654
|
}
|
|
655
|
+
|
|
724
656
|
/**
|
|
725
657
|
* Check whether a media stream track exists already in a sender.
|
|
726
658
|
* See https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtrack for more information
|
|
727
659
|
*/
|
|
728
|
-
|
|
729
|
-
|
|
730
660
|
_trackExists(track) {
|
|
731
661
|
const [sender] = this.getSenders().filter(sender => {
|
|
732
662
|
var _sender$track;
|
|
733
|
-
|
|
734
663
|
return ((_sender$track = sender.track) === null || _sender$track === void 0 ? void 0 : _sender$track.id) === track.id;
|
|
735
664
|
});
|
|
736
665
|
return sender ? true : false;
|
|
737
666
|
}
|
|
667
|
+
|
|
738
668
|
/**
|
|
739
669
|
* Updates transceivers after offer/answer updates if necessary.
|
|
740
670
|
*/
|
|
741
|
-
|
|
742
|
-
|
|
743
671
|
_updateTransceivers(transceiverUpdates) {
|
|
744
672
|
let removeStopped = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
745
|
-
|
|
746
673
|
for (const update of transceiverUpdates) {
|
|
747
674
|
const [transceiver] = this.getTransceivers().filter(t => t.sender.id === update.transceiverId);
|
|
748
|
-
|
|
749
675
|
if (!transceiver) {
|
|
750
676
|
continue;
|
|
751
677
|
}
|
|
752
|
-
|
|
753
|
-
|
|
678
|
+
if (update.currentDirection) {
|
|
679
|
+
transceiver._currentDirection = update.currentDirection;
|
|
680
|
+
}
|
|
754
681
|
transceiver._mid = update.mid;
|
|
755
682
|
transceiver._stopped = Boolean(update.isStopped);
|
|
756
683
|
transceiver._sender._rtpParameters = new _RTCRtpSendParameters.default(update.senderRtpParameters);
|
|
757
684
|
transceiver._receiver._rtpParameters = new _RTCRtpReceiveParameters.default(update.receiverRtpParameters);
|
|
758
685
|
}
|
|
759
|
-
|
|
760
686
|
if (removeStopped) {
|
|
761
687
|
const stopped = this.getTransceivers().filter(t => t.stopped);
|
|
762
|
-
|
|
763
688
|
const newTransceivers = this._transceivers.filter(t => !stopped.includes(t.transceiver));
|
|
764
|
-
|
|
765
689
|
this._transceivers = newTransceivers;
|
|
766
690
|
}
|
|
767
691
|
}
|
|
692
|
+
|
|
768
693
|
/**
|
|
769
694
|
* Inserts transceiver into the transceiver array in the order they are created (timestamp).
|
|
770
695
|
* @param order an index that refers to when it it was created relatively.
|
|
771
696
|
* @param transceiver the transceiver object to be inserted.
|
|
772
697
|
*/
|
|
773
|
-
|
|
774
|
-
|
|
775
698
|
_insertTransceiverSorted(order, transceiver) {
|
|
776
699
|
this._transceivers.push({
|
|
777
700
|
order,
|
|
778
701
|
transceiver
|
|
779
702
|
});
|
|
780
|
-
|
|
781
703
|
this._transceivers.sort((a, b) => a.order - b.order);
|
|
782
704
|
}
|
|
783
|
-
|
|
784
705
|
}
|
|
785
|
-
|
|
786
706
|
exports.default = RTCPeerConnection;
|
|
787
707
|
//# sourceMappingURL=RTCPeerConnection.js.map
|