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