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