react-native-webrtc 106.0.0-beta.2 → 106.0.0-beta.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 (163) hide show
  1. package/.eslintignore +6 -0
  2. package/.github/stale.yml +15 -0
  3. package/.github/workflows/ci.yml +17 -0
  4. package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +36 -0
  5. package/android/src/main/java/com/oney/WebRTCModule/SerializeUtils.java +65 -26
  6. package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +30 -1
  7. package/android/src/main/java/com/oney/WebRTCModule/videoEffects/ProcessorProvider.java +37 -0
  8. package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoEffectProcessor.java +57 -0
  9. package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoFrameProcessor.java +19 -0
  10. package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoFrameProcessorFactoryInterface.java +13 -0
  11. package/ios/RCTWebRTC/SerializeUtils.m +18 -5
  12. package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +53 -5
  13. package/ios/RCTWebRTC/WebRTCModule+Transceivers.m +5 -4
  14. package/ios/RCTWebRTC.xcodeproj/project.pbxproj +46 -9
  15. package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  16. package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  17. package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/xcuserdata/saghul.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  18. package/ios/RCTWebRTC.xcodeproj/xcuserdata/saghul.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  19. package/ios/RCTWebRTC.xcworkspace/contents.xcworkspacedata +10 -0
  20. package/lib/commonjs/EventEmitter.js.map +1 -1
  21. package/lib/commonjs/Logger.js.map +1 -1
  22. package/lib/commonjs/MediaDevices.js +2 -2
  23. package/lib/commonjs/MediaDevices.js.map +1 -1
  24. package/lib/commonjs/MediaStream.js +3 -3
  25. package/lib/commonjs/MediaStream.js.map +1 -1
  26. package/lib/commonjs/MediaStreamTrack.js +15 -3
  27. package/lib/commonjs/MediaStreamTrack.js.map +1 -1
  28. package/lib/commonjs/Permissions.js +3 -3
  29. package/lib/commonjs/Permissions.js.map +1 -1
  30. package/lib/commonjs/RTCDataChannel.js +6 -5
  31. package/lib/commonjs/RTCDataChannel.js.map +1 -1
  32. package/lib/commonjs/RTCErrorEvent.js +1 -1
  33. package/lib/commonjs/RTCErrorEvent.js.map +1 -1
  34. package/lib/commonjs/RTCPeerConnection.js +139 -58
  35. package/lib/commonjs/RTCPeerConnection.js.map +1 -1
  36. package/lib/commonjs/RTCRtcpParameters.js +7 -0
  37. package/lib/commonjs/RTCRtcpParameters.js.map +1 -1
  38. package/lib/commonjs/RTCRtpCapabilities.js +10 -2
  39. package/lib/commonjs/RTCRtpCapabilities.js.map +1 -1
  40. package/lib/commonjs/RTCRtpCodecParameters.js +22 -4
  41. package/lib/commonjs/RTCRtpCodecParameters.js.map +1 -1
  42. package/lib/commonjs/RTCRtpEncodingParameters.js +21 -10
  43. package/lib/commonjs/RTCRtpEncodingParameters.js.map +1 -1
  44. package/lib/commonjs/RTCRtpHeaderExtension.js +8 -0
  45. package/lib/commonjs/RTCRtpHeaderExtension.js.map +1 -1
  46. package/lib/commonjs/RTCRtpParameters.js +25 -3
  47. package/lib/commonjs/RTCRtpParameters.js.map +1 -1
  48. package/lib/commonjs/RTCRtpReceiveParameters.js.map +1 -1
  49. package/lib/commonjs/RTCRtpReceiver.js +21 -10
  50. package/lib/commonjs/RTCRtpReceiver.js.map +1 -1
  51. package/lib/commonjs/RTCRtpSendParameters.js +10 -4
  52. package/lib/commonjs/RTCRtpSendParameters.js.map +1 -1
  53. package/lib/commonjs/RTCRtpSender.js +3 -3
  54. package/lib/commonjs/RTCRtpSender.js.map +1 -1
  55. package/lib/commonjs/RTCRtpTransceiver.js.map +1 -1
  56. package/lib/commonjs/RTCSessionDescription.js.map +1 -1
  57. package/lib/commonjs/RTCUtil.js +13 -0
  58. package/lib/commonjs/RTCUtil.js.map +1 -1
  59. package/lib/commonjs/getDisplayMedia.js.map +1 -1
  60. package/lib/commonjs/getUserMedia.js +3 -3
  61. package/lib/commonjs/getUserMedia.js.map +1 -1
  62. package/lib/commonjs/index.js +12 -93
  63. package/lib/commonjs/index.js.map +1 -1
  64. package/lib/module/EventEmitter.js.map +1 -1
  65. package/lib/module/Logger.js.map +1 -1
  66. package/lib/module/MediaDevices.js +1 -1
  67. package/lib/module/MediaDevices.js.map +1 -1
  68. package/lib/module/MediaStream.js +2 -2
  69. package/lib/module/MediaStream.js.map +1 -1
  70. package/lib/module/MediaStreamTrack.js +14 -2
  71. package/lib/module/MediaStreamTrack.js.map +1 -1
  72. package/lib/module/Permissions.js +3 -3
  73. package/lib/module/Permissions.js.map +1 -1
  74. package/lib/module/RTCDataChannel.js +4 -3
  75. package/lib/module/RTCDataChannel.js.map +1 -1
  76. package/lib/module/RTCErrorEvent.js +2 -2
  77. package/lib/module/RTCErrorEvent.js.map +1 -1
  78. package/lib/module/RTCPeerConnection.js +135 -55
  79. package/lib/module/RTCPeerConnection.js.map +1 -1
  80. package/lib/module/RTCRtcpParameters.js +7 -0
  81. package/lib/module/RTCRtcpParameters.js.map +1 -1
  82. package/lib/module/RTCRtpCapabilities.js +10 -2
  83. package/lib/module/RTCRtpCapabilities.js.map +1 -1
  84. package/lib/module/RTCRtpCodecParameters.js +22 -4
  85. package/lib/module/RTCRtpCodecParameters.js.map +1 -1
  86. package/lib/module/RTCRtpEncodingParameters.js +21 -10
  87. package/lib/module/RTCRtpEncodingParameters.js.map +1 -1
  88. package/lib/module/RTCRtpHeaderExtension.js +8 -0
  89. package/lib/module/RTCRtpHeaderExtension.js.map +1 -1
  90. package/lib/module/RTCRtpParameters.js +20 -3
  91. package/lib/module/RTCRtpParameters.js.map +1 -1
  92. package/lib/module/RTCRtpReceiveParameters.js +1 -1
  93. package/lib/module/RTCRtpReceiveParameters.js.map +1 -1
  94. package/lib/module/RTCRtpReceiver.js +18 -8
  95. package/lib/module/RTCRtpReceiver.js.map +1 -1
  96. package/lib/module/RTCRtpSendParameters.js +10 -5
  97. package/lib/module/RTCRtpSendParameters.js.map +1 -1
  98. package/lib/module/RTCRtpSender.js +3 -3
  99. package/lib/module/RTCRtpSender.js.map +1 -1
  100. package/lib/module/RTCRtpTransceiver.js.map +1 -1
  101. package/lib/module/RTCSessionDescription.js.map +1 -1
  102. package/lib/module/RTCUtil.js +11 -0
  103. package/lib/module/RTCUtil.js.map +1 -1
  104. package/lib/module/getDisplayMedia.js.map +1 -1
  105. package/lib/module/getUserMedia.js +1 -1
  106. package/lib/module/getUserMedia.js.map +1 -1
  107. package/lib/module/index.js +8 -26
  108. package/lib/module/index.js.map +1 -1
  109. package/lib/typescript/EventEmitter.d.ts +4 -3
  110. package/lib/typescript/MediaStreamTrack.d.ts +1 -0
  111. package/lib/typescript/Permissions.d.ts +1 -1
  112. package/lib/typescript/RTCDataChannel.d.ts +2 -1
  113. package/lib/typescript/RTCErrorEvent.d.ts +1 -1
  114. package/lib/typescript/RTCPeerConnection.d.ts +7 -8
  115. package/lib/typescript/RTCRtcpParameters.d.ts +6 -4
  116. package/lib/typescript/RTCRtpCodecParameters.d.ts +11 -9
  117. package/lib/typescript/RTCRtpEncodingParameters.d.ts +13 -11
  118. package/lib/typescript/RTCRtpHeaderExtension.d.ts +7 -5
  119. package/lib/typescript/RTCRtpParameters.d.ts +9 -8
  120. package/lib/typescript/RTCRtpReceiveParameters.d.ts +1 -1
  121. package/lib/typescript/RTCRtpReceiver.d.ts +9 -4
  122. package/lib/typescript/RTCRtpSendParameters.d.ts +9 -10
  123. package/lib/typescript/RTCRtpSender.d.ts +3 -3
  124. package/lib/typescript/RTCRtpTransceiver.d.ts +1 -1
  125. package/lib/typescript/RTCSessionDescription.d.ts +6 -8
  126. package/lib/typescript/RTCUtil.d.ts +7 -0
  127. package/lib/typescript/index.d.ts +6 -15
  128. package/package.json +7 -4
  129. package/react-native-webrtc.podspec +1 -2
  130. package/src/.eslintrc.cjs +67 -0
  131. package/src/EventEmitter.ts +5 -4
  132. package/src/Logger.ts +1 -1
  133. package/src/MediaDevices.ts +2 -2
  134. package/src/MediaStream.ts +13 -4
  135. package/src/MediaStreamTrack.ts +21 -5
  136. package/src/Permissions.ts +12 -5
  137. package/src/RTCDataChannel.ts +17 -5
  138. package/src/RTCErrorEvent.ts +9 -9
  139. package/src/RTCPeerConnection.ts +189 -91
  140. package/src/RTCRtcpParameters.ts +21 -12
  141. package/src/RTCRtpCapabilities.ts +15 -4
  142. package/src/RTCRtpCodecParameters.ts +34 -13
  143. package/src/RTCRtpEncodingParameters.ts +37 -23
  144. package/src/RTCRtpHeaderExtension.ts +15 -6
  145. package/src/RTCRtpParameters.ts +26 -11
  146. package/src/RTCRtpReceiveParameters.ts +3 -3
  147. package/src/RTCRtpReceiver.ts +26 -10
  148. package/src/RTCRtpSendParameters.ts +29 -17
  149. package/src/RTCRtpSender.ts +14 -13
  150. package/src/RTCRtpTransceiver.ts +11 -7
  151. package/src/RTCSessionDescription.ts +7 -2
  152. package/src/RTCUtil.ts +24 -4
  153. package/src/getDisplayMedia.ts +1 -1
  154. package/src/getUserMedia.ts +9 -2
  155. package/src/index.ts +9 -34
  156. package/tools/downloadWebRTC.js +7 -5
  157. package/.prettierignore +0 -9
  158. package/.prettierrc.json +0 -10
  159. package/lib/commonjs/typings.d.js +0 -2
  160. package/lib/commonjs/typings.d.js.map +0 -1
  161. package/lib/module/typings.d.js +0 -2
  162. package/lib/module/typings.d.js.map +0 -1
  163. package/src/typings.d.ts +0 -1
@@ -1,13 +1,13 @@
1
1
 
2
- import { NativeModules } from 'react-native';
3
2
  import { defineCustomEventTarget } from 'event-target-shim';
3
+ import { NativeModules } from 'react-native';
4
4
 
5
5
  import getDisplayMedia from './getDisplayMedia';
6
6
  import getUserMedia from './getUserMedia';
7
7
 
8
8
  const { WebRTCModule } = NativeModules;
9
9
 
10
- const MEDIA_DEVICES_EVENTS = ['devicechange'];
10
+ const MEDIA_DEVICES_EVENTS = [ 'devicechange' ];
11
11
 
12
12
  class MediaDevices extends defineCustomEventTarget(...MEDIA_DEVICES_EVENTS) {
13
13
  /**
@@ -1,13 +1,13 @@
1
1
 
2
- import { NativeModules } from 'react-native';
3
2
  import { defineCustomEventTarget } from 'event-target-shim';
4
- import { uniqueID } from './RTCUtil';
3
+ import { NativeModules } from 'react-native';
5
4
 
6
5
  import MediaStreamTrack from './MediaStreamTrack';
6
+ import { uniqueID } from './RTCUtil';
7
7
 
8
8
  const { WebRTCModule } = NativeModules;
9
9
 
10
- const MEDIA_STREAM_EVENTS = ['active', 'inactive', 'addtrack', 'removetrack'];
10
+ const MEDIA_STREAM_EVENTS = [ 'active', 'inactive', 'addtrack', 'removetrack' ];
11
11
 
12
12
  export default class MediaStream extends defineCustomEventTarget(...MEDIA_STREAM_EVENTS) {
13
13
  id: string;
@@ -51,17 +51,20 @@ export default class MediaStream extends defineCustomEventTarget(...MEDIA_STREAM
51
51
  WebRTCModule.mediaStreamCreate(this.id);
52
52
  } else if (arg instanceof MediaStream) {
53
53
  WebRTCModule.mediaStreamCreate(this.id);
54
+
54
55
  for (const track of arg.getTracks()) {
55
56
  this.addTrack(track);
56
57
  }
57
58
  } else if (Array.isArray(arg)) {
58
59
  WebRTCModule.mediaStreamCreate(this.id);
60
+
59
61
  for (const track of arg) {
60
62
  this.addTrack(track);
61
63
  }
62
64
  } else if (typeof arg === 'object' && arg.streamId && arg.streamReactTag && arg.tracks) {
63
65
  this.id = arg.streamId;
64
66
  this._reactTag = arg.streamReactTag;
67
+
65
68
  for (const trackInfo of arg.tracks) {
66
69
  // We are not using addTrack here because the track is already part of the
67
70
  // stream, so there is no need to add it on the native side.
@@ -74,18 +77,22 @@ export default class MediaStream extends defineCustomEventTarget(...MEDIA_STREAM
74
77
 
75
78
  addTrack(track: MediaStreamTrack): void {
76
79
  const index = this._tracks.indexOf(track);
80
+
77
81
  if (index !== -1) {
78
82
  return;
79
83
  }
84
+
80
85
  this._tracks.push(track);
81
86
  WebRTCModule.mediaStreamAddTrack(this._reactTag, track.id);
82
87
  }
83
88
 
84
89
  removeTrack(track: MediaStreamTrack): void {
85
90
  const index = this._tracks.indexOf(track);
91
+
86
92
  if (index === -1) {
87
93
  return;
88
94
  }
95
+
89
96
  this._tracks.splice(index, 1);
90
97
  WebRTCModule.mediaStreamRemoveTrack(this._reactTag, track.id);
91
98
  }
@@ -115,9 +122,11 @@ export default class MediaStream extends defineCustomEventTarget(...MEDIA_STREAM
115
122
  }
116
123
 
117
124
  release(releaseTracks = true): void {
118
- const tracks = [...this._tracks];
125
+ const tracks = [ ...this._tracks ];
126
+
119
127
  for (const track of tracks) {
120
128
  this.removeTrack(track);
129
+
121
130
  if (releaseTracks) {
122
131
  track.release();
123
132
  }
@@ -1,12 +1,12 @@
1
1
 
2
- import { NativeModules } from 'react-native';
3
2
  import { defineCustomEventTarget } from 'event-target-shim';
3
+ import { NativeModules } from 'react-native';
4
4
 
5
5
  import { deepClone } from './RTCUtil';
6
6
 
7
7
  const { WebRTCModule } = NativeModules;
8
8
 
9
- const MEDIA_STREAM_TRACK_EVENTS = ['ended', 'mute', 'unmute'];
9
+ const MEDIA_STREAM_TRACK_EVENTS = [ 'ended', 'mute', 'unmute' ];
10
10
 
11
11
  type MediaStreamTrackState = 'live' | 'ended';
12
12
 
@@ -19,10 +19,10 @@ class MediaStreamTrack extends defineCustomEventTarget(...MEDIA_STREAM_TRACK_EVE
19
19
 
20
20
  readonly id: string;
21
21
  readonly kind: string;
22
- readonly label: string = "";
22
+ readonly label: string = '';
23
23
  readyState: MediaStreamTrackState;
24
24
  readonly remote: boolean;
25
-
25
+
26
26
  constructor(info) {
27
27
  super();
28
28
 
@@ -37,6 +37,7 @@ class MediaStreamTrack extends defineCustomEventTarget(...MEDIA_STREAM_TRACK_EVE
37
37
  this.remote = info.remote;
38
38
 
39
39
  const _readyState = info.readyState.toLowerCase();
40
+
40
41
  this.readyState = _readyState === 'initializing' || _readyState === 'live' ? 'live' : 'ended';
41
42
  }
42
43
 
@@ -48,6 +49,7 @@ class MediaStreamTrack extends defineCustomEventTarget(...MEDIA_STREAM_TRACK_EVE
48
49
  if (enabled === this._enabled) {
49
50
  return;
50
51
  }
52
+
51
53
  WebRTCModule.mediaStreamTrackSetEnabled(this.id, !this._enabled);
52
54
  this._enabled = !this._enabled;
53
55
  }
@@ -73,12 +75,26 @@ class MediaStreamTrack extends defineCustomEventTarget(...MEDIA_STREAM_TRACK_EVE
73
75
  if (this.remote) {
74
76
  throw new Error('Not implemented for remote tracks');
75
77
  }
78
+
76
79
  if (this.kind !== 'video') {
77
80
  throw new Error('Only implemented for video tracks');
78
81
  }
82
+
79
83
  WebRTCModule.mediaStreamTrackSwitchCamera(this.id);
80
84
  }
81
85
 
86
+ _setVideoEffect(name:string) {
87
+ if (this.remote) {
88
+ throw new Error('Not implemented for remote tracks');
89
+ }
90
+
91
+ if (this.kind !== 'video') {
92
+ throw new Error('Only implemented for video tracks');
93
+ }
94
+
95
+ WebRTCModule.mediaStreamTrackSetVideoEffect(this.id, name);
96
+ }
97
+
82
98
  applyConstraints(): never {
83
99
  throw new Error('Not implemented.');
84
100
  }
@@ -98,7 +114,7 @@ class MediaStreamTrack extends defineCustomEventTarget(...MEDIA_STREAM_TRACK_EVE
98
114
  getSettings() {
99
115
  return deepClone(this._settings);
100
116
  }
101
-
117
+
102
118
  release(): void {
103
119
  WebRTCModule.mediaStreamTrackRelease(this.id);
104
120
  }
@@ -29,9 +29,9 @@ class Permissions {
29
29
  * This implementation only supports requesting these permissions, a subset
30
30
  * of: https://www.w3.org/TR/permissions/#permission-registry
31
31
  */
32
- VALID_PERMISSIONS = ['camera', 'microphone'];
32
+ VALID_PERMISSIONS = [ 'camera', 'microphone' ];
33
33
 
34
- _lastReq: Promise<any> = Promise.resolve();
34
+ _lastReq: Promise<unknown> = Promise.resolve();
35
35
 
36
36
  /**
37
37
  * Helper for requesting Android permissions. On Android only one permission
@@ -44,7 +44,7 @@ class Permissions {
44
44
  * https://facebook.github.io/react-native/docs/permissionsandroid#permissions-that-require-prompting-the-user
45
45
  */
46
46
  _requestPermissionAndroid(perm: Permission) {
47
- return new Promise((resolve, reject) => {
47
+ return new Promise(resolve => {
48
48
  PermissionsAndroid.request(perm).then(
49
49
  granted => resolve(granted === PermissionsAndroid.RESULTS.GRANTED),
50
50
  () => resolve(false)
@@ -59,12 +59,14 @@ class Permissions {
59
59
  if (typeof permissionDesc !== 'object') {
60
60
  throw new TypeError('Argument 1 of Permissions.query is not an object.');
61
61
  }
62
+
62
63
  if (typeof permissionDesc.name === 'undefined') {
63
- throw new TypeError("Missing required 'name' member of PermissionDescriptor.");
64
+ throw new TypeError('Missing required \'name\' member of PermissionDescriptor.');
64
65
  }
66
+
65
67
  if (this.VALID_PERMISSIONS.indexOf(permissionDesc.name) === -1) {
66
68
  throw new TypeError(
67
- "'name' member of PermissionDescriptor is not a valid value for enumeration PermissionName."
69
+ '\'name\' member of PermissionDescriptor is not a valid value for enumeration PermissionName.'
68
70
  );
69
71
  }
70
72
  }
@@ -79,11 +81,13 @@ class Permissions {
79
81
  } catch (e) {
80
82
  return Promise.reject(e);
81
83
  }
84
+
82
85
  if (Platform.OS === 'android') {
83
86
  const perm =
84
87
  permissionDesc.name === 'camera'
85
88
  ? PermissionsAndroid.PERMISSIONS.CAMERA
86
89
  : PermissionsAndroid.PERMISSIONS.RECORD_AUDIO;
90
+
87
91
  return new Promise(resolve => {
88
92
  PermissionsAndroid.check(perm).then(
89
93
  granted => resolve(granted ? this.RESULT.GRANTED : this.RESULT.PROMPT),
@@ -107,13 +111,16 @@ class Permissions {
107
111
  } catch (e) {
108
112
  return Promise.reject(e);
109
113
  }
114
+
110
115
  if (Platform.OS === 'android') {
111
116
  const perm =
112
117
  permissionDesc.name === 'camera'
113
118
  ? PermissionsAndroid.PERMISSIONS.CAMERA
114
119
  : PermissionsAndroid.PERMISSIONS.RECORD_AUDIO;
115
120
  const requestPermission = () => this._requestPermissionAndroid(perm);
121
+
116
122
  this._lastReq = this._lastReq.then(requestPermission, requestPermission);
123
+
117
124
  return this._lastReq;
118
125
  } else if (Platform.OS === 'ios' || Platform.OS === 'macos') {
119
126
  return WebRTCModule.requestPermission(permissionDesc.name);
@@ -1,16 +1,17 @@
1
1
 
2
- import { NativeModules } from 'react-native';
3
2
  import * as base64 from 'base64-js';
4
3
  import { defineCustomEventTarget } from 'event-target-shim';
4
+ import { EmitterSubscription, NativeModules } from 'react-native';
5
+
6
+ import EventEmitter from './EventEmitter';
5
7
  import MessageEvent from './MessageEvent';
6
8
  import RTCDataChannelEvent from './RTCDataChannelEvent';
7
- import EventEmitter from './EventEmitter';
8
9
 
9
10
  const { WebRTCModule } = NativeModules;
10
11
 
11
12
  type RTCDataChannelState = 'connecting' | 'open' | 'closing' | 'closed';
12
13
 
13
- const DATA_CHANNEL_EVENTS = ['open', 'message', 'bufferedamountlow', 'closing', 'close', 'error'];
14
+ const DATA_CHANNEL_EVENTS = [ 'open', 'message', 'bufferedamountlow', 'closing', 'close', 'error' ];
14
15
 
15
16
  export default class RTCDataChannel extends defineCustomEventTarget(...DATA_CHANNEL_EVENTS) {
16
17
  _peerConnectionId: number;
@@ -23,7 +24,7 @@ export default class RTCDataChannel extends defineCustomEventTarget(...DATA_CHAN
23
24
  _ordered: boolean;
24
25
  _protocol: string;
25
26
  _readyState: RTCDataChannelState;
26
- _subscriptions: any[] = [];
27
+ _subscriptions: EmitterSubscription[] = [];
27
28
 
28
29
  binaryType = 'arraybuffer'; // we only support 'arraybuffer'
29
30
  bufferedAmount = 0;
@@ -85,6 +86,7 @@ export default class RTCDataChannel extends defineCustomEventTarget(...DATA_CHAN
85
86
  send(data: string | ArrayBuffer | ArrayBufferView): void {
86
87
  if (typeof data === 'string') {
87
88
  WebRTCModule.dataChannelSend(this._peerConnectionId, this._reactTag, data, 'text');
89
+
88
90
  return;
89
91
  }
90
92
 
@@ -96,13 +98,17 @@ export default class RTCDataChannel extends defineCustomEventTarget(...DATA_CHAN
96
98
  } else {
97
99
  throw new TypeError('Data must be either string, ArrayBuffer, or ArrayBufferView');
98
100
  }
99
- WebRTCModule.dataChannelSend(this._peerConnectionId, this._reactTag, base64.fromByteArray(data as Uint8Array), 'binary');
101
+
102
+ const base64data = base64.fromByteArray(data as Uint8Array);
103
+
104
+ WebRTCModule.dataChannelSend(this._peerConnectionId, this._reactTag, base64data, 'binary');
100
105
  }
101
106
 
102
107
  close(): void {
103
108
  if (this._readyState === 'closing' || this._readyState === 'closed') {
104
109
  return;
105
110
  }
111
+
106
112
  WebRTCModule.dataChannelClose(this._peerConnectionId, this._reactTag);
107
113
  }
108
114
 
@@ -117,10 +123,13 @@ export default class RTCDataChannel extends defineCustomEventTarget(...DATA_CHAN
117
123
  if (ev.reactTag !== this._reactTag) {
118
124
  return;
119
125
  }
126
+
120
127
  this._readyState = ev.state;
128
+
121
129
  if (this._id === null && ev.id !== -1) {
122
130
  this._id = ev.id;
123
131
  }
132
+
124
133
  if (this._readyState === 'open') {
125
134
  // @ts-ignore
126
135
  this.dispatchEvent(new RTCDataChannelEvent('open', { channel: this }));
@@ -138,10 +147,13 @@ export default class RTCDataChannel extends defineCustomEventTarget(...DATA_CHAN
138
147
  if (ev.reactTag !== this._reactTag) {
139
148
  return;
140
149
  }
150
+
141
151
  let data = ev.data;
152
+
142
153
  if (ev.type === 'binary') {
143
154
  data = base64.toByteArray(ev.data).buffer;
144
155
  }
156
+
145
157
  // @ts-ignore
146
158
  this.dispatchEvent(new MessageEvent('message', { data }));
147
159
  })
@@ -1,4 +1,4 @@
1
- import RTCEvent from "./RTCEvent";
1
+ import RTCEvent from './RTCEvent';
2
2
 
3
3
  type RTCPeerConnectionErrorFunc =
4
4
  | 'addTransceiver'
@@ -8,14 +8,14 @@ type RTCPeerConnectionErrorFunc =
8
8
 
9
9
  /**
10
10
  * @brief This class Represents internal error happening on the native side as
11
- * part of asynchronous invocations to synchronous web APIs.
11
+ * part of asynchronous invocations to synchronous web APIs.
12
12
  */
13
13
  export default class RTCErrorEvent extends RTCEvent {
14
- readonly func: RTCPeerConnectionErrorFunc;
15
- readonly message: string;
16
- constructor(type: string, func: RTCPeerConnectionErrorFunc, message: string) {
17
- super(type);
18
- this.func = func;
19
- this.message = message;
20
- }
14
+ readonly func: RTCPeerConnectionErrorFunc;
15
+ readonly message: string;
16
+ constructor(type: string, func: RTCPeerConnectionErrorFunc, message: string) {
17
+ super(type);
18
+ this.func = func;
19
+ this.message = message;
20
+ }
21
21
  }