react-native-webrtc 1.98.0 → 1.100.0

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 (155) hide show
  1. package/android/src/main/java/com/oney/WebRTCModule/PeerConnectionObserver.java +1 -1
  2. package/android/src/main/java/com/oney/WebRTCModule/VideoTrackAdapter.java +17 -21
  3. package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +3 -1
  4. package/ios/RCTWebRTC/RCTConvert+WebRTC.m +3 -0
  5. package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +1 -1
  6. package/ios/RCTWebRTC/WebRTCModule+VideoTrackAdapter.h +1 -1
  7. package/ios/RCTWebRTC/WebRTCModule+VideoTrackAdapter.m +3 -9
  8. package/ios/RCTWebRTC/WebRTCModule.m +0 -4
  9. package/lib/commonjs/EventEmitter.js +16 -0
  10. package/lib/commonjs/EventEmitter.js.map +1 -0
  11. package/lib/commonjs/MediaDevices.js +61 -0
  12. package/lib/commonjs/MediaDevices.js.map +1 -0
  13. package/lib/commonjs/MediaStream.js +158 -0
  14. package/lib/commonjs/MediaStream.js.map +1 -0
  15. package/lib/commonjs/MediaStreamError.js +26 -0
  16. package/lib/commonjs/MediaStreamError.js.map +1 -0
  17. package/lib/commonjs/MediaStreamErrorEvent.js +23 -0
  18. package/lib/commonjs/MediaStreamErrorEvent.js.map +1 -0
  19. package/lib/commonjs/MediaStreamEvent.js +23 -0
  20. package/lib/commonjs/MediaStreamEvent.js.map +1 -0
  21. package/lib/commonjs/MediaStreamTrack.js +127 -0
  22. package/lib/commonjs/MediaStreamTrack.js.map +1 -0
  23. package/lib/commonjs/MediaStreamTrackEvent.js +23 -0
  24. package/lib/commonjs/MediaStreamTrackEvent.js.map +1 -0
  25. package/lib/commonjs/MessageEvent.js +23 -0
  26. package/lib/commonjs/MessageEvent.js.map +1 -0
  27. package/lib/commonjs/Permissions.js +125 -0
  28. package/lib/commonjs/Permissions.js.map +1 -0
  29. package/lib/commonjs/RTCDataChannel.js +198 -0
  30. package/lib/commonjs/RTCDataChannel.js.map +1 -0
  31. package/lib/commonjs/RTCDataChannelEvent.js +23 -0
  32. package/lib/commonjs/RTCDataChannelEvent.js.map +1 -0
  33. package/lib/commonjs/RTCEvent.js +20 -0
  34. package/lib/commonjs/RTCEvent.js.map +1 -0
  35. package/lib/commonjs/RTCIceCandidate.js +34 -0
  36. package/lib/commonjs/RTCIceCandidate.js.map +1 -0
  37. package/lib/commonjs/RTCIceCandidateEvent.js +25 -0
  38. package/lib/commonjs/RTCIceCandidateEvent.js.map +1 -0
  39. package/lib/commonjs/RTCPeerConnection.js +371 -0
  40. package/lib/commonjs/RTCPeerConnection.js.map +1 -0
  41. package/lib/commonjs/RTCSessionDescription.js +43 -0
  42. package/lib/commonjs/RTCSessionDescription.js.map +1 -0
  43. package/lib/commonjs/RTCUtil.js +218 -0
  44. package/lib/commonjs/RTCUtil.js.map +1 -0
  45. package/lib/commonjs/RTCView.js +68 -0
  46. package/lib/commonjs/RTCView.js.map +1 -0
  47. package/lib/commonjs/ScreenCapturePickerView.js +13 -0
  48. package/lib/commonjs/ScreenCapturePickerView.js.map +1 -0
  49. package/lib/commonjs/getDisplayMedia.js +39 -0
  50. package/lib/commonjs/getDisplayMedia.js.map +1 -0
  51. package/lib/commonjs/getUserMedia.js +122 -0
  52. package/lib/commonjs/getUserMedia.js.map +1 -0
  53. package/lib/commonjs/index.js +101 -0
  54. package/lib/commonjs/index.js.map +1 -0
  55. package/lib/commonjs/typings.d.js +2 -0
  56. package/lib/commonjs/typings.d.js.map +1 -0
  57. package/lib/module/EventEmitter.js +7 -0
  58. package/lib/module/EventEmitter.js.map +1 -0
  59. package/lib/module/MediaDevices.js +46 -0
  60. package/lib/module/MediaDevices.js.map +1 -0
  61. package/lib/module/MediaStream.js +142 -0
  62. package/lib/module/MediaStream.js.map +1 -0
  63. package/lib/module/MediaStreamError.js +17 -0
  64. package/lib/module/MediaStreamError.js.map +1 -0
  65. package/lib/module/MediaStreamErrorEvent.js +14 -0
  66. package/lib/module/MediaStreamErrorEvent.js.map +1 -0
  67. package/lib/module/MediaStreamEvent.js +14 -0
  68. package/lib/module/MediaStreamEvent.js.map +1 -0
  69. package/lib/module/MediaStreamTrack.js +116 -0
  70. package/lib/module/MediaStreamTrack.js.map +1 -0
  71. package/lib/module/MediaStreamTrackEvent.js +14 -0
  72. package/lib/module/MediaStreamTrackEvent.js.map +1 -0
  73. package/lib/module/MessageEvent.js +14 -0
  74. package/lib/module/MessageEvent.js.map +1 -0
  75. package/lib/module/Permissions.js +115 -0
  76. package/lib/module/Permissions.js.map +1 -0
  77. package/lib/module/RTCDataChannel.js +176 -0
  78. package/lib/module/RTCDataChannel.js.map +1 -0
  79. package/lib/module/RTCDataChannelEvent.js +14 -0
  80. package/lib/module/RTCDataChannelEvent.js.map +1 -0
  81. package/lib/module/RTCEvent.js +11 -0
  82. package/lib/module/RTCEvent.js.map +1 -0
  83. package/lib/module/RTCIceCandidate.js +25 -0
  84. package/lib/module/RTCIceCandidate.js.map +1 -0
  85. package/lib/module/RTCIceCandidateEvent.js +16 -0
  86. package/lib/module/RTCIceCandidateEvent.js.map +1 -0
  87. package/lib/module/RTCPeerConnection.js +342 -0
  88. package/lib/module/RTCPeerConnection.js.map +1 -0
  89. package/lib/module/RTCSessionDescription.js +34 -0
  90. package/lib/module/RTCSessionDescription.js.map +1 -0
  91. package/lib/module/RTCUtil.js +207 -0
  92. package/lib/module/RTCUtil.js.map +1 -0
  93. package/lib/module/RTCView.js +59 -0
  94. package/lib/module/RTCView.js.map +1 -0
  95. package/lib/module/ScreenCapturePickerView.js +3 -0
  96. package/lib/module/ScreenCapturePickerView.js.map +1 -0
  97. package/lib/module/getDisplayMedia.js +26 -0
  98. package/lib/module/getDisplayMedia.js.map +1 -0
  99. package/lib/module/getUserMedia.js +103 -0
  100. package/lib/module/getUserMedia.js.map +1 -0
  101. package/lib/module/index.js +31 -0
  102. package/lib/module/index.js.map +1 -0
  103. package/lib/module/typings.d.js +2 -0
  104. package/lib/module/typings.d.js.map +1 -0
  105. package/lib/typescript/EventEmitter.d.ts +3 -0
  106. package/lib/typescript/MediaDevices.d.ts +27 -0
  107. package/lib/typescript/MediaStream.d.ts +39 -0
  108. package/lib/typescript/MediaStreamError.d.ts +6 -0
  109. package/lib/typescript/MediaStreamErrorEvent.d.ts +6 -0
  110. package/lib/typescript/MediaStreamEvent.d.ts +8 -0
  111. package/lib/typescript/MediaStreamTrack.d.ts +34 -0
  112. package/lib/typescript/MediaStreamTrackEvent.d.ts +8 -0
  113. package/lib/typescript/MessageEvent.d.ts +9 -0
  114. package/lib/typescript/Permissions.d.ts +55 -0
  115. package/lib/typescript/RTCDataChannel.d.ts +33 -0
  116. package/lib/typescript/RTCDataChannelEvent.d.ts +8 -0
  117. package/lib/typescript/RTCEvent.d.ts +4 -0
  118. package/lib/typescript/RTCIceCandidate.d.ts +11 -0
  119. package/lib/typescript/RTCIceCandidateEvent.d.ts +6 -0
  120. package/lib/typescript/RTCPeerConnection.d.ts +58 -0
  121. package/lib/typescript/RTCSessionDescription.d.ts +14 -0
  122. package/lib/typescript/RTCUtil.d.ts +28 -0
  123. package/lib/typescript/RTCView.d.ts +53 -0
  124. package/lib/typescript/ScreenCapturePickerView.d.ts +2 -0
  125. package/lib/typescript/getDisplayMedia.d.ts +1 -0
  126. package/lib/typescript/getUserMedia.d.ts +6 -0
  127. package/lib/typescript/index.d.ts +11 -0
  128. package/package.json +24 -8
  129. package/src/{EventEmitter.js → EventEmitter.ts} +0 -0
  130. package/src/{MediaDevices.js → MediaDevices.ts} +2 -3
  131. package/src/{MediaStream.js → MediaStream.ts} +1 -1
  132. package/src/{MediaStreamError.js → MediaStreamError.ts} +2 -2
  133. package/src/{MediaStreamErrorEvent.js → MediaStreamErrorEvent.ts} +1 -1
  134. package/src/{MediaStreamEvent.js → MediaStreamEvent.ts} +2 -2
  135. package/src/{MediaStreamTrack.js → MediaStreamTrack.ts} +9 -7
  136. package/src/{MediaStreamTrackEvent.js → MediaStreamTrackEvent.ts} +2 -2
  137. package/src/MessageEvent.ts +11 -0
  138. package/src/{Permissions.js → Permissions.ts} +6 -6
  139. package/src/{RTCDataChannel.js → RTCDataChannel.ts} +12 -8
  140. package/src/{RTCDataChannelEvent.js → RTCDataChannelEvent.ts} +2 -2
  141. package/src/{RTCEvent.js → RTCEvent.ts} +1 -2
  142. package/src/{RTCIceCandidate.js → RTCIceCandidate.ts} +0 -0
  143. package/src/{RTCIceCandidateEvent.js → RTCIceCandidateEvent.ts} +2 -6
  144. package/src/{RTCPeerConnection.js → RTCPeerConnection.ts} +28 -19
  145. package/src/{RTCSessionDescription.js → RTCSessionDescription.ts} +6 -3
  146. package/src/{RTCUtil.js → RTCUtil.ts} +5 -1
  147. package/src/{RTCView.js → RTCView.ts} +0 -0
  148. package/src/{ScreenCapturePickerView.js → ScreenCapturePickerView.ts} +0 -0
  149. package/src/{getDisplayMedia.js → getDisplayMedia.ts} +0 -0
  150. package/src/{getUserMedia.js → getUserMedia.ts} +7 -2
  151. package/src/{index.js → index.ts} +6 -7
  152. package/src/typings.d.ts +1 -0
  153. package/tools/build-webrtc.py +17 -15
  154. package/tsconfig.json +14 -0
  155. package/src/MessageEvent.js +0 -10
@@ -0,0 +1,176 @@
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
+ import { NativeModules } from 'react-native';
4
+ import * as base64 from 'base64-js';
5
+ import { defineCustomEventTarget } from 'event-target-shim';
6
+ import MessageEvent from './MessageEvent';
7
+ import RTCDataChannelEvent from './RTCDataChannelEvent';
8
+ import EventEmitter from './EventEmitter';
9
+ const {
10
+ WebRTCModule
11
+ } = NativeModules;
12
+ const DATA_CHANNEL_EVENTS = ['open', 'message', 'bufferedamountlow', 'closing', 'close', 'error'];
13
+ export default class RTCDataChannel extends defineCustomEventTarget(...DATA_CHANNEL_EVENTS) {
14
+ // we only support 'arraybuffer'
15
+ constructor(info) {
16
+ super();
17
+
18
+ _defineProperty(this, "_peerConnectionId", void 0);
19
+
20
+ _defineProperty(this, "_reactTag", void 0);
21
+
22
+ _defineProperty(this, "_id", void 0);
23
+
24
+ _defineProperty(this, "_label", void 0);
25
+
26
+ _defineProperty(this, "_maxPacketLifeTime", void 0);
27
+
28
+ _defineProperty(this, "_maxRetransmits", void 0);
29
+
30
+ _defineProperty(this, "_negotiated", void 0);
31
+
32
+ _defineProperty(this, "_ordered", void 0);
33
+
34
+ _defineProperty(this, "_protocol", void 0);
35
+
36
+ _defineProperty(this, "_readyState", void 0);
37
+
38
+ _defineProperty(this, "_subscriptions", []);
39
+
40
+ _defineProperty(this, "binaryType", 'arraybuffer');
41
+
42
+ _defineProperty(this, "bufferedAmount", 0);
43
+
44
+ _defineProperty(this, "bufferedAmountLowThreshold", 0);
45
+
46
+ this._peerConnectionId = info.peerConnectionId;
47
+ this._reactTag = info.reactTag;
48
+ this._label = info.label;
49
+ this._id = info.id === -1 ? null : info.id; // null until negotiated.
50
+
51
+ this._ordered = Boolean(info.ordered);
52
+ this._maxPacketLifeTime = info.maxPacketLifeTime;
53
+ this._maxRetransmits = info.maxRetransmits;
54
+ this._protocol = info.protocol || '';
55
+ this._negotiated = Boolean(info.negotiated);
56
+ this._readyState = info.readyState;
57
+
58
+ this._registerEvents();
59
+ }
60
+
61
+ get label() {
62
+ return this._label;
63
+ }
64
+
65
+ get id() {
66
+ return this._id;
67
+ }
68
+
69
+ get ordered() {
70
+ return this._ordered;
71
+ }
72
+
73
+ get maxPacketLifeTime() {
74
+ return this._maxPacketLifeTime;
75
+ }
76
+
77
+ get maxRetransmits() {
78
+ return this._maxRetransmits;
79
+ }
80
+
81
+ get protocol() {
82
+ return this._protocol;
83
+ }
84
+
85
+ get negotiated() {
86
+ return this._negotiated;
87
+ }
88
+
89
+ get readyState() {
90
+ return this._readyState;
91
+ }
92
+
93
+ send(data) {
94
+ if (typeof data === 'string') {
95
+ WebRTCModule.dataChannelSend(this._peerConnectionId, this._reactTag, data, 'text');
96
+ return;
97
+ } // Safely convert the buffer object to an Uint8Array for base64-encoding
98
+
99
+
100
+ if (ArrayBuffer.isView(data)) {
101
+ data = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
102
+ } else if (data instanceof ArrayBuffer) {
103
+ data = new Uint8Array(data);
104
+ } else {
105
+ throw new TypeError('Data must be either string, ArrayBuffer, or ArrayBufferView');
106
+ }
107
+
108
+ WebRTCModule.dataChannelSend(this._peerConnectionId, this._reactTag, base64.fromByteArray(data), 'binary');
109
+ }
110
+
111
+ close() {
112
+ if (this._readyState === 'closing' || this._readyState === 'closed') {
113
+ return;
114
+ }
115
+
116
+ WebRTCModule.dataChannelClose(this._peerConnectionId, this._reactTag);
117
+ }
118
+
119
+ _unregisterEvents() {
120
+ this._subscriptions.forEach(e => e.remove());
121
+
122
+ this._subscriptions = [];
123
+ }
124
+
125
+ _registerEvents() {
126
+ this._subscriptions = [EventEmitter.addListener('dataChannelStateChanged', ev => {
127
+ if (ev.reactTag !== this._reactTag) {
128
+ return;
129
+ }
130
+
131
+ this._readyState = ev.state;
132
+
133
+ if (this._id === null && ev.id !== -1) {
134
+ this._id = ev.id;
135
+ }
136
+
137
+ if (this._readyState === 'open') {
138
+ // @ts-ignore
139
+ this.dispatchEvent(new RTCDataChannelEvent('open', {
140
+ channel: this
141
+ }));
142
+ } else if (this._readyState === 'closing') {
143
+ // @ts-ignore
144
+ this.dispatchEvent(new RTCDataChannelEvent('closing', {
145
+ channel: this
146
+ }));
147
+ } else if (this._readyState === 'closed') {
148
+ // @ts-ignore
149
+ this.dispatchEvent(new RTCDataChannelEvent('close', {
150
+ channel: this
151
+ }));
152
+
153
+ this._unregisterEvents();
154
+
155
+ WebRTCModule.dataChannelDispose(this._peerConnectionId, this._reactTag);
156
+ }
157
+ }), EventEmitter.addListener('dataChannelReceiveMessage', ev => {
158
+ if (ev.reactTag !== this._reactTag) {
159
+ return;
160
+ }
161
+
162
+ let data = ev.data;
163
+
164
+ if (ev.type === 'binary') {
165
+ data = base64.toByteArray(ev.data).buffer;
166
+ } // @ts-ignore
167
+
168
+
169
+ this.dispatchEvent(new MessageEvent('message', {
170
+ data
171
+ }));
172
+ })];
173
+ }
174
+
175
+ }
176
+ //# sourceMappingURL=RTCDataChannel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["RTCDataChannel.ts"],"names":["NativeModules","base64","defineCustomEventTarget","MessageEvent","RTCDataChannelEvent","EventEmitter","WebRTCModule","DATA_CHANNEL_EVENTS","RTCDataChannel","constructor","info","_peerConnectionId","peerConnectionId","_reactTag","reactTag","_label","label","_id","id","_ordered","Boolean","ordered","_maxPacketLifeTime","maxPacketLifeTime","_maxRetransmits","maxRetransmits","_protocol","protocol","_negotiated","negotiated","_readyState","readyState","_registerEvents","send","data","dataChannelSend","ArrayBuffer","isView","Uint8Array","buffer","byteOffset","byteLength","TypeError","fromByteArray","close","dataChannelClose","_unregisterEvents","_subscriptions","forEach","e","remove","addListener","ev","state","dispatchEvent","channel","dataChannelDispose","type","toByteArray"],"mappings":";;AACA,SAASA,aAAT,QAA8B,cAA9B;AACA,OAAO,KAAKC,MAAZ,MAAwB,WAAxB;AACA,SAASC,uBAAT,QAAwC,mBAAxC;AACA,OAAOC,YAAP,MAAyB,gBAAzB;AACA,OAAOC,mBAAP,MAAgC,uBAAhC;AACA,OAAOC,YAAP,MAAyB,gBAAzB;AAEA,MAAM;AAAEC,EAAAA;AAAF,IAAmBN,aAAzB;AAIA,MAAMO,mBAAmB,GAAG,CAAC,MAAD,EAAS,SAAT,EAAoB,mBAApB,EAAyC,SAAzC,EAAoD,OAApD,EAA6D,OAA7D,CAA5B;AAEA,eAAe,MAAMC,cAAN,SAA6BN,uBAAuB,CAAC,GAAGK,mBAAJ,CAApD,CAA6E;AAapD;AAIpCE,EAAAA,WAAW,CAACC,IAAD,EAAO;AACd;;AADc;;AAAA;;AAAA;;AAAA;;AAAA;;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QxD;;;AACA,WAAKe,aAAL,CAAmB,IAAInD,YAAJ,CAAiB,SAAjB,EAA4B;AAAE+B,QAAAA;AAAF,OAA5B,CAAnB;AACH,KAVD,CAtBkB,CAAtB;AAkCH;;AAnIuF","sourcesContent":["\nimport { NativeModules } from 'react-native';\nimport * as base64 from 'base64-js';\nimport { defineCustomEventTarget } from 'event-target-shim';\nimport MessageEvent from './MessageEvent';\nimport RTCDataChannelEvent from './RTCDataChannelEvent';\nimport EventEmitter from './EventEmitter';\n\nconst { WebRTCModule } = NativeModules;\n\ntype RTCDataChannelState = 'connecting' | 'open' | 'closing' | 'closed';\n\nconst DATA_CHANNEL_EVENTS = ['open', 'message', 'bufferedamountlow', 'closing', 'close', 'error'];\n\nexport default class RTCDataChannel extends defineCustomEventTarget(...DATA_CHANNEL_EVENTS) {\n _peerConnectionId: number;\n _reactTag: string;\n _id: number;\n _label: string;\n _maxPacketLifeTime?: number;\n _maxRetransmits?: number;\n _negotiated: boolean;\n _ordered: boolean;\n _protocol: string;\n _readyState: RTCDataChannelState;\n _subscriptions: Array<any> = [];\n\n binaryType: string = 'arraybuffer'; // we only support 'arraybuffer'\n bufferedAmount: number = 0;\n bufferedAmountLowThreshold: number = 0;\n\n constructor(info) {\n super();\n\n this._peerConnectionId = info.peerConnectionId;\n this._reactTag = info.reactTag;\n\n this._label = info.label;\n this._id = info.id === -1 ? null : info.id; // null until negotiated.\n this._ordered = Boolean(info.ordered);\n this._maxPacketLifeTime = info.maxPacketLifeTime;\n this._maxRetransmits = info.maxRetransmits;\n this._protocol = info.protocol || '';\n this._negotiated = Boolean(info.negotiated);\n this._readyState = info.readyState;\n\n this._registerEvents();\n }\n\n get label(): string {\n return this._label;\n }\n\n get id(): number {\n return this._id;\n }\n\n get ordered(): boolean {\n return this._ordered;\n }\n\n get maxPacketLifeTime(): number | undefined {\n return this._maxPacketLifeTime;\n }\n\n get maxRetransmits(): number | undefined {\n return this._maxRetransmits;\n }\n\n get protocol(): string {\n return this._protocol;\n }\n\n get negotiated(): boolean {\n return this._negotiated;\n }\n\n get readyState(): string {\n return this._readyState;\n }\n\n send(data: string | ArrayBuffer | ArrayBufferView) {\n if (typeof data === 'string') {\n WebRTCModule.dataChannelSend(this._peerConnectionId, this._reactTag, data, 'text');\n return;\n }\n\n // Safely convert the buffer object to an Uint8Array for base64-encoding\n if (ArrayBuffer.isView(data)) {\n data = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);\n } else if (data instanceof ArrayBuffer) {\n data = new Uint8Array(data);\n } else {\n throw new TypeError('Data must be either string, ArrayBuffer, or ArrayBufferView');\n }\n WebRTCModule.dataChannelSend(this._peerConnectionId, this._reactTag, base64.fromByteArray(data as Uint8Array), 'binary');\n }\n\n close() {\n if (this._readyState === 'closing' || this._readyState === 'closed') {\n return;\n }\n WebRTCModule.dataChannelClose(this._peerConnectionId, this._reactTag);\n }\n\n _unregisterEvents() {\n this._subscriptions.forEach(e => e.remove());\n this._subscriptions = [];\n }\n\n _registerEvents() {\n this._subscriptions = [\n EventEmitter.addListener('dataChannelStateChanged', ev => {\n if (ev.reactTag !== this._reactTag) {\n return;\n }\n this._readyState = ev.state;\n if (this._id === null && ev.id !== -1) {\n this._id = ev.id;\n }\n if (this._readyState === 'open') {\n // @ts-ignore\n this.dispatchEvent(new RTCDataChannelEvent('open', { channel: this }));\n } else if (this._readyState === 'closing') {\n // @ts-ignore\n this.dispatchEvent(new RTCDataChannelEvent('closing', { channel: this }));\n } else if (this._readyState === 'closed') {\n // @ts-ignore\n this.dispatchEvent(new RTCDataChannelEvent('close', { channel: this }));\n this._unregisterEvents();\n WebRTCModule.dataChannelDispose(this._peerConnectionId, this._reactTag);\n }\n }),\n EventEmitter.addListener('dataChannelReceiveMessage', ev => {\n if (ev.reactTag !== this._reactTag) {\n return;\n }\n let data = ev.data;\n if (ev.type === 'binary') {\n data = base64.toByteArray(ev.data).buffer;\n }\n // @ts-ignore\n this.dispatchEvent(new MessageEvent('message', { data }));\n })\n ];\n }\n}\n"]}
@@ -0,0 +1,14 @@
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
+ export default class RTCDataChannelEvent {
4
+ constructor(type, eventInitDict) {
5
+ _defineProperty(this, "type", void 0);
6
+
7
+ _defineProperty(this, "channel", void 0);
8
+
9
+ this.type = type.toString();
10
+ this.channel = eventInitDict.channel;
11
+ }
12
+
13
+ }
14
+ //# sourceMappingURL=RTCDataChannelEvent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["RTCDataChannelEvent.ts"],"names":["RTCDataChannelEvent","constructor","type","eventInitDict","toString","channel"],"mappings":";;AAGA,eAAe,MAAMA,mBAAN,CAA0B;AAGrCC,EAAAA,WAAW,CAACC,IAAD,EAAOC,aAAP,EAAmD;AAAA;;AAAA;;AAC1D,SAAKD,IAAL,GAAYA,IAAI,CAACE,QAAL,EAAZ;AACA,SAAKC,OAAL,GAAeF,aAAa,CAACE,OAA7B;AACH;;AANoC","sourcesContent":["\nimport type RTCDataChannel from './RTCDataChannel';\n\nexport default class RTCDataChannelEvent {\n type: string;\n channel: RTCDataChannel;\n constructor(type, eventInitDict: { channel: RTCDataChannel }) {\n this.type = type.toString();\n this.channel = eventInitDict.channel;\n }\n}\n"]}
@@ -0,0 +1,11 @@
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
+ export default class RTCEvent {
4
+ constructor(type) {
5
+ _defineProperty(this, "type", void 0);
6
+
7
+ this.type = type.toString();
8
+ }
9
+
10
+ }
11
+ //# sourceMappingURL=RTCEvent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["RTCEvent.ts"],"names":["RTCEvent","constructor","type","toString"],"mappings":";;AACA,eAAe,MAAMA,QAAN,CAAe;AAE1BC,EAAAA,WAAW,CAACC,IAAD,EAAO;AAAA;;AACd,SAAKA,IAAL,GAAYA,IAAI,CAACC,QAAL,EAAZ;AACH;;AAJyB","sourcesContent":["\nexport default class RTCEvent {\n type: string;\n constructor(type) {\n this.type = type.toString();\n }\n}\n"]}
@@ -0,0 +1,25 @@
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
+ export default class RTCIceCandidate {
4
+ constructor(info) {
5
+ _defineProperty(this, "candidate", void 0);
6
+
7
+ _defineProperty(this, "sdpMLineIndex", void 0);
8
+
9
+ _defineProperty(this, "sdpMid", void 0);
10
+
11
+ this.candidate = info.candidate;
12
+ this.sdpMLineIndex = info.sdpMLineIndex;
13
+ this.sdpMid = info.sdpMid;
14
+ }
15
+
16
+ toJSON() {
17
+ return {
18
+ candidate: this.candidate,
19
+ sdpMLineIndex: this.sdpMLineIndex,
20
+ sdpMid: this.sdpMid
21
+ };
22
+ }
23
+
24
+ }
25
+ //# sourceMappingURL=RTCIceCandidate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["RTCIceCandidate.ts"],"names":["RTCIceCandidate","constructor","info","candidate","sdpMLineIndex","sdpMid","toJSON"],"mappings":";;AACA,eAAe,MAAMA,eAAN,CAAsB;AAKjCC,EAAAA,WAAW,CAACC,IAAD,EAAO;AAAA;;AAAA;;AAAA;;AACd,SAAKC,SAAL,GAAiBD,IAAI,CAACC,SAAtB;AACA,SAAKC,aAAL,GAAqBF,IAAI,CAACE,aAA1B;AACA,SAAKC,MAAL,GAAcH,IAAI,CAACG,MAAnB;AACH;;AAEDC,EAAAA,MAAM,GAAG;AACL,WAAO;AACHH,MAAAA,SAAS,EAAE,KAAKA,SADb;AAEHC,MAAAA,aAAa,EAAE,KAAKA,aAFjB;AAGHC,MAAAA,MAAM,EAAE,KAAKA;AAHV,KAAP;AAKH;;AAjBgC","sourcesContent":["\nexport default class RTCIceCandidate {\n candidate: string;\n sdpMLineIndex: number;\n sdpMid: string;\n\n constructor(info) {\n this.candidate = info.candidate;\n this.sdpMLineIndex = info.sdpMLineIndex;\n this.sdpMid = info.sdpMid;\n }\n\n toJSON() {\n return {\n candidate: this.candidate,\n sdpMLineIndex: this.sdpMLineIndex,\n sdpMid: this.sdpMid\n };\n }\n}\n"]}
@@ -0,0 +1,16 @@
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
+ export default class RTCIceCandidateEvent {
4
+ constructor(type, eventInitDict) {
5
+ var _eventInitDict$candid;
6
+
7
+ _defineProperty(this, "type", void 0);
8
+
9
+ _defineProperty(this, "candidate", void 0);
10
+
11
+ this.type = type.toString();
12
+ this.candidate = (_eventInitDict$candid = eventInitDict === null || eventInitDict === void 0 ? void 0 : eventInitDict.candidate) !== null && _eventInitDict$candid !== void 0 ? _eventInitDict$candid : null;
13
+ }
14
+
15
+ }
16
+ //# sourceMappingURL=RTCIceCandidateEvent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["RTCIceCandidateEvent.ts"],"names":["RTCIceCandidateEvent","constructor","type","eventInitDict","toString","candidate"],"mappings":";;AAGA,eAAe,MAAMA,oBAAN,CAA2B;AAGtCC,EAAAA,WAAW,CAACC,IAAD,EAAOC,aAAP,EAAsB;AAAA;;AAAA;;AAAA;;AAC7B,SAAKD,IAAL,GAAYA,IAAI,CAACE,QAAL,EAAZ;AACA,SAAKC,SAAL,4BAAiBF,aAAjB,aAAiBA,aAAjB,uBAAiBA,aAAa,CAAEE,SAAhC,yEAA6C,IAA7C;AACH;;AANqC","sourcesContent":["\nimport type RTCIceCandidate from './RTCIceCandidate';\n\nexport default class RTCIceCandidateEvent {\n type: string;\n candidate: RTCIceCandidate | null;\n constructor(type, eventInitDict) {\n this.type = type.toString();\n this.candidate = eventInitDict?.candidate ?? null;\n }\n}\n"]}
@@ -0,0 +1,342 @@
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
+ import { defineCustomEventTarget } from 'event-target-shim';
4
+ import { NativeModules } from 'react-native';
5
+ import MediaStream from './MediaStream';
6
+ import MediaStreamEvent from './MediaStreamEvent';
7
+ import MediaStreamTrackEvent from './MediaStreamTrackEvent';
8
+ import RTCDataChannel from './RTCDataChannel';
9
+ import RTCDataChannelEvent from './RTCDataChannelEvent';
10
+ import RTCSessionDescription from './RTCSessionDescription';
11
+ import RTCIceCandidate from './RTCIceCandidate';
12
+ import RTCIceCandidateEvent from './RTCIceCandidateEvent';
13
+ import RTCEvent from './RTCEvent';
14
+ import * as RTCUtil from './RTCUtil';
15
+ import EventEmitter from './EventEmitter';
16
+ const {
17
+ WebRTCModule
18
+ } = NativeModules;
19
+ const PEER_CONNECTION_EVENTS = ['connectionstatechange', 'icecandidate', 'icecandidateerror', 'iceconnectionstatechange', 'icegatheringstatechange', 'negotiationneeded', 'signalingstatechange', 'datachannel', 'addstream', 'removestream'];
20
+ let nextPeerConnectionId = 0;
21
+ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_CONNECTION_EVENTS) {
22
+ constructor(configuration) {
23
+ super();
24
+
25
+ _defineProperty(this, "localDescription", null);
26
+
27
+ _defineProperty(this, "remoteDescription", null);
28
+
29
+ _defineProperty(this, "signalingState", 'stable');
30
+
31
+ _defineProperty(this, "iceGatheringState", 'new');
32
+
33
+ _defineProperty(this, "connectionState", 'new');
34
+
35
+ _defineProperty(this, "iceConnectionState", 'new');
36
+
37
+ _defineProperty(this, "_peerConnectionId", void 0);
38
+
39
+ _defineProperty(this, "_localStreams", []);
40
+
41
+ _defineProperty(this, "_remoteStreams", []);
42
+
43
+ _defineProperty(this, "_subscriptions", []);
44
+
45
+ this._peerConnectionId = nextPeerConnectionId++;
46
+ WebRTCModule.peerConnectionInit(configuration, this._peerConnectionId);
47
+
48
+ this._registerEvents();
49
+ }
50
+
51
+ addStream(stream) {
52
+ const index = this._localStreams.indexOf(stream);
53
+
54
+ if (index !== -1) {
55
+ return;
56
+ }
57
+
58
+ WebRTCModule.peerConnectionAddStream(stream._reactTag, this._peerConnectionId);
59
+
60
+ this._localStreams.push(stream);
61
+ }
62
+
63
+ removeStream(stream) {
64
+ const index = this._localStreams.indexOf(stream);
65
+
66
+ if (index === -1) {
67
+ return;
68
+ }
69
+
70
+ this._localStreams.splice(index, 1);
71
+
72
+ WebRTCModule.peerConnectionRemoveStream(stream._reactTag, this._peerConnectionId);
73
+ }
74
+
75
+ createOffer(options) {
76
+ return new Promise((resolve, reject) => {
77
+ WebRTCModule.peerConnectionCreateOffer(this._peerConnectionId, RTCUtil.normalizeOfferAnswerOptions(options), (successful, data) => {
78
+ if (successful) {
79
+ resolve(data);
80
+ } else {
81
+ reject(data); // TODO: convert to NavigatorUserMediaError
82
+ }
83
+ });
84
+ });
85
+ }
86
+
87
+ createAnswer() {
88
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
89
+ return new Promise((resolve, reject) => {
90
+ WebRTCModule.peerConnectionCreateAnswer(this._peerConnectionId, RTCUtil.normalizeOfferAnswerOptions(options), (successful, data) => {
91
+ if (successful) {
92
+ resolve(data);
93
+ } else {
94
+ reject(data);
95
+ }
96
+ });
97
+ });
98
+ }
99
+
100
+ setConfiguration(configuration) {
101
+ WebRTCModule.peerConnectionSetConfiguration(configuration, this._peerConnectionId);
102
+ }
103
+
104
+ async setLocalDescription(sessionDescription) {
105
+ const desc = sessionDescription ? sessionDescription.toJSON ? sessionDescription.toJSON() : sessionDescription : null;
106
+ const newSdp = await WebRTCModule.peerConnectionSetLocalDescription(this._peerConnectionId, desc);
107
+ this.localDescription = new RTCSessionDescription(newSdp);
108
+ }
109
+
110
+ setRemoteDescription(sessionDescription) {
111
+ return new Promise((resolve, reject) => {
112
+ WebRTCModule.peerConnectionSetRemoteDescription(sessionDescription.toJSON ? sessionDescription.toJSON() : sessionDescription, this._peerConnectionId, (successful, data) => {
113
+ if (successful) {
114
+ this.remoteDescription = new RTCSessionDescription(data);
115
+ resolve();
116
+ } else {
117
+ reject(data);
118
+ }
119
+ });
120
+ });
121
+ }
122
+
123
+ async addIceCandidate(candidate) {
124
+ if (!candidate || !candidate.candidate) {
125
+ // XXX end-of cantidates is not implemented: https://bugs.chromium.org/p/webrtc/issues/detail?id=9218
126
+ return;
127
+ }
128
+
129
+ const newSdp = await WebRTCModule.peerConnectionAddICECandidate(this._peerConnectionId, candidate.toJSON ? candidate.toJSON() : candidate);
130
+ this.remoteDescription = new RTCSessionDescription(newSdp);
131
+ }
132
+
133
+ getStats() {
134
+ return WebRTCModule.peerConnectionGetStats(this._peerConnectionId).then(data => {
135
+ /* On both Android and iOS it is faster to construct a single
136
+ JSON string representing the Map of StatsReports and have it
137
+ pass through the React Native bridge rather than the Map of
138
+ StatsReports. While the implementations do try to be faster in
139
+ general, the stress is on being faster to pass through the React
140
+ Native bridge which is a bottleneck that tends to be visible in
141
+ the UI when there is congestion involving UI-related passing.
142
+ TODO Implement the logic for filtering the stats based on
143
+ the sender/receiver
144
+ */
145
+ return new Map(JSON.parse(data));
146
+ });
147
+ }
148
+
149
+ getLocalStreams() {
150
+ return this._localStreams.slice();
151
+ }
152
+
153
+ getRemoteStreams() {
154
+ return this._remoteStreams.slice();
155
+ }
156
+
157
+ close() {
158
+ WebRTCModule.peerConnectionClose(this._peerConnectionId);
159
+ }
160
+
161
+ restartIce() {
162
+ WebRTCModule.peerConnectionRestartIce(this._peerConnectionId);
163
+ }
164
+
165
+ _unregisterEvents() {
166
+ this._subscriptions.forEach(e => e.remove());
167
+
168
+ this._subscriptions = [];
169
+ }
170
+
171
+ _registerEvents() {
172
+ this._subscriptions = [EventEmitter.addListener('peerConnectionOnRenegotiationNeeded', ev => {
173
+ if (ev.id !== this._peerConnectionId) {
174
+ return;
175
+ } // @ts-ignore
176
+
177
+
178
+ this.dispatchEvent(new RTCEvent('negotiationneeded'));
179
+ }), EventEmitter.addListener('peerConnectionIceConnectionChanged', ev => {
180
+ if (ev.id !== this._peerConnectionId) {
181
+ return;
182
+ }
183
+
184
+ this.iceConnectionState = ev.iceConnectionState; // @ts-ignore
185
+
186
+ this.dispatchEvent(new RTCEvent('iceconnectionstatechange'));
187
+
188
+ if (ev.iceConnectionState === 'closed') {
189
+ // This PeerConnection is done, clean up event handlers.
190
+ this._unregisterEvents();
191
+ }
192
+ }), EventEmitter.addListener('peerConnectionStateChanged', ev => {
193
+ if (ev.id !== this._peerConnectionId) {
194
+ return;
195
+ }
196
+
197
+ this.connectionState = ev.connectionState; // @ts-ignore
198
+
199
+ this.dispatchEvent(new RTCEvent('connectionstatechange'));
200
+
201
+ if (ev.connectionState === 'closed') {
202
+ // This PeerConnection is done, clean up event handlers.
203
+ this._unregisterEvents();
204
+ }
205
+ }), EventEmitter.addListener('peerConnectionSignalingStateChanged', ev => {
206
+ if (ev.id !== this._peerConnectionId) {
207
+ return;
208
+ }
209
+
210
+ this.signalingState = ev.signalingState; // @ts-ignore
211
+
212
+ this.dispatchEvent(new RTCEvent('signalingstatechange'));
213
+ }), EventEmitter.addListener('peerConnectionAddedStream', ev => {
214
+ if (ev.id !== this._peerConnectionId) {
215
+ return;
216
+ }
217
+
218
+ const stream = new MediaStream(ev);
219
+
220
+ this._remoteStreams.push(stream);
221
+
222
+ this.remoteDescription = new RTCSessionDescription(ev.sdp); // @ts-ignore
223
+
224
+ this.dispatchEvent(new MediaStreamEvent('addstream', {
225
+ stream
226
+ }));
227
+ }), EventEmitter.addListener('peerConnectionRemovedStream', ev => {
228
+ if (ev.id !== this._peerConnectionId) {
229
+ return;
230
+ }
231
+
232
+ const stream = this._remoteStreams.find(s => s._reactTag === ev.streamId);
233
+
234
+ if (stream) {
235
+ const index = this._remoteStreams.indexOf(stream);
236
+
237
+ if (index !== -1) {
238
+ this._remoteStreams.splice(index, 1);
239
+ }
240
+ }
241
+
242
+ this.remoteDescription = new RTCSessionDescription(ev.sdp); // @ts-ignore
243
+
244
+ this.dispatchEvent(new MediaStreamEvent('removestream', {
245
+ stream
246
+ }));
247
+ }), EventEmitter.addListener('mediaStreamTrackMuteChanged', ev => {
248
+ if (ev.peerConnectionId !== this._peerConnectionId) {
249
+ return;
250
+ }
251
+
252
+ let track;
253
+
254
+ for (const stream of this._remoteStreams) {
255
+ const t = stream._tracks.find(track => track.id === ev.trackId);
256
+
257
+ if (t) {
258
+ track = t;
259
+ break;
260
+ }
261
+ }
262
+
263
+ if (track) {
264
+ track._muted = ev.muted;
265
+ const eventName = ev.muted ? 'mute' : 'unmute';
266
+ track.dispatchEvent(new MediaStreamTrackEvent(eventName, {
267
+ track
268
+ }));
269
+ }
270
+ }), EventEmitter.addListener('peerConnectionGotICECandidate', ev => {
271
+ if (ev.id !== this._peerConnectionId) {
272
+ return;
273
+ }
274
+
275
+ this.localDescription = new RTCSessionDescription(ev.sdp);
276
+ const candidate = new RTCIceCandidate(ev.candidate); // @ts-ignore
277
+
278
+ this.dispatchEvent(new RTCIceCandidateEvent('icecandidate', {
279
+ candidate
280
+ }));
281
+ }), EventEmitter.addListener('peerConnectionIceGatheringChanged', ev => {
282
+ if (ev.id !== this._peerConnectionId) {
283
+ return;
284
+ }
285
+
286
+ this.iceGatheringState = ev.iceGatheringState;
287
+
288
+ if (this.iceGatheringState === 'complete') {
289
+ this.localDescription = new RTCSessionDescription(ev.sdp); // @ts-ignore
290
+
291
+ this.dispatchEvent(new RTCIceCandidateEvent('icecandidate', {
292
+ candidate: null
293
+ }));
294
+ } // @ts-ignore
295
+
296
+
297
+ this.dispatchEvent(new RTCEvent('icegatheringstatechange'));
298
+ }), EventEmitter.addListener('peerConnectionDidOpenDataChannel', ev => {
299
+ if (ev.id !== this._peerConnectionId) {
300
+ return;
301
+ }
302
+
303
+ const channel = new RTCDataChannel(ev.dataChannel); // @ts-ignore
304
+
305
+ this.dispatchEvent(new RTCDataChannelEvent('datachannel', {
306
+ channel
307
+ }));
308
+ })];
309
+ }
310
+ /**
311
+ * Creates a new RTCDataChannel object with the given label. The
312
+ * RTCDataChannelInit dictionary can be used to configure properties of the
313
+ * underlying channel such as data reliability.
314
+ *
315
+ * @param {string} label - the value with which the label attribute of the new
316
+ * instance is to be initialized
317
+ * @param {RTCDataChannelInit} dataChannelDict - an optional dictionary of
318
+ * values with which to initialize corresponding attributes of the new
319
+ * instance such as id
320
+ */
321
+
322
+
323
+ createDataChannel(label, dataChannelDict) {
324
+ if (dataChannelDict && 'id' in dataChannelDict) {
325
+ const id = dataChannelDict.id;
326
+
327
+ if (typeof id !== 'number') {
328
+ throw new TypeError('DataChannel id must be a number: ' + id);
329
+ }
330
+ }
331
+
332
+ const channelInfo = WebRTCModule.createDataChannel(this._peerConnectionId, label, dataChannelDict);
333
+
334
+ if (channelInfo === null) {
335
+ throw new TypeError('Failed to create new DataChannel');
336
+ }
337
+
338
+ return new RTCDataChannel(channelInfo);
339
+ }
340
+
341
+ }
342
+ //# sourceMappingURL=RTCPeerConnection.js.map