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.
Files changed (260) hide show
  1. package/README.md +13 -10
  2. package/android/src/main/java/com/oney/WebRTCModule/PeerConnectionObserver.java +18 -0
  3. package/android/src/main/java/com/oney/WebRTCModule/SerializeUtils.java +1 -1
  4. package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +13 -26
  5. package/ios/RCTWebRTC/CaptureController.m +4 -0
  6. package/ios/RCTWebRTC/ScreenCaptureController.m +4 -0
  7. package/ios/RCTWebRTC/ScreenCapturePickerViewManager.m +2 -2
  8. package/ios/RCTWebRTC/ScreenCapturer.m +4 -0
  9. package/ios/RCTWebRTC/SerializeUtils.m +12 -10
  10. package/ios/RCTWebRTC/TrackCapturerEventsEmitter.m +1 -1
  11. package/ios/RCTWebRTC/VideoCaptureController.h +2 -1
  12. package/ios/RCTWebRTC/VideoCaptureController.m +3 -0
  13. package/ios/RCTWebRTC/WebRTCModule+Permissions.m +10 -1
  14. package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.h +1 -1
  15. package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m +40 -3
  16. package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +30 -19
  17. package/ios/RCTWebRTC/WebRTCModule.m +3 -1
  18. package/ios/RCTWebRTC/WebRTCModuleOptions.h +1 -0
  19. package/ios/RCTWebRTC/WebRTCModuleOptions.m +1 -0
  20. package/ios/RCTWebRTC.xcodeproj/project.pbxproj +1 -0
  21. package/lib/commonjs/EventEmitter.js +4 -16
  22. package/lib/commonjs/EventEmitter.js.map +1 -1
  23. package/lib/commonjs/Logger.js +2 -26
  24. package/lib/commonjs/Logger.js.map +1 -1
  25. package/lib/commonjs/MediaDevices.js +2 -14
  26. package/lib/commonjs/MediaDevices.js.map +1 -1
  27. package/lib/commonjs/MediaStream.js +8 -45
  28. package/lib/commonjs/MediaStream.js.map +1 -1
  29. package/lib/commonjs/MediaStreamError.js +0 -11
  30. package/lib/commonjs/MediaStreamError.js.map +1 -1
  31. package/lib/commonjs/MediaStreamErrorEvent.js +0 -9
  32. package/lib/commonjs/MediaStreamErrorEvent.js.map +1 -1
  33. package/lib/commonjs/MediaStreamEvent.js +0 -9
  34. package/lib/commonjs/MediaStreamEvent.js.map +1 -1
  35. package/lib/commonjs/MediaStreamTrack.js +6 -65
  36. package/lib/commonjs/MediaStreamTrack.js.map +1 -1
  37. package/lib/commonjs/MediaStreamTrackEvent.js +11 -10
  38. package/lib/commonjs/MediaStreamTrackEvent.js.map +1 -1
  39. package/lib/commonjs/MessageEvent.js +12 -10
  40. package/lib/commonjs/MessageEvent.js.map +1 -1
  41. package/lib/commonjs/Permissions.js +19 -29
  42. package/lib/commonjs/Permissions.js.map +1 -1
  43. package/lib/commonjs/RTCDataChannel.js +8 -78
  44. package/lib/commonjs/RTCDataChannel.js.map +1 -1
  45. package/lib/commonjs/RTCDataChannelEvent.js +11 -10
  46. package/lib/commonjs/RTCDataChannelEvent.js.map +1 -1
  47. package/lib/commonjs/RTCErrorEvent.js +2 -15
  48. package/lib/commonjs/RTCErrorEvent.js.map +1 -1
  49. package/lib/commonjs/RTCEvent.js +13 -10
  50. package/lib/commonjs/RTCEvent.js.map +1 -1
  51. package/lib/commonjs/RTCIceCandidate.js +0 -14
  52. package/lib/commonjs/RTCIceCandidate.js.map +1 -1
  53. package/lib/commonjs/RTCIceCandidateEvent.js +13 -13
  54. package/lib/commonjs/RTCIceCandidateEvent.js.map +1 -1
  55. package/lib/commonjs/RTCPeerConnection.js +175 -255
  56. package/lib/commonjs/RTCPeerConnection.js.map +1 -1
  57. package/lib/commonjs/RTCRtcpParameters.js +0 -10
  58. package/lib/commonjs/RTCRtcpParameters.js.map +1 -1
  59. package/lib/commonjs/RTCRtpCapabilities.js +5 -22
  60. package/lib/commonjs/RTCRtpCapabilities.js.map +1 -1
  61. package/lib/commonjs/RTCRtpCodecCapability.js +0 -8
  62. package/lib/commonjs/RTCRtpCodecCapability.js.map +1 -1
  63. package/lib/commonjs/RTCRtpCodecParameters.js +0 -19
  64. package/lib/commonjs/RTCRtpCodecParameters.js.map +1 -1
  65. package/lib/commonjs/RTCRtpEncodingParameters.js +4 -34
  66. package/lib/commonjs/RTCRtpEncodingParameters.js.map +1 -1
  67. package/lib/commonjs/RTCRtpHeaderExtension.js +0 -12
  68. package/lib/commonjs/RTCRtpHeaderExtension.js.map +1 -1
  69. package/lib/commonjs/RTCRtpParameters.js +2 -18
  70. package/lib/commonjs/RTCRtpParameters.js.map +1 -1
  71. package/lib/commonjs/RTCRtpReceiveParameters.js +0 -5
  72. package/lib/commonjs/RTCRtpReceiveParameters.js.map +1 -1
  73. package/lib/commonjs/RTCRtpReceiver.js +1 -26
  74. package/lib/commonjs/RTCRtpReceiver.js.map +1 -1
  75. package/lib/commonjs/RTCRtpSendParameters.js +0 -22
  76. package/lib/commonjs/RTCRtpSendParameters.js.map +1 -1
  77. package/lib/commonjs/RTCRtpSender.js +1 -30
  78. package/lib/commonjs/RTCRtpSender.js.map +1 -1
  79. package/lib/commonjs/RTCRtpTransceiver.js +3 -38
  80. package/lib/commonjs/RTCRtpTransceiver.js.map +1 -1
  81. package/lib/commonjs/RTCSessionDescription.js +0 -13
  82. package/lib/commonjs/RTCSessionDescription.js.map +1 -1
  83. package/lib/commonjs/RTCTrackEvent.js +16 -14
  84. package/lib/commonjs/RTCTrackEvent.js.map +1 -1
  85. package/lib/commonjs/RTCUtil.js +9 -36
  86. package/lib/commonjs/RTCUtil.js.map +1 -1
  87. package/lib/commonjs/RTCView.js +6 -3
  88. package/lib/commonjs/RTCView.js.map +1 -1
  89. package/lib/commonjs/ScreenCapturePickerView.js +0 -3
  90. package/lib/commonjs/ScreenCapturePickerView.js.map +1 -1
  91. package/lib/commonjs/getDisplayMedia.js +0 -6
  92. package/lib/commonjs/getDisplayMedia.js.map +1 -1
  93. package/lib/commonjs/getUserMedia.js +7 -28
  94. package/lib/commonjs/getUserMedia.js.map +1 -1
  95. package/lib/commonjs/index.js +1 -26
  96. package/lib/commonjs/index.js.map +1 -1
  97. package/lib/module/EventEmitter.js +5 -12
  98. package/lib/module/EventEmitter.js.map +1 -1
  99. package/lib/module/Logger.js +2 -22
  100. package/lib/module/Logger.js.map +1 -1
  101. package/lib/module/MediaDevices.js +2 -7
  102. package/lib/module/MediaDevices.js.map +1 -1
  103. package/lib/module/MediaStream.js +9 -38
  104. package/lib/module/MediaStream.js.map +1 -1
  105. package/lib/module/MediaStreamError.js +0 -9
  106. package/lib/module/MediaStreamError.js.map +1 -1
  107. package/lib/module/MediaStreamErrorEvent.js +0 -7
  108. package/lib/module/MediaStreamErrorEvent.js.map +1 -1
  109. package/lib/module/MediaStreamEvent.js +0 -7
  110. package/lib/module/MediaStreamEvent.js.map +1 -1
  111. package/lib/module/MediaStreamTrack.js +6 -58
  112. package/lib/module/MediaStreamTrack.js.map +1 -1
  113. package/lib/module/MediaStreamTrackEvent.js +11 -8
  114. package/lib/module/MediaStreamTrackEvent.js.map +1 -1
  115. package/lib/module/MessageEvent.js +12 -8
  116. package/lib/module/MessageEvent.js.map +1 -1
  117. package/lib/module/Permissions.js +19 -26
  118. package/lib/module/Permissions.js.map +1 -1
  119. package/lib/module/RTCDataChannel.js +9 -67
  120. package/lib/module/RTCDataChannel.js.map +1 -1
  121. package/lib/module/RTCDataChannelEvent.js +11 -8
  122. package/lib/module/RTCDataChannelEvent.js.map +1 -1
  123. package/lib/module/RTCErrorEvent.js +2 -11
  124. package/lib/module/RTCErrorEvent.js.map +1 -1
  125. package/lib/module/RTCEvent.js +13 -7
  126. package/lib/module/RTCEvent.js.map +1 -1
  127. package/lib/module/RTCIceCandidate.js +0 -12
  128. package/lib/module/RTCIceCandidate.js.map +1 -1
  129. package/lib/module/RTCIceCandidateEvent.js +13 -11
  130. package/lib/module/RTCIceCandidateEvent.js.map +1 -1
  131. package/lib/module/RTCPeerConnection.js +176 -230
  132. package/lib/module/RTCPeerConnection.js.map +1 -1
  133. package/lib/module/RTCRtcpParameters.js +0 -8
  134. package/lib/module/RTCRtcpParameters.js.map +1 -1
  135. package/lib/module/RTCRtpCapabilities.js +5 -17
  136. package/lib/module/RTCRtpCapabilities.js.map +1 -1
  137. package/lib/module/RTCRtpCodecCapability.js +0 -6
  138. package/lib/module/RTCRtpCodecCapability.js.map +1 -1
  139. package/lib/module/RTCRtpCodecParameters.js +0 -17
  140. package/lib/module/RTCRtpCodecParameters.js.map +1 -1
  141. package/lib/module/RTCRtpEncodingParameters.js +4 -32
  142. package/lib/module/RTCRtpEncodingParameters.js.map +1 -1
  143. package/lib/module/RTCRtpHeaderExtension.js +0 -10
  144. package/lib/module/RTCRtpHeaderExtension.js.map +1 -1
  145. package/lib/module/RTCRtpParameters.js +2 -12
  146. package/lib/module/RTCRtpParameters.js.map +1 -1
  147. package/lib/module/RTCRtpReceiveParameters.js +0 -1
  148. package/lib/module/RTCRtpReceiveParameters.js.map +1 -1
  149. package/lib/module/RTCRtpReceiver.js +1 -19
  150. package/lib/module/RTCRtpReceiver.js.map +1 -1
  151. package/lib/module/RTCRtpSendParameters.js +0 -18
  152. package/lib/module/RTCRtpSendParameters.js.map +1 -1
  153. package/lib/module/RTCRtpSender.js +1 -23
  154. package/lib/module/RTCRtpSender.js.map +1 -1
  155. package/lib/module/RTCRtpTransceiver.js +3 -34
  156. package/lib/module/RTCRtpTransceiver.js.map +1 -1
  157. package/lib/module/RTCSessionDescription.js +0 -11
  158. package/lib/module/RTCSessionDescription.js.map +1 -1
  159. package/lib/module/RTCTrackEvent.js +16 -12
  160. package/lib/module/RTCTrackEvent.js.map +1 -1
  161. package/lib/module/RTCUtil.js +9 -32
  162. package/lib/module/RTCUtil.js.map +1 -1
  163. package/lib/module/RTCView.js +1 -0
  164. package/lib/module/RTCView.js.map +1 -1
  165. package/lib/module/ScreenCapturePickerView.js.map +1 -1
  166. package/lib/module/getDisplayMedia.js.map +1 -1
  167. package/lib/module/getUserMedia.js +7 -18
  168. package/lib/module/getUserMedia.js.map +1 -1
  169. package/lib/module/index.js +2 -7
  170. package/lib/module/index.js.map +1 -1
  171. package/lib/typescript/EventEmitter.d.ts +3 -2
  172. package/lib/typescript/EventEmitter.d.ts.map +1 -0
  173. package/lib/typescript/Logger.d.ts +1 -0
  174. package/lib/typescript/Logger.d.ts.map +1 -0
  175. package/lib/typescript/MediaDevices.d.ts +1 -0
  176. package/lib/typescript/MediaDevices.d.ts.map +1 -0
  177. package/lib/typescript/MediaStream.d.ts +15 -4
  178. package/lib/typescript/MediaStream.d.ts.map +1 -0
  179. package/lib/typescript/MediaStreamError.d.ts +1 -0
  180. package/lib/typescript/MediaStreamError.d.ts.map +1 -0
  181. package/lib/typescript/MediaStreamErrorEvent.d.ts +1 -0
  182. package/lib/typescript/MediaStreamErrorEvent.d.ts.map +1 -0
  183. package/lib/typescript/MediaStreamEvent.d.ts +1 -0
  184. package/lib/typescript/MediaStreamEvent.d.ts.map +1 -0
  185. package/lib/typescript/MediaStreamTrack.d.ts +2 -1
  186. package/lib/typescript/MediaStreamTrack.d.ts.map +1 -0
  187. package/lib/typescript/MediaStreamTrackEvent.d.ts +17 -5
  188. package/lib/typescript/MediaStreamTrackEvent.d.ts.map +1 -0
  189. package/lib/typescript/MessageEvent.d.ts +19 -6
  190. package/lib/typescript/MessageEvent.d.ts.map +1 -0
  191. package/lib/typescript/Permissions.d.ts +2 -1
  192. package/lib/typescript/Permissions.d.ts.map +1 -0
  193. package/lib/typescript/RTCDataChannel.d.ts +14 -4
  194. package/lib/typescript/RTCDataChannel.d.ts.map +1 -0
  195. package/lib/typescript/RTCDataChannelEvent.d.ts +17 -5
  196. package/lib/typescript/RTCDataChannelEvent.d.ts.map +1 -0
  197. package/lib/typescript/RTCErrorEvent.d.ts +5 -4
  198. package/lib/typescript/RTCErrorEvent.d.ts.map +1 -0
  199. package/lib/typescript/RTCEvent.d.ts +13 -3
  200. package/lib/typescript/RTCEvent.d.ts.map +1 -0
  201. package/lib/typescript/RTCIceCandidate.d.ts +8 -5
  202. package/lib/typescript/RTCIceCandidate.d.ts.map +1 -0
  203. package/lib/typescript/RTCIceCandidateEvent.d.ts +18 -3
  204. package/lib/typescript/RTCIceCandidateEvent.d.ts.map +1 -0
  205. package/lib/typescript/RTCPeerConnection.d.ts +34 -10
  206. package/lib/typescript/RTCPeerConnection.d.ts.map +1 -0
  207. package/lib/typescript/RTCRtcpParameters.d.ts +1 -0
  208. package/lib/typescript/RTCRtcpParameters.d.ts.map +1 -0
  209. package/lib/typescript/RTCRtpCapabilities.d.ts +1 -0
  210. package/lib/typescript/RTCRtpCapabilities.d.ts.map +1 -0
  211. package/lib/typescript/RTCRtpCodecCapability.d.ts +1 -0
  212. package/lib/typescript/RTCRtpCodecCapability.d.ts.map +1 -0
  213. package/lib/typescript/RTCRtpCodecParameters.d.ts +1 -0
  214. package/lib/typescript/RTCRtpCodecParameters.d.ts.map +1 -0
  215. package/lib/typescript/RTCRtpEncodingParameters.d.ts +1 -0
  216. package/lib/typescript/RTCRtpEncodingParameters.d.ts.map +1 -0
  217. package/lib/typescript/RTCRtpHeaderExtension.d.ts +1 -0
  218. package/lib/typescript/RTCRtpHeaderExtension.d.ts.map +1 -0
  219. package/lib/typescript/RTCRtpParameters.d.ts +1 -0
  220. package/lib/typescript/RTCRtpParameters.d.ts.map +1 -0
  221. package/lib/typescript/RTCRtpReceiveParameters.d.ts +1 -0
  222. package/lib/typescript/RTCRtpReceiveParameters.d.ts.map +1 -0
  223. package/lib/typescript/RTCRtpReceiver.d.ts +1 -0
  224. package/lib/typescript/RTCRtpReceiver.d.ts.map +1 -0
  225. package/lib/typescript/RTCRtpSendParameters.d.ts +2 -1
  226. package/lib/typescript/RTCRtpSendParameters.d.ts.map +1 -0
  227. package/lib/typescript/RTCRtpSender.d.ts +1 -0
  228. package/lib/typescript/RTCRtpSender.d.ts.map +1 -0
  229. package/lib/typescript/RTCRtpTransceiver.d.ts +1 -0
  230. package/lib/typescript/RTCRtpTransceiver.d.ts.map +1 -0
  231. package/lib/typescript/RTCSessionDescription.d.ts +1 -0
  232. package/lib/typescript/RTCSessionDescription.d.ts.map +1 -0
  233. package/lib/typescript/RTCTrackEvent.d.ts +21 -6
  234. package/lib/typescript/RTCTrackEvent.d.ts.map +1 -0
  235. package/lib/typescript/RTCUtil.d.ts +1 -0
  236. package/lib/typescript/RTCUtil.d.ts.map +1 -0
  237. package/lib/typescript/RTCView.d.ts +1 -0
  238. package/lib/typescript/RTCView.d.ts.map +1 -0
  239. package/lib/typescript/ScreenCapturePickerView.d.ts +1 -0
  240. package/lib/typescript/ScreenCapturePickerView.d.ts.map +1 -0
  241. package/lib/typescript/getDisplayMedia.d.ts +1 -0
  242. package/lib/typescript/getDisplayMedia.d.ts.map +1 -0
  243. package/lib/typescript/getUserMedia.d.ts +1 -0
  244. package/lib/typescript/getUserMedia.d.ts.map +1 -0
  245. package/lib/typescript/index.d.ts +1 -0
  246. package/lib/typescript/index.d.ts.map +1 -0
  247. package/package.json +2 -4
  248. package/react-native-webrtc.podspec +1 -1
  249. package/src/MediaStream.ts +14 -4
  250. package/src/MediaStreamTrackEvent.ts +18 -4
  251. package/src/MessageEvent.ts +19 -5
  252. package/src/RTCDataChannel.ts +10 -8
  253. package/src/RTCDataChannelEvent.ts +21 -4
  254. package/src/RTCErrorEvent.ts +3 -3
  255. package/src/RTCEvent.ts +18 -4
  256. package/src/RTCIceCandidate.ts +7 -1
  257. package/src/RTCIceCandidateEvent.ts +19 -4
  258. package/src/RTCPeerConnection.ts +114 -52
  259. package/src/RTCTrackEvent.ts +25 -4
  260. package/src/index.ts +1 -2
@@ -1,15 +1,21 @@
1
1
 
2
- import { defineCustomEventTarget } from 'event-target-shim';
2
+ import EventTarget from 'event-target-shim';
3
3
  import { NativeModules } from 'react-native';
4
4
 
5
5
  import MediaStreamTrack from './MediaStreamTrack';
6
+ import MediaStreamTrackEvent from './MediaStreamTrackEvent';
6
7
  import { uniqueID } from './RTCUtil';
7
8
 
8
9
  const { WebRTCModule } = NativeModules;
9
10
 
10
- const MEDIA_STREAM_EVENTS = [ 'active', 'inactive', 'addtrack', 'removetrack' ];
11
+ type MediaStreamEventMap = {
12
+ active: MediaStreamTrackEvent<'active'>
13
+ inactive: MediaStreamTrackEvent<'inactive'>
14
+ addtrack: MediaStreamTrackEvent<'addtrack'>
15
+ removetrack: MediaStreamTrackEvent<'removetrack'>
16
+ }
11
17
 
12
- export default class MediaStream extends defineCustomEventTarget(...MEDIA_STREAM_EVENTS) {
18
+ export default class MediaStream extends EventTarget<MediaStreamEventMap> {
13
19
  _tracks: MediaStreamTrack[] = [];
14
20
 
15
21
  _id: string;
@@ -35,7 +41,11 @@ export default class MediaStream extends defineCustomEventTarget(...MEDIA_STREAM
35
41
  * done internally, when the stream is first created in native and the JS wrapper is
36
42
  * built afterwards.
37
43
  */
38
- constructor(arg) {
44
+ constructor(arg?:
45
+ MediaStream |
46
+ MediaStreamTrack[] |
47
+ { streamId: string, streamReactTag: string, tracks: MediaStreamTrack[] }
48
+ ) {
39
49
  super();
40
50
 
41
51
  // Assign a UUID to start with. It will get overridden for remote streams.
@@ -1,11 +1,25 @@
1
+ import { Event } from 'event-target-shim';
1
2
 
2
3
  import type MediaStreamTrack from './MediaStreamTrack';
3
4
 
4
- export default class MediaStreamTrackEvent {
5
- type: string;
5
+ type MEDIA_STREAM_EVENTS = 'active'| 'inactive'| 'addtrack'| 'removetrack'
6
+
7
+ interface IMediaStreamTrackEventInitDict extends Event.EventInit {
8
+ track: MediaStreamTrack;
9
+ }
10
+
11
+ /**
12
+ * @eventClass
13
+ * This event is fired whenever the MediaStreamTrack has changed in any way.
14
+ * @param {MEDIA_STREAM_EVENTS} type - The type of event.
15
+ * @param {IMediaStreamTrackEventInitDict} eventInitDict - The event init properties.
16
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/MediaStream#events MDN} for details.
17
+ */
18
+ export default class MediaStreamTrackEvent<TEventType extends MEDIA_STREAM_EVENTS> extends Event<TEventType> {
19
+ /** @eventProperty */
6
20
  track: MediaStreamTrack;
7
- constructor(type, eventInitDict: { track: MediaStreamTrack }) {
8
- this.type = type.toString();
21
+ constructor(type: TEventType, eventInitDict: IMediaStreamTrackEventInitDict) {
22
+ super(type, eventInitDict);
9
23
  this.track = eventInitDict.track;
10
24
  }
11
25
  }
@@ -1,11 +1,25 @@
1
-
1
+ import { Event } from 'event-target-shim';
2
2
  export type MessageEventData = string | ArrayBuffer | Blob;
3
3
 
4
- export default class MessageEvent {
5
- type: string;
4
+ type MESSAGE_EVENTS = 'message' | 'messageerror';
5
+
6
+ interface IMessageEventInitDict extends Event.EventInit {
7
+ data: MessageEventData;
8
+ }
9
+
10
+ /**
11
+ * @eventClass
12
+ * This event is fired whenever the RTCDataChannel send message.
13
+ * @param {MESSAGE_EVENTS} type - The type of event.
14
+ * @param {IMessageEventInitDict} eventInitDict - The event init properties.
15
+ * @see
16
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel/message_event#event_type MDN} for details.
17
+ */
18
+ export default class MessageEvent<TEventType extends MESSAGE_EVENTS> extends Event<TEventType> {
19
+ /** @eventProperty */
6
20
  data: MessageEventData;
7
- constructor(type: string, eventInitDict: { data: MessageEventData }) {
8
- this.type = type.toString();
21
+ constructor(type: TEventType, eventInitDict: IMessageEventInitDict) {
22
+ super(type, eventInitDict);
9
23
  this.data = eventInitDict.data;
10
24
  }
11
25
  }
@@ -1,6 +1,6 @@
1
1
 
2
2
  import * as base64 from 'base64-js';
3
- import { defineCustomEventTarget } from 'event-target-shim';
3
+ import { EventTarget } from 'event-target-shim';
4
4
  import { NativeModules } from 'react-native';
5
5
 
6
6
  import { addListener, removeListener } from './EventEmitter';
@@ -11,9 +11,16 @@ const { WebRTCModule } = NativeModules;
11
11
 
12
12
  type RTCDataChannelState = 'connecting' | 'open' | 'closing' | 'closed';
13
13
 
14
- const DATA_CHANNEL_EVENTS = [ 'open', 'message', 'bufferedamountlow', 'closing', 'close', 'error' ];
14
+ type DataChannelEventMap = {
15
+ bufferedamountlow: RTCDataChannelEvent<'bufferedamountlow'>;
16
+ close: RTCDataChannelEvent<'close'>;
17
+ closing: RTCDataChannelEvent<'closing'>;
18
+ error: RTCDataChannelEvent<'error'>;
19
+ message: MessageEvent<'message'>;
20
+ open: RTCDataChannelEvent<'open'>;
21
+ };
15
22
 
16
- export default class RTCDataChannel extends defineCustomEventTarget(...DATA_CHANNEL_EVENTS) {
23
+ export default class RTCDataChannel extends EventTarget<DataChannelEventMap> {
17
24
  _peerConnectionId: number;
18
25
  _reactTag: string;
19
26
 
@@ -130,13 +137,10 @@ export default class RTCDataChannel extends defineCustomEventTarget(...DATA_CHAN
130
137
  }
131
138
 
132
139
  if (this._readyState === 'open') {
133
- // @ts-ignore
134
140
  this.dispatchEvent(new RTCDataChannelEvent('open', { channel: this }));
135
141
  } else if (this._readyState === 'closing') {
136
- // @ts-ignore
137
142
  this.dispatchEvent(new RTCDataChannelEvent('closing', { channel: this }));
138
143
  } else if (this._readyState === 'closed') {
139
- // @ts-ignore
140
144
  this.dispatchEvent(new RTCDataChannelEvent('close', { channel: this }));
141
145
 
142
146
  // This DataChannel is done, clean up event handlers.
@@ -157,7 +161,6 @@ export default class RTCDataChannel extends defineCustomEventTarget(...DATA_CHAN
157
161
  data = base64.toByteArray(ev.data).buffer;
158
162
  }
159
163
 
160
- // @ts-ignore
161
164
  this.dispatchEvent(new MessageEvent('message', { data }));
162
165
  });
163
166
 
@@ -169,7 +172,6 @@ export default class RTCDataChannel extends defineCustomEventTarget(...DATA_CHAN
169
172
  this._bufferedAmount = ev.bufferedAmount;
170
173
 
171
174
  if (this._bufferedAmount < this.bufferedAmountLowThreshold) {
172
- // @ts-ignore
173
175
  this.dispatchEvent(new RTCDataChannelEvent('bufferedamountlow', { channel: this }));
174
176
  }
175
177
  });
@@ -1,11 +1,28 @@
1
+ import { Event } from 'event-target-shim';
1
2
 
2
3
  import type RTCDataChannel from './RTCDataChannel';
3
4
 
4
- export default class RTCDataChannelEvent {
5
- type: string;
5
+ type DATA_CHANNEL_EVENTS = 'open'| 'message'| 'bufferedamountlow'| 'closing'| 'close'| 'error' | 'datachannel';
6
+
7
+ interface IRTCDataChannelEventInitDict extends Event.EventInit {
8
+ channel: RTCDataChannel;
9
+ }
10
+
11
+
12
+ /**
13
+ * @eventClass
14
+ * This event is fired whenever the RTCDataChannel has changed in any way.
15
+ * @param {DATA_CHANNEL_EVENTS} type - The type of event.
16
+ * @param {IRTCDataChannelEventInitDict} eventInitDict - The event init properties.
17
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel#events MDN} for details.
18
+ */
19
+ export default class RTCDataChannelEvent<
20
+ TEventType extends DATA_CHANNEL_EVENTS
21
+ > extends Event<TEventType> {
22
+ /** @eventProperty */
6
23
  channel: RTCDataChannel;
7
- constructor(type, eventInitDict: { channel: RTCDataChannel }) {
8
- this.type = type.toString();
24
+ constructor(type: TEventType, eventInitDict: IRTCDataChannelEventInitDict) {
25
+ super(type, eventInitDict);
9
26
  this.channel = eventInitDict.channel;
10
27
  }
11
28
  }
@@ -1,4 +1,4 @@
1
- import RTCEvent from './RTCEvent';
1
+ import { Event } from 'event-target-shim';
2
2
 
3
3
  type RTCPeerConnectionErrorFunc =
4
4
  | 'addTransceiver'
@@ -10,10 +10,10 @@ type RTCPeerConnectionErrorFunc =
10
10
  * @brief This class Represents internal error happening on the native side as
11
11
  * part of asynchronous invocations to synchronous web APIs.
12
12
  */
13
- export default class RTCErrorEvent extends RTCEvent {
13
+ export default class RTCErrorEvent<TEventType extends RTCPeerConnectionErrorFunc> extends Event<TEventType> {
14
14
  readonly func: RTCPeerConnectionErrorFunc;
15
15
  readonly message: string;
16
- constructor(type: string, func: RTCPeerConnectionErrorFunc, message: string) {
16
+ constructor(type: TEventType, func: RTCPeerConnectionErrorFunc, message: string) {
17
17
  super(type);
18
18
  this.func = func;
19
19
  this.message = message;
package/src/RTCEvent.ts CHANGED
@@ -1,7 +1,21 @@
1
+ import { Event } from 'event-target-shim';
1
2
 
2
- export default class RTCEvent {
3
- type: string;
4
- constructor(type) {
5
- this.type = type.toString();
3
+ // Import for documentation purposes
4
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
5
+ import RTCIceCandidateEvent from './RTCIceCandidateEvent';
6
+
7
+ type RTC_EVENTS = 'connectionstatechange' | 'iceconnectionstatechange' | 'icegatheringstatechange' |
8
+ 'negotiationneeded' | 'signalingstatechange' | 'error'
9
+
10
+ /**
11
+ * @eventClass
12
+ * This event is fired whenever the RTC_EVENTS has changed except on icecandidate related.
13
+ * @type {RTCIceCandidateEvent} for icecandidate related.
14
+ * @param {RTC_EVENTS} type - The type of event.
15
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection#events MDN} for details.
16
+ */
17
+ export default class RTCEvent<TEventType extends RTC_EVENTS> extends Event<TEventType> {
18
+ constructor(type: TEventType, eventInitDict?: Event.EventInit) {
19
+ super(type, eventInitDict);
6
20
  }
7
21
  }
@@ -1,9 +1,15 @@
1
+ interface RTCIceCandidateInfo {
2
+ candidate?: string;
3
+ sdpMLineIndex?: number | null;
4
+ sdpMid?: string | null;
5
+ }
6
+
1
7
  export default class RTCIceCandidate {
2
8
  candidate: string;
3
9
  sdpMLineIndex: number;
4
10
  sdpMid: string;
5
11
 
6
- constructor({ candidate = '', sdpMLineIndex = null, sdpMid = null }) {
12
+ constructor({ candidate = '', sdpMLineIndex = null, sdpMid = null }: RTCIceCandidateInfo) {
7
13
  if (sdpMLineIndex === null || sdpMid === null) {
8
14
  throw new TypeError('`sdpMLineIndex` and `sdpMid` must not null');
9
15
  }
@@ -1,11 +1,26 @@
1
+ import { Event } from 'event-target-shim';
1
2
 
2
3
  import type RTCIceCandidate from './RTCIceCandidate';
3
4
 
4
- export default class RTCIceCandidateEvent {
5
- type: string;
5
+ type RTC_ICECANDIDATE_EVENTS = 'icecandidate' | 'icecandidateerror'
6
+
7
+ interface IRTCDataChannelEventInitDict extends Event.EventInit {
8
+ candidate: RTCIceCandidate | null
9
+ }
10
+
11
+ /**
12
+ * @eventClass
13
+ * This event is fired whenever the icecandidate related RTC_EVENTS changed.
14
+ * @type {RTCIceCandidateEvent} for icecandidate related.
15
+ * @param {RTC_ICECANDIDATE_EVENTS} type - The type of event.
16
+ * @param {IRTCDataChannelEventInitDict} eventInitDict - The event init properties.
17
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection#events MDN} for details.
18
+ */
19
+ export default class RTCIceCandidateEvent<TEventType extends RTC_ICECANDIDATE_EVENTS> extends Event<TEventType> {
20
+ /** @eventProperty */
6
21
  candidate: RTCIceCandidate | null;
7
- constructor(type, eventInitDict) {
8
- this.type = type.toString();
22
+ constructor(type: TEventType, eventInitDict: IRTCDataChannelEventInitDict) {
23
+ super(type, eventInitDict);
9
24
  this.candidate = eventInitDict?.candidate ?? null;
10
25
  }
11
26
  }
@@ -1,5 +1,5 @@
1
1
 
2
- import { defineCustomEventTarget } from 'event-target-shim';
2
+ import { EventTarget } from 'event-target-shim';
3
3
  import { NativeModules } from 'react-native';
4
4
 
5
5
  import { addListener, removeListener } from './EventEmitter';
@@ -47,25 +47,22 @@ type RTCDataChannelInit = {
47
47
  id?: number
48
48
  };
49
49
 
50
- const PEER_CONNECTION_EVENTS = [
51
- 'connectionstatechange',
52
- 'icecandidate',
53
- 'icecandidateerror',
54
- 'iceconnectionstatechange',
55
- 'icegatheringstatechange',
56
- 'negotiationneeded',
57
- 'signalingstatechange',
58
- 'datachannel',
59
- 'track',
60
- 'error'
61
- ];
50
+ type RTCPeerConnectionEventMap = {
51
+ connectionstatechange: RTCEvent<'connectionstatechange'>
52
+ icecandidate: RTCIceCandidateEvent<'icecandidate'>
53
+ icecandidateerror: RTCIceCandidateEvent<'icecandidateerror'>
54
+ iceconnectionstatechange: RTCEvent<'iceconnectionstatechange'>
55
+ icegatheringstatechange: RTCEvent<'icegatheringstatechange'>
56
+ negotiationneeded: RTCEvent<'negotiationneeded'>
57
+ signalingstatechange: RTCEvent<'signalingstatechange'>
58
+ datachannel: RTCDataChannelEvent<'datachannel'>
59
+ track: RTCTrackEvent<'track'>
60
+ error: RTCEvent<'error'>
61
+ }
62
62
 
63
63
  let nextPeerConnectionId = 0;
64
64
 
65
- export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_CONNECTION_EVENTS) {
66
- localDescription: RTCSessionDescription | null = null;
67
- remoteDescription: RTCSessionDescription | null = null;
68
-
65
+ export default class RTCPeerConnection extends EventTarget<RTCPeerConnectionEventMap> {
69
66
  signalingState: RTCSignalingState = 'stable';
70
67
  iceGatheringState: RTCIceGatheringState = 'new';
71
68
  connectionState: RTCPeerConnectionState = 'new';
@@ -76,11 +73,19 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
76
73
  _remoteStreams: Map<string, MediaStream>;
77
74
  _pendingTrackEvents: any[];
78
75
 
76
+ _currentLocalDescription: RTCSessionDescription | null = null;
77
+ _pendingLocalDescription: RTCSessionDescription | null = null;
78
+ _currentRemoteDescription: RTCSessionDescription | null = null;
79
+ _pendingRemoteDescription: RTCSessionDescription | null = null;
80
+
79
81
  constructor(configuration) {
80
82
  super();
81
83
 
82
84
  this._pcId = nextPeerConnectionId++;
83
- WebRTCModule.peerConnectionInit(configuration, this._pcId);
85
+
86
+ if (!WebRTCModule.peerConnectionInit(configuration, this._pcId)) {
87
+ throw new Error('Failed to initialize PeerConnection, check the native logs!');
88
+ }
84
89
 
85
90
  this._transceivers = [];
86
91
  this._remoteStreams = new Map();
@@ -91,6 +96,30 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
91
96
  log.debug(`${this._pcId} ctor`);
92
97
  }
93
98
 
99
+ get currentLocalDescription(): RTCSessionDescription | null {
100
+ return this._currentLocalDescription;
101
+ }
102
+
103
+ get pendingLocalDescription(): RTCSessionDescription | null {
104
+ return this._pendingLocalDescription;
105
+ }
106
+
107
+ get localDescription(): RTCSessionDescription | null {
108
+ return this._pendingLocalDescription || this._currentLocalDescription;
109
+ }
110
+
111
+ get currentRemoteDescription(): RTCSessionDescription | null {
112
+ return this._currentRemoteDescription;
113
+ }
114
+
115
+ get pendingRemoteDescription(): RTCSessionDescription | null {
116
+ return this._pendingRemoteDescription;
117
+ }
118
+
119
+ get remoteDescription(): RTCSessionDescription | null {
120
+ return this._pendingRemoteDescription || this._currentRemoteDescription;
121
+ }
122
+
94
123
  async createOffer(options) {
95
124
  log.debug(`${this._pcId} createOffer`);
96
125
 
@@ -157,16 +186,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
157
186
  desc = null;
158
187
  }
159
188
 
160
- const {
161
- sdpInfo,
162
- transceiversInfo
163
- } = await WebRTCModule.peerConnectionSetLocalDescription(this._pcId, desc);
164
-
165
- if (sdpInfo.type && sdpInfo.sdp) {
166
- this.localDescription = new RTCSessionDescription(sdpInfo);
167
- } else {
168
- this.localDescription = null;
169
- }
189
+ const { transceiversInfo } = await WebRTCModule.peerConnectionSetLocalDescription(this._pcId, desc);
170
190
 
171
191
  this._updateTransceivers(transceiversInfo, /* removeStopped */ desc?.type === 'answer');
172
192
 
@@ -190,17 +210,10 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
190
210
  }
191
211
 
192
212
  const {
193
- sdpInfo,
194
213
  newTransceivers,
195
214
  transceiversInfo
196
215
  } = await WebRTCModule.peerConnectionSetRemoteDescription(this._pcId, desc);
197
216
 
198
- if (sdpInfo.type && sdpInfo.sdp) {
199
- this.remoteDescription = new RTCSessionDescription(sdpInfo);
200
- } else {
201
- this.remoteDescription = null;
202
- }
203
-
204
217
  newTransceivers?.forEach(t => {
205
218
  const { transceiverOrder, transceiver } = t;
206
219
  const newSender = new RTCRtpSender({ ...transceiver.sender, track: null });
@@ -269,11 +282,10 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
269
282
  receiver: transceiver.receiver
270
283
  };
271
284
 
272
- // @ts-ignore
285
+
273
286
  this.dispatchEvent(new RTCTrackEvent('track', eventData));
274
287
 
275
288
  streams.forEach(stream => {
276
- // @ts-ignore
277
289
  stream.dispatchEvent(new MediaStreamTrackEvent('addtrack', { track }));
278
290
  });
279
291
 
@@ -306,7 +318,13 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
306
318
  candidate.toJSON ? candidate.toJSON() : candidate
307
319
  );
308
320
 
309
- this.remoteDescription = new RTCSessionDescription(newSdp);
321
+ if (this.signalingState === 'stable') {
322
+ this._currentRemoteDescription = new RTCSessionDescription(newSdp);
323
+ this._pendingRemoteDescription = null;
324
+ } else {
325
+ this._currentRemoteDescription = null;
326
+ this._pendingRemoteDescription = new RTCSessionDescription(newSdp);
327
+ }
310
328
  }
311
329
 
312
330
  /**
@@ -530,7 +548,6 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
530
548
  return;
531
549
  }
532
550
 
533
- // @ts-ignore
534
551
  this.dispatchEvent(new RTCEvent('negotiationneeded'));
535
552
  });
536
553
 
@@ -541,7 +558,6 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
541
558
 
542
559
  this.iceConnectionState = ev.iceConnectionState;
543
560
 
544
- // @ts-ignore
545
561
  this.dispatchEvent(new RTCEvent('iceconnectionstatechange'));
546
562
  });
547
563
 
@@ -552,7 +568,6 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
552
568
 
553
569
  this.connectionState = ev.connectionState;
554
570
 
555
- // @ts-ignore
556
571
  this.dispatchEvent(new RTCEvent('connectionstatechange'));
557
572
 
558
573
  if (ev.connectionState === 'closed') {
@@ -569,7 +584,42 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
569
584
  }
570
585
 
571
586
  this.signalingState = ev.signalingState;
572
- // @ts-ignore
587
+ const { localSdp, remoteSdp } = ev;
588
+
589
+ if (localSdp.type && localSdp.sdp) {
590
+ switch (this.signalingState) {
591
+ case 'stable':
592
+ this._currentLocalDescription = new RTCSessionDescription(localSdp);
593
+ this._pendingLocalDescription = null;
594
+ break;
595
+ case 'have-local-offer':
596
+ case 'have-local-pranswer':
597
+ this._currentLocalDescription = null;
598
+ this._pendingLocalDescription = new RTCSessionDescription(localSdp);
599
+ break;
600
+ }
601
+ } else {
602
+ this._currentLocalDescription = null;
603
+ this._pendingLocalDescription = null;
604
+ }
605
+
606
+ if (remoteSdp.type && remoteSdp.sdp) {
607
+ switch (this.signalingState) {
608
+ case 'stable':
609
+ this._currentRemoteDescription = new RTCSessionDescription(remoteSdp);
610
+ this._pendingRemoteDescription = null;
611
+ break;
612
+ case 'have-remote-offer':
613
+ case 'have-remote-pranswer':
614
+ this._currentRemoteDescription = null;
615
+ this._pendingRemoteDescription = new RTCSessionDescription(remoteSdp);
616
+ break;
617
+ }
618
+ } else {
619
+ this._currentRemoteDescription = null;
620
+ this._pendingRemoteDescription = null;
621
+ }
622
+
573
623
  this.dispatchEvent(new RTCEvent('signalingstatechange'));
574
624
  });
575
625
 
@@ -611,7 +661,6 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
611
661
 
612
662
  stream._tracks.splice(trackIdx, 1);
613
663
 
614
- // @ts-ignore
615
664
  stream.dispatchEvent(new MediaStreamTrackEvent('removetrack', { track }));
616
665
 
617
666
  // Dispatch a mute event for the track.
@@ -630,14 +679,20 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
630
679
 
631
680
  // Can happen when doing a rollback.
632
681
  if (sdpInfo.type && sdpInfo.sdp) {
633
- this.localDescription = new RTCSessionDescription(sdpInfo);
682
+ if (this.signalingState === 'stable') {
683
+ this._currentLocalDescription = new RTCSessionDescription(sdpInfo);
684
+ this._pendingLocalDescription = null;
685
+ } else {
686
+ this._currentLocalDescription = null;
687
+ this._pendingLocalDescription = new RTCSessionDescription(sdpInfo);
688
+ }
634
689
  } else {
635
- this.localDescription = null;
690
+ this._currentLocalDescription = null;
691
+ this._pendingLocalDescription = null;
636
692
  }
637
693
 
638
694
  const candidate = new RTCIceCandidate(ev.candidate);
639
695
 
640
- // @ts-ignore
641
696
  this.dispatchEvent(new RTCIceCandidateEvent('icecandidate', { candidate }));
642
697
  });
643
698
 
@@ -653,16 +708,21 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
653
708
 
654
709
  // Can happen when doing a rollback.
655
710
  if (sdpInfo.type && sdpInfo.sdp) {
656
- this.localDescription = new RTCSessionDescription(sdpInfo);
711
+ if (this.signalingState === 'stable') {
712
+ this._currentLocalDescription = new RTCSessionDescription(sdpInfo);
713
+ this._pendingLocalDescription = null;
714
+ } else {
715
+ this._currentLocalDescription = null;
716
+ this._pendingLocalDescription = new RTCSessionDescription(sdpInfo);
717
+ }
657
718
  } else {
658
- this.localDescription = null;
719
+ this._currentLocalDescription = null;
720
+ this._pendingLocalDescription = null;
659
721
  }
660
722
 
661
- // @ts-ignore
662
723
  this.dispatchEvent(new RTCIceCandidateEvent('icecandidate', { candidate: null }));
663
724
  }
664
725
 
665
- // @ts-ignore
666
726
  this.dispatchEvent(new RTCEvent('icegatheringstatechange'));
667
727
  });
668
728
 
@@ -673,7 +733,6 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
673
733
 
674
734
  const channel = new RTCDataChannel(ev.dataChannel);
675
735
 
676
- // @ts-ignore
677
736
  this.dispatchEvent(new RTCDataChannelEvent('datachannel', { channel }));
678
737
  });
679
738
 
@@ -748,7 +807,10 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
748
807
  continue;
749
808
  }
750
809
 
751
- transceiver._currentDirection = update.currentDirection;
810
+ if (update.currentDirection) {
811
+ transceiver._currentDirection = update.currentDirection;
812
+ }
813
+
752
814
  transceiver._mid = update.mid;
753
815
  transceiver._stopped = Boolean(update.isStopped);
754
816
  transceiver._sender._rtpParameters = new RTCRtpSendParameters(update.senderRtpParameters);
@@ -1,18 +1,39 @@
1
+ import { Event } from 'event-target-shim';
1
2
 
2
3
  import MediaStream from './MediaStream';
3
4
  import type MediaStreamTrack from './MediaStreamTrack';
4
5
  import RTCRtpReceiver from './RTCRtpReceiver';
5
6
  import RTCRtpTransceiver from './RTCRtpTransceiver';
6
7
 
7
- export default class RTCTrackEvent {
8
- type: string;
8
+ type TRACK_EVENTS = 'track'
9
+
10
+ interface IRTCTrackEventInitDict extends Event.EventInit {
11
+ streams: MediaStream[]
12
+ transceiver: RTCRtpTransceiver
13
+ }
14
+
15
+ /**
16
+ * @eventClass
17
+ * This event is fired whenever the Track is changed in PeerConnection.
18
+ * @param {TRACK_EVENTS} type - The type of event.
19
+ * @param {IRTCTrackEventInitDict} eventInitDict - The event init properties.
20
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/track_event MDN} for details.
21
+ */
22
+ export default class RTCTrackEvent<TEventType extends TRACK_EVENTS> extends Event<TEventType> {
23
+ /** @eventProperty */
9
24
  readonly streams: MediaStream[] = [];
25
+
26
+ /** @eventProperty */
10
27
  readonly transceiver: RTCRtpTransceiver;
28
+
29
+ /** @eventProperty */
11
30
  readonly receiver: RTCRtpReceiver | null;
31
+
32
+ /** @eventProperty */
12
33
  readonly track: MediaStreamTrack | null;
13
34
 
14
- constructor(type: string, eventInitDict: { streams: MediaStream[], transceiver: RTCRtpTransceiver }) {
15
- this.type = type.toString();
35
+ constructor(type: TEventType, eventInitDict: IRTCTrackEventInitDict) {
36
+ super(type, eventInitDict);
16
37
  this.streams = eventInitDict.streams;
17
38
  this.transceiver = eventInitDict.transceiver;
18
39
  this.receiver = eventInitDict.transceiver.receiver;
package/src/index.ts CHANGED
@@ -25,8 +25,7 @@ import RTCSessionDescription from './RTCSessionDescription';
25
25
  import RTCView from './RTCView';
26
26
  import ScreenCapturePickerView from './ScreenCapturePickerView';
27
27
 
28
- Logger.enable('*');
29
- // Logger.enable(`*,-${Logger.ROOT_PREFIX}:*:DEBUG`);
28
+ Logger.enable(`${Logger.ROOT_PREFIX}:*`);
30
29
 
31
30
  // Add listeners for the native events early, since they are added asynchronously.
32
31
  setupNativeEvents();