@dtelecom/livekit-client 1.12.1

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 (279) hide show
  1. package/LICENSE +175 -0
  2. package/README.md +315 -0
  3. package/dist/@dtelecom/livekit-client.e2ee.worker.js +2 -0
  4. package/dist/@dtelecom/livekit-client.e2ee.worker.js.map +1 -0
  5. package/dist/@dtelecom/livekit-client.e2ee.worker.mjs +1633 -0
  6. package/dist/@dtelecom/livekit-client.e2ee.worker.mjs.map +1 -0
  7. package/dist/@dtelecom/livekit-client.esm.mjs +22545 -0
  8. package/dist/@dtelecom/livekit-client.esm.mjs.map +1 -0
  9. package/dist/@dtelecom/livekit-client.umd.js +2 -0
  10. package/dist/@dtelecom/livekit-client.umd.js.map +1 -0
  11. package/dist/@dtelecom/src/api/SignalClient.d.ts +102 -0
  12. package/dist/@dtelecom/src/api/SignalClient.d.ts.map +1 -0
  13. package/dist/@dtelecom/src/connectionHelper/ConnectionCheck.d.ts +26 -0
  14. package/dist/@dtelecom/src/connectionHelper/ConnectionCheck.d.ts.map +1 -0
  15. package/dist/@dtelecom/src/connectionHelper/checks/Checker.d.ts +59 -0
  16. package/dist/@dtelecom/src/connectionHelper/checks/Checker.d.ts.map +1 -0
  17. package/dist/@dtelecom/src/connectionHelper/checks/publishAudio.d.ts +6 -0
  18. package/dist/@dtelecom/src/connectionHelper/checks/publishAudio.d.ts.map +1 -0
  19. package/dist/@dtelecom/src/connectionHelper/checks/publishVideo.d.ts +6 -0
  20. package/dist/@dtelecom/src/connectionHelper/checks/publishVideo.d.ts.map +1 -0
  21. package/dist/@dtelecom/src/connectionHelper/checks/reconnect.d.ts +6 -0
  22. package/dist/@dtelecom/src/connectionHelper/checks/reconnect.d.ts.map +1 -0
  23. package/dist/@dtelecom/src/connectionHelper/checks/turn.d.ts +6 -0
  24. package/dist/@dtelecom/src/connectionHelper/checks/turn.d.ts.map +1 -0
  25. package/dist/@dtelecom/src/connectionHelper/checks/webrtc.d.ts +6 -0
  26. package/dist/@dtelecom/src/connectionHelper/checks/webrtc.d.ts.map +1 -0
  27. package/dist/@dtelecom/src/connectionHelper/checks/websocket.d.ts +6 -0
  28. package/dist/@dtelecom/src/connectionHelper/checks/websocket.d.ts.map +1 -0
  29. package/dist/@dtelecom/src/e2ee/E2eeManager.d.ts +47 -0
  30. package/dist/@dtelecom/src/e2ee/E2eeManager.d.ts.map +1 -0
  31. package/dist/@dtelecom/src/e2ee/KeyProvider.d.ts +44 -0
  32. package/dist/@dtelecom/src/e2ee/KeyProvider.d.ts.map +1 -0
  33. package/dist/@dtelecom/src/e2ee/constants.d.ts +15 -0
  34. package/dist/@dtelecom/src/e2ee/constants.d.ts.map +1 -0
  35. package/dist/@dtelecom/src/e2ee/errors.d.ts +11 -0
  36. package/dist/@dtelecom/src/e2ee/errors.d.ts.map +1 -0
  37. package/dist/@dtelecom/src/e2ee/index.d.ts +4 -0
  38. package/dist/@dtelecom/src/e2ee/index.d.ts.map +1 -0
  39. package/dist/@dtelecom/src/e2ee/types.d.ts +130 -0
  40. package/dist/@dtelecom/src/e2ee/types.d.ts.map +1 -0
  41. package/dist/@dtelecom/src/e2ee/utils.d.ts +24 -0
  42. package/dist/@dtelecom/src/e2ee/utils.d.ts.map +1 -0
  43. package/dist/@dtelecom/src/e2ee/worker/FrameCryptor.d.ts +176 -0
  44. package/dist/@dtelecom/src/e2ee/worker/FrameCryptor.d.ts.map +1 -0
  45. package/dist/@dtelecom/src/e2ee/worker/ParticipantKeyHandler.d.ts +65 -0
  46. package/dist/@dtelecom/src/e2ee/worker/ParticipantKeyHandler.d.ts.map +1 -0
  47. package/dist/@dtelecom/src/e2ee/worker/e2ee.worker.d.ts +2 -0
  48. package/dist/@dtelecom/src/e2ee/worker/e2ee.worker.d.ts.map +1 -0
  49. package/dist/@dtelecom/src/index.d.ts +38 -0
  50. package/dist/@dtelecom/src/index.d.ts.map +1 -0
  51. package/dist/@dtelecom/src/logger.d.ts +29 -0
  52. package/dist/@dtelecom/src/logger.d.ts.map +1 -0
  53. package/dist/@dtelecom/src/options.d.ts +104 -0
  54. package/dist/@dtelecom/src/options.d.ts.map +1 -0
  55. package/dist/@dtelecom/src/proto/livekit_models_pb.d.ts +1264 -0
  56. package/dist/@dtelecom/src/proto/livekit_models_pb.d.ts.map +1 -0
  57. package/dist/@dtelecom/src/proto/livekit_rtc_pb.d.ts +1373 -0
  58. package/dist/@dtelecom/src/proto/livekit_rtc_pb.d.ts.map +1 -0
  59. package/dist/@dtelecom/src/room/DefaultReconnectPolicy.d.ts +8 -0
  60. package/dist/@dtelecom/src/room/DefaultReconnectPolicy.d.ts.map +1 -0
  61. package/dist/@dtelecom/src/room/DeviceManager.d.ts +9 -0
  62. package/dist/@dtelecom/src/room/DeviceManager.d.ts.map +1 -0
  63. package/dist/@dtelecom/src/room/PCTransport.d.ts +41 -0
  64. package/dist/@dtelecom/src/room/PCTransport.d.ts.map +1 -0
  65. package/dist/@dtelecom/src/room/RTCEngine.d.ts +143 -0
  66. package/dist/@dtelecom/src/room/RTCEngine.d.ts.map +1 -0
  67. package/dist/@dtelecom/src/room/ReconnectPolicy.d.ts +24 -0
  68. package/dist/@dtelecom/src/room/ReconnectPolicy.d.ts.map +1 -0
  69. package/dist/@dtelecom/src/room/RegionUrlProvider.d.ts +17 -0
  70. package/dist/@dtelecom/src/room/RegionUrlProvider.d.ts.map +1 -0
  71. package/dist/@dtelecom/src/room/Room.d.ts +248 -0
  72. package/dist/@dtelecom/src/room/Room.d.ts.map +1 -0
  73. package/dist/@dtelecom/src/room/defaults.d.ts +8 -0
  74. package/dist/@dtelecom/src/room/defaults.d.ts.map +1 -0
  75. package/dist/@dtelecom/src/room/errors.d.ts +43 -0
  76. package/dist/@dtelecom/src/room/errors.d.ts.map +1 -0
  77. package/dist/@dtelecom/src/room/events.d.ts +477 -0
  78. package/dist/@dtelecom/src/room/events.d.ts.map +1 -0
  79. package/dist/@dtelecom/src/room/participant/LocalParticipant.d.ts +177 -0
  80. package/dist/@dtelecom/src/room/participant/LocalParticipant.d.ts.map +1 -0
  81. package/dist/@dtelecom/src/room/participant/Participant.d.ts +95 -0
  82. package/dist/@dtelecom/src/room/participant/Participant.d.ts.map +1 -0
  83. package/dist/@dtelecom/src/room/participant/ParticipantTrackPermission.d.ts +26 -0
  84. package/dist/@dtelecom/src/room/participant/ParticipantTrackPermission.d.ts.map +1 -0
  85. package/dist/@dtelecom/src/room/participant/RemoteParticipant.d.ts +55 -0
  86. package/dist/@dtelecom/src/room/participant/RemoteParticipant.d.ts.map +1 -0
  87. package/dist/@dtelecom/src/room/participant/publishUtils.d.ts +28 -0
  88. package/dist/@dtelecom/src/room/participant/publishUtils.d.ts.map +1 -0
  89. package/dist/@dtelecom/src/room/stats.d.ts +67 -0
  90. package/dist/@dtelecom/src/room/stats.d.ts.map +1 -0
  91. package/dist/@dtelecom/src/room/timers.d.ts +13 -0
  92. package/dist/@dtelecom/src/room/timers.d.ts.map +1 -0
  93. package/dist/@dtelecom/src/room/track/LocalAudioTrack.d.ts +25 -0
  94. package/dist/@dtelecom/src/room/track/LocalAudioTrack.d.ts.map +1 -0
  95. package/dist/@dtelecom/src/room/track/LocalTrack.d.ts +78 -0
  96. package/dist/@dtelecom/src/room/track/LocalTrack.d.ts.map +1 -0
  97. package/dist/@dtelecom/src/room/track/LocalTrackPublication.d.ts +38 -0
  98. package/dist/@dtelecom/src/room/track/LocalTrackPublication.d.ts.map +1 -0
  99. package/dist/@dtelecom/src/room/track/LocalVideoTrack.d.ts +54 -0
  100. package/dist/@dtelecom/src/room/track/LocalVideoTrack.d.ts.map +1 -0
  101. package/dist/@dtelecom/src/room/track/RemoteAudioTrack.d.ts +53 -0
  102. package/dist/@dtelecom/src/room/track/RemoteAudioTrack.d.ts.map +1 -0
  103. package/dist/@dtelecom/src/room/track/RemoteTrack.d.ts +15 -0
  104. package/dist/@dtelecom/src/room/track/RemoteTrack.d.ts.map +1 -0
  105. package/dist/@dtelecom/src/room/track/RemoteTrackPublication.d.ts +64 -0
  106. package/dist/@dtelecom/src/room/track/RemoteTrackPublication.d.ts.map +1 -0
  107. package/dist/@dtelecom/src/room/track/RemoteVideoTrack.d.ts +56 -0
  108. package/dist/@dtelecom/src/room/track/RemoteVideoTrack.d.ts.map +1 -0
  109. package/dist/@dtelecom/src/room/track/Track.d.ts +125 -0
  110. package/dist/@dtelecom/src/room/track/Track.d.ts.map +1 -0
  111. package/dist/@dtelecom/src/room/track/TrackPublication.d.ts +72 -0
  112. package/dist/@dtelecom/src/room/track/TrackPublication.d.ts.map +1 -0
  113. package/dist/@dtelecom/src/room/track/create.d.ts +24 -0
  114. package/dist/@dtelecom/src/room/track/create.d.ts.map +1 -0
  115. package/dist/@dtelecom/src/room/track/facingMode.d.ts +41 -0
  116. package/dist/@dtelecom/src/room/track/facingMode.d.ts.map +1 -0
  117. package/dist/@dtelecom/src/room/track/options.d.ts +272 -0
  118. package/dist/@dtelecom/src/room/track/options.d.ts.map +1 -0
  119. package/dist/@dtelecom/src/room/track/processor/types.d.ts +19 -0
  120. package/dist/@dtelecom/src/room/track/processor/types.d.ts.map +1 -0
  121. package/dist/@dtelecom/src/room/track/types.d.ts +24 -0
  122. package/dist/@dtelecom/src/room/track/types.d.ts.map +1 -0
  123. package/dist/@dtelecom/src/room/track/utils.d.ts +27 -0
  124. package/dist/@dtelecom/src/room/track/utils.d.ts.map +1 -0
  125. package/dist/@dtelecom/src/room/types.d.ts +26 -0
  126. package/dist/@dtelecom/src/room/types.d.ts.map +1 -0
  127. package/dist/@dtelecom/src/room/utils.d.ts +92 -0
  128. package/dist/@dtelecom/src/room/utils.d.ts.map +1 -0
  129. package/dist/@dtelecom/src/test/MockMediaStreamTrack.d.ts +26 -0
  130. package/dist/@dtelecom/src/test/MockMediaStreamTrack.d.ts.map +1 -0
  131. package/dist/@dtelecom/src/test/mocks.d.ts +12 -0
  132. package/dist/@dtelecom/src/test/mocks.d.ts.map +1 -0
  133. package/dist/@dtelecom/src/utils/AsyncQueue.d.ts +23 -0
  134. package/dist/@dtelecom/src/utils/AsyncQueue.d.ts.map +1 -0
  135. package/dist/@dtelecom/src/utils/browserParser.d.ts +12 -0
  136. package/dist/@dtelecom/src/utils/browserParser.d.ts.map +1 -0
  137. package/dist/@dtelecom/src/version.d.ts +3 -0
  138. package/dist/@dtelecom/src/version.d.ts.map +1 -0
  139. package/dist/ts4.2/@dtelecom/src/api/SignalClient.d.ts +105 -0
  140. package/dist/ts4.2/@dtelecom/src/connectionHelper/ConnectionCheck.d.ts +26 -0
  141. package/dist/ts4.2/@dtelecom/src/connectionHelper/checks/Checker.d.ts +59 -0
  142. package/dist/ts4.2/@dtelecom/src/connectionHelper/checks/publishAudio.d.ts +6 -0
  143. package/dist/ts4.2/@dtelecom/src/connectionHelper/checks/publishVideo.d.ts +6 -0
  144. package/dist/ts4.2/@dtelecom/src/connectionHelper/checks/reconnect.d.ts +6 -0
  145. package/dist/ts4.2/@dtelecom/src/connectionHelper/checks/turn.d.ts +6 -0
  146. package/dist/ts4.2/@dtelecom/src/connectionHelper/checks/webrtc.d.ts +6 -0
  147. package/dist/ts4.2/@dtelecom/src/connectionHelper/checks/websocket.d.ts +6 -0
  148. package/dist/ts4.2/@dtelecom/src/e2ee/E2eeManager.d.ts +47 -0
  149. package/dist/ts4.2/@dtelecom/src/e2ee/KeyProvider.d.ts +44 -0
  150. package/dist/ts4.2/@dtelecom/src/e2ee/constants.d.ts +15 -0
  151. package/dist/ts4.2/@dtelecom/src/e2ee/errors.d.ts +11 -0
  152. package/dist/ts4.2/@dtelecom/src/e2ee/index.d.ts +4 -0
  153. package/dist/ts4.2/@dtelecom/src/e2ee/types.d.ts +130 -0
  154. package/dist/ts4.2/@dtelecom/src/e2ee/utils.d.ts +24 -0
  155. package/dist/ts4.2/@dtelecom/src/e2ee/worker/FrameCryptor.d.ts +176 -0
  156. package/dist/ts4.2/@dtelecom/src/e2ee/worker/ParticipantKeyHandler.d.ts +65 -0
  157. package/dist/ts4.2/@dtelecom/src/e2ee/worker/e2ee.worker.d.ts +2 -0
  158. package/dist/ts4.2/@dtelecom/src/index.d.ts +38 -0
  159. package/dist/ts4.2/@dtelecom/src/logger.d.ts +29 -0
  160. package/dist/ts4.2/@dtelecom/src/options.d.ts +104 -0
  161. package/dist/ts4.2/@dtelecom/src/proto/livekit_models_pb.d.ts +1264 -0
  162. package/dist/ts4.2/@dtelecom/src/proto/livekit_rtc_pb.d.ts +1373 -0
  163. package/dist/ts4.2/@dtelecom/src/room/DefaultReconnectPolicy.d.ts +8 -0
  164. package/dist/ts4.2/@dtelecom/src/room/DeviceManager.d.ts +9 -0
  165. package/dist/ts4.2/@dtelecom/src/room/PCTransport.d.ts +43 -0
  166. package/dist/ts4.2/@dtelecom/src/room/RTCEngine.d.ts +143 -0
  167. package/dist/ts4.2/@dtelecom/src/room/ReconnectPolicy.d.ts +24 -0
  168. package/dist/ts4.2/@dtelecom/src/room/RegionUrlProvider.d.ts +17 -0
  169. package/dist/ts4.2/@dtelecom/src/room/Room.d.ts +248 -0
  170. package/dist/ts4.2/@dtelecom/src/room/defaults.d.ts +8 -0
  171. package/dist/ts4.2/@dtelecom/src/room/errors.d.ts +43 -0
  172. package/dist/ts4.2/@dtelecom/src/room/events.d.ts +477 -0
  173. package/dist/ts4.2/@dtelecom/src/room/participant/LocalParticipant.d.ts +177 -0
  174. package/dist/ts4.2/@dtelecom/src/room/participant/Participant.d.ts +95 -0
  175. package/dist/ts4.2/@dtelecom/src/room/participant/ParticipantTrackPermission.d.ts +26 -0
  176. package/dist/ts4.2/@dtelecom/src/room/participant/RemoteParticipant.d.ts +55 -0
  177. package/dist/ts4.2/@dtelecom/src/room/participant/publishUtils.d.ts +28 -0
  178. package/dist/ts4.2/@dtelecom/src/room/stats.d.ts +67 -0
  179. package/dist/ts4.2/@dtelecom/src/room/timers.d.ts +13 -0
  180. package/dist/ts4.2/@dtelecom/src/room/track/LocalAudioTrack.d.ts +25 -0
  181. package/dist/ts4.2/@dtelecom/src/room/track/LocalTrack.d.ts +78 -0
  182. package/dist/ts4.2/@dtelecom/src/room/track/LocalTrackPublication.d.ts +38 -0
  183. package/dist/ts4.2/@dtelecom/src/room/track/LocalVideoTrack.d.ts +54 -0
  184. package/dist/ts4.2/@dtelecom/src/room/track/RemoteAudioTrack.d.ts +53 -0
  185. package/dist/ts4.2/@dtelecom/src/room/track/RemoteTrack.d.ts +15 -0
  186. package/dist/ts4.2/@dtelecom/src/room/track/RemoteTrackPublication.d.ts +64 -0
  187. package/dist/ts4.2/@dtelecom/src/room/track/RemoteVideoTrack.d.ts +56 -0
  188. package/dist/ts4.2/@dtelecom/src/room/track/Track.d.ts +125 -0
  189. package/dist/ts4.2/@dtelecom/src/room/track/TrackPublication.d.ts +72 -0
  190. package/dist/ts4.2/@dtelecom/src/room/track/create.d.ts +24 -0
  191. package/dist/ts4.2/@dtelecom/src/room/track/facingMode.d.ts +41 -0
  192. package/dist/ts4.2/@dtelecom/src/room/track/options.d.ts +280 -0
  193. package/dist/ts4.2/@dtelecom/src/room/track/processor/types.d.ts +19 -0
  194. package/dist/ts4.2/@dtelecom/src/room/track/types.d.ts +24 -0
  195. package/dist/ts4.2/@dtelecom/src/room/track/utils.d.ts +27 -0
  196. package/dist/ts4.2/@dtelecom/src/room/types.d.ts +26 -0
  197. package/dist/ts4.2/@dtelecom/src/room/utils.d.ts +92 -0
  198. package/dist/ts4.2/@dtelecom/src/test/MockMediaStreamTrack.d.ts +26 -0
  199. package/dist/ts4.2/@dtelecom/src/test/mocks.d.ts +12 -0
  200. package/dist/ts4.2/@dtelecom/src/utils/AsyncQueue.d.ts +23 -0
  201. package/dist/ts4.2/@dtelecom/src/utils/browserParser.d.ts +12 -0
  202. package/dist/ts4.2/@dtelecom/src/version.d.ts +3 -0
  203. package/package.json +102 -0
  204. package/src/api/SignalClient.ts +790 -0
  205. package/src/connectionHelper/ConnectionCheck.ts +90 -0
  206. package/src/connectionHelper/checks/Checker.ts +163 -0
  207. package/src/connectionHelper/checks/publishAudio.ts +33 -0
  208. package/src/connectionHelper/checks/publishVideo.ts +33 -0
  209. package/src/connectionHelper/checks/reconnect.ts +45 -0
  210. package/src/connectionHelper/checks/turn.ts +54 -0
  211. package/src/connectionHelper/checks/webrtc.ts +82 -0
  212. package/src/connectionHelper/checks/websocket.ts +27 -0
  213. package/src/e2ee/E2eeManager.ts +375 -0
  214. package/src/e2ee/KeyProvider.ts +78 -0
  215. package/src/e2ee/constants.ts +44 -0
  216. package/src/e2ee/errors.ts +16 -0
  217. package/src/e2ee/index.ts +3 -0
  218. package/src/e2ee/types.ts +161 -0
  219. package/src/e2ee/utils.ts +127 -0
  220. package/src/e2ee/worker/FrameCryptor.test.ts +19 -0
  221. package/src/e2ee/worker/FrameCryptor.ts +612 -0
  222. package/src/e2ee/worker/ParticipantKeyHandler.ts +175 -0
  223. package/src/e2ee/worker/e2ee.worker.ts +223 -0
  224. package/src/e2ee/worker/tsconfig.json +6 -0
  225. package/src/index.ts +85 -0
  226. package/src/logger.ts +64 -0
  227. package/src/options.ts +127 -0
  228. package/src/proto/livekit_models_pb.ts +2096 -0
  229. package/src/proto/livekit_rtc_pb.ts +2332 -0
  230. package/src/room/DefaultReconnectPolicy.ts +35 -0
  231. package/src/room/DeviceManager.ts +88 -0
  232. package/src/room/PCTransport.ts +452 -0
  233. package/src/room/RTCEngine.ts +1421 -0
  234. package/src/room/ReconnectPolicy.ts +27 -0
  235. package/src/room/RegionUrlProvider.ts +82 -0
  236. package/src/room/Room.test.ts +30 -0
  237. package/src/room/Room.ts +1907 -0
  238. package/src/room/defaults.ts +49 -0
  239. package/src/room/errors.ts +90 -0
  240. package/src/room/events.ts +535 -0
  241. package/src/room/participant/LocalParticipant.ts +1350 -0
  242. package/src/room/participant/Participant.ts +299 -0
  243. package/src/room/participant/ParticipantTrackPermission.ts +42 -0
  244. package/src/room/participant/RemoteParticipant.ts +359 -0
  245. package/src/room/participant/publishUtils.test.ts +189 -0
  246. package/src/room/participant/publishUtils.ts +399 -0
  247. package/src/room/stats.ts +136 -0
  248. package/src/room/timers.ts +16 -0
  249. package/src/room/track/LocalAudioTrack.ts +171 -0
  250. package/src/room/track/LocalTrack.ts +430 -0
  251. package/src/room/track/LocalTrackPublication.ts +87 -0
  252. package/src/room/track/LocalVideoTrack.test.ts +73 -0
  253. package/src/room/track/LocalVideoTrack.ts +513 -0
  254. package/src/room/track/RemoteAudioTrack.ts +248 -0
  255. package/src/room/track/RemoteTrack.ts +62 -0
  256. package/src/room/track/RemoteTrackPublication.ts +311 -0
  257. package/src/room/track/RemoteVideoTrack.test.ts +152 -0
  258. package/src/room/track/RemoteVideoTrack.ts +410 -0
  259. package/src/room/track/Track.ts +452 -0
  260. package/src/room/track/TrackPublication.ts +158 -0
  261. package/src/room/track/create.ts +143 -0
  262. package/src/room/track/facingMode.test.ts +31 -0
  263. package/src/room/track/facingMode.ts +103 -0
  264. package/src/room/track/options.ts +362 -0
  265. package/src/room/track/processor/types.ts +20 -0
  266. package/src/room/track/types.ts +25 -0
  267. package/src/room/track/utils.test.ts +111 -0
  268. package/src/room/track/utils.ts +183 -0
  269. package/src/room/types.ts +39 -0
  270. package/src/room/utils.test.ts +16 -0
  271. package/src/room/utils.ts +501 -0
  272. package/src/room/worker.d.ts +4 -0
  273. package/src/test/MockMediaStreamTrack.ts +84 -0
  274. package/src/test/mocks.ts +19 -0
  275. package/src/utils/AsyncQueue.test.ts +100 -0
  276. package/src/utils/AsyncQueue.ts +57 -0
  277. package/src/utils/browserParser.test.ts +88 -0
  278. package/src/utils/browserParser.ts +74 -0
  279. package/src/version.ts +4 -0
@@ -0,0 +1,375 @@
1
+ import { EventEmitter } from 'events';
2
+ import type TypedEventEmitter from 'typed-emitter';
3
+ import log from '../logger';
4
+ import { Encryption_Type, TrackInfo } from '../proto/livekit_models_pb';
5
+ import type RTCEngine from '../room/RTCEngine';
6
+ import type Room from '../room/Room';
7
+ import { ConnectionState } from '../room/Room';
8
+ import { DeviceUnsupportedError } from '../room/errors';
9
+ import { EngineEvent, ParticipantEvent, RoomEvent } from '../room/events';
10
+ import LocalTrack from '../room/track/LocalTrack';
11
+ import type RemoteTrack from '../room/track/RemoteTrack';
12
+ import type { Track } from '../room/track/Track';
13
+ import type { VideoCodec } from '../room/track/options';
14
+ import type { BaseKeyProvider } from './KeyProvider';
15
+ import { E2EE_FLAG } from './constants';
16
+ import type {
17
+ E2EEManagerCallbacks,
18
+ E2EEOptions,
19
+ E2EEWorkerMessage,
20
+ EnableMessage,
21
+ EncodeMessage,
22
+ InitMessage,
23
+ KeyInfo,
24
+ RTPVideoMapMessage,
25
+ RatchetRequestMessage,
26
+ RemoveTransformMessage,
27
+ SetKeyMessage,
28
+ UpdateCodecMessage,
29
+ } from './types';
30
+ import { EncryptionEvent } from './types';
31
+ import { isE2EESupported, isScriptTransformSupported, mimeTypeToVideoCodecString } from './utils';
32
+
33
+ /**
34
+ * @experimental
35
+ */
36
+ export class E2EEManager extends (EventEmitter as new () => TypedEventEmitter<E2EEManagerCallbacks>) {
37
+ protected worker: Worker;
38
+
39
+ protected room?: Room;
40
+
41
+ private encryptionEnabled: boolean;
42
+
43
+ private keyProvider: BaseKeyProvider;
44
+
45
+ get isEnabled() {
46
+ return this.encryptionEnabled;
47
+ }
48
+
49
+ constructor(options: E2EEOptions) {
50
+ super();
51
+ this.keyProvider = options.keyProvider;
52
+ this.worker = options.worker;
53
+ this.encryptionEnabled = false;
54
+ }
55
+
56
+ /**
57
+ * @internal
58
+ */
59
+ setup(room: Room) {
60
+ if (!isE2EESupported()) {
61
+ throw new DeviceUnsupportedError(
62
+ 'tried to setup end-to-end encryption on an unsupported browser',
63
+ );
64
+ }
65
+ log.info('setting up e2ee');
66
+ if (room !== this.room) {
67
+ this.room = room;
68
+ this.setupEventListeners(room, this.keyProvider);
69
+ // this.worker = new Worker('');
70
+ const msg: InitMessage = {
71
+ kind: 'init',
72
+ data: {
73
+ keyProviderOptions: this.keyProvider.getOptions(),
74
+ },
75
+ };
76
+ if (this.worker) {
77
+ log.info(`initializing worker`, { worker: this.worker });
78
+ this.worker.onmessage = this.onWorkerMessage;
79
+ this.worker.onerror = this.onWorkerError;
80
+ this.worker.postMessage(msg);
81
+ }
82
+ }
83
+ }
84
+
85
+ /**
86
+ * @internal
87
+ */
88
+ async setParticipantCryptorEnabled(enabled: boolean, participantId?: string) {
89
+ log.info(`set e2ee to ${enabled}`);
90
+
91
+ if (this.worker) {
92
+ const enableMsg: EnableMessage = {
93
+ kind: 'enable',
94
+ data: { enabled, participantId },
95
+ };
96
+ this.worker.postMessage(enableMsg);
97
+ } else {
98
+ throw new ReferenceError('failed to enable e2ee, worker is not ready');
99
+ }
100
+ }
101
+
102
+ private onWorkerMessage = (ev: MessageEvent<E2EEWorkerMessage>) => {
103
+ const { kind, data } = ev.data;
104
+ switch (kind) {
105
+ case 'error':
106
+ console.error('error in worker', { data });
107
+ this.emit(EncryptionEvent.Error, data.error);
108
+ break;
109
+ case 'enable':
110
+ if (this.encryptionEnabled !== data.enabled && !data.participantId) {
111
+ this.emit(
112
+ EncryptionEvent.ParticipantEncryptionStatusChanged,
113
+ data.enabled,
114
+ this.room?.localParticipant,
115
+ );
116
+ this.encryptionEnabled = data.enabled;
117
+ } else if (data.participantId) {
118
+ const participant = this.room?.getParticipantByIdentity(data.participantId);
119
+ this.emit(EncryptionEvent.ParticipantEncryptionStatusChanged, data.enabled, participant);
120
+ }
121
+ if (this.encryptionEnabled) {
122
+ this.keyProvider.getKeys().forEach((keyInfo) => {
123
+ this.postKey(keyInfo);
124
+ });
125
+ }
126
+ break;
127
+ case 'ratchetKey':
128
+ this.keyProvider.emit('keyRatcheted', data.material, data.keyIndex);
129
+ break;
130
+ default:
131
+ break;
132
+ }
133
+ };
134
+
135
+ private onWorkerError = (ev: ErrorEvent) => {
136
+ log.error('e2ee worker encountered an error:', { error: ev.error });
137
+ this.emit(EncryptionEvent.Error, ev.error);
138
+ };
139
+
140
+ public setupEngine(engine: RTCEngine) {
141
+ engine.on(EngineEvent.RTPVideoMapUpdate, (rtpMap) => {
142
+ this.postRTPMap(rtpMap);
143
+ });
144
+ }
145
+
146
+ private setupEventListeners(room: Room, keyProvider: BaseKeyProvider) {
147
+ room.on(RoomEvent.TrackPublished, (pub, participant) =>
148
+ this.setParticipantCryptorEnabled(
149
+ pub.trackInfo!.encryption !== Encryption_Type.NONE,
150
+ participant.identity,
151
+ ),
152
+ );
153
+ room.on(RoomEvent.ConnectionStateChanged, (state) => {
154
+ if (state === ConnectionState.Connected) {
155
+ room.participants.forEach((participant) => {
156
+ participant.tracks.forEach((pub) => {
157
+ this.setParticipantCryptorEnabled(
158
+ pub.trackInfo!.encryption !== Encryption_Type.NONE,
159
+ participant.identity,
160
+ );
161
+ });
162
+ });
163
+ }
164
+ });
165
+
166
+ room.on(RoomEvent.TrackUnsubscribed, (track, _, participant) => {
167
+ const msg: RemoveTransformMessage = {
168
+ kind: 'removeTransform',
169
+ data: {
170
+ participantId: participant.identity,
171
+ trackId: track.mediaStreamID,
172
+ },
173
+ };
174
+ this.worker?.postMessage(msg);
175
+ });
176
+ room.on(RoomEvent.TrackSubscribed, (track, pub, participant) => {
177
+ this.setupE2EEReceiver(track, participant.identity, pub.trackInfo);
178
+ });
179
+ room.localParticipant.on(ParticipantEvent.LocalTrackPublished, async (publication) => {
180
+ this.setupE2EESender(
181
+ publication.track!,
182
+ publication.track!.sender!,
183
+ room.localParticipant.identity,
184
+ );
185
+ });
186
+
187
+ keyProvider
188
+ .on('setKey', (keyInfo) => this.postKey(keyInfo))
189
+ .on('ratchetRequest', (participantId, keyIndex) =>
190
+ this.postRatchetRequest(participantId, keyIndex),
191
+ );
192
+ }
193
+
194
+ private postRatchetRequest(participantId?: string, keyIndex?: number) {
195
+ if (!this.worker) {
196
+ throw Error('could not ratchet key, worker is missing');
197
+ }
198
+ const msg: RatchetRequestMessage = {
199
+ kind: 'ratchetRequest',
200
+ data: {
201
+ participantId,
202
+ keyIndex,
203
+ },
204
+ };
205
+ this.worker.postMessage(msg);
206
+ }
207
+
208
+ private postKey({ key, participantId, keyIndex }: KeyInfo) {
209
+ if (!this.worker) {
210
+ throw Error('could not set key, worker is missing');
211
+ }
212
+ const msg: SetKeyMessage = {
213
+ kind: 'setKey',
214
+ data: {
215
+ participantId,
216
+ key,
217
+ keyIndex,
218
+ },
219
+ };
220
+ this.worker.postMessage(msg);
221
+ }
222
+
223
+ private postRTPMap(map: Map<number, VideoCodec>) {
224
+ if (!this.worker) {
225
+ throw Error('could not post rtp map, worker is missing');
226
+ }
227
+ const msg: RTPVideoMapMessage = {
228
+ kind: 'setRTPMap',
229
+ data: {
230
+ map,
231
+ },
232
+ };
233
+ this.worker.postMessage(msg);
234
+ }
235
+
236
+ private setupE2EEReceiver(track: RemoteTrack, remoteId: string, trackInfo?: TrackInfo) {
237
+ if (!track.receiver) {
238
+ return;
239
+ }
240
+ if (!trackInfo?.mimeType || trackInfo.mimeType === '') {
241
+ throw new TypeError('MimeType missing from trackInfo, cannot set up E2EE cryptor');
242
+ }
243
+ this.handleReceiver(
244
+ track.receiver,
245
+ track.mediaStreamID,
246
+ remoteId,
247
+ track.kind === 'video' ? mimeTypeToVideoCodecString(trackInfo.mimeType) : undefined,
248
+ );
249
+ }
250
+
251
+ private setupE2EESender(track: Track, sender: RTCRtpSender, localId: string) {
252
+ if (!(track instanceof LocalTrack) || !sender) {
253
+ if (!sender) log.warn('early return because sender is not ready');
254
+ return;
255
+ }
256
+ this.handleSender(sender, track.mediaStreamID, localId, undefined);
257
+ }
258
+
259
+ /**
260
+ * Handles the given {@code RTCRtpReceiver} by creating a {@code TransformStream} which will inject
261
+ * a frame decoder.
262
+ *
263
+ */
264
+ private async handleReceiver(
265
+ receiver: RTCRtpReceiver,
266
+ trackId: string,
267
+ participantId: string,
268
+ codec?: VideoCodec,
269
+ ) {
270
+ if (!this.worker) {
271
+ return;
272
+ }
273
+
274
+ if (isScriptTransformSupported()) {
275
+ const options = {
276
+ kind: 'decode',
277
+ participantId,
278
+ trackId,
279
+ codec,
280
+ };
281
+ // @ts-ignore
282
+ receiver.transform = new RTCRtpScriptTransform(this.worker, options);
283
+ } else {
284
+ if (E2EE_FLAG in receiver && codec) {
285
+ // only update codec
286
+ const msg: UpdateCodecMessage = {
287
+ kind: 'updateCodec',
288
+ data: {
289
+ trackId,
290
+ codec,
291
+ participantId,
292
+ },
293
+ };
294
+ this.worker.postMessage(msg);
295
+ return;
296
+ }
297
+ // @ts-ignore
298
+ let writable: WritableStream = receiver.writableStream;
299
+ // @ts-ignore
300
+ let readable: ReadableStream = receiver.readableStream;
301
+ if (!writable || !readable) {
302
+ // @ts-ignore
303
+ const receiverStreams = receiver.createEncodedStreams();
304
+ // @ts-ignore
305
+ receiver.writableStream = receiverStreams.writable;
306
+ writable = receiverStreams.writable;
307
+ // @ts-ignore
308
+ receiver.readableStream = receiverStreams.readable;
309
+ readable = receiverStreams.readable;
310
+ }
311
+
312
+ const msg: EncodeMessage = {
313
+ kind: 'decode',
314
+ data: {
315
+ readableStream: readable,
316
+ writableStream: writable,
317
+ trackId: trackId,
318
+ codec,
319
+ participantId,
320
+ },
321
+ };
322
+ this.worker.postMessage(msg, [readable, writable]);
323
+ }
324
+
325
+ // @ts-ignore
326
+ receiver[E2EE_FLAG] = true;
327
+ }
328
+
329
+ /**
330
+ * Handles the given {@code RTCRtpSender} by creating a {@code TransformStream} which will inject
331
+ * a frame encoder.
332
+ *
333
+ */
334
+ private handleSender(
335
+ sender: RTCRtpSender,
336
+ trackId: string,
337
+ participantId: string,
338
+ codec?: VideoCodec,
339
+ ) {
340
+ if (E2EE_FLAG in sender || !this.worker) {
341
+ return;
342
+ }
343
+
344
+ if (isScriptTransformSupported()) {
345
+ log.warn('initialize script transform');
346
+
347
+ const options = {
348
+ kind: 'encode',
349
+ participantId,
350
+ trackId,
351
+ codec,
352
+ };
353
+ // @ts-ignore
354
+ sender.transform = new RTCRtpScriptTransform(this.worker, options);
355
+ } else {
356
+ log.warn('initialize encoded streams');
357
+ // @ts-ignore
358
+ const senderStreams = sender.createEncodedStreams();
359
+ const msg: EncodeMessage = {
360
+ kind: 'encode',
361
+ data: {
362
+ readableStream: senderStreams.readable,
363
+ writableStream: senderStreams.writable,
364
+ codec,
365
+ trackId,
366
+ participantId,
367
+ },
368
+ };
369
+ this.worker.postMessage(msg, [senderStreams.readable, senderStreams.writable]);
370
+ }
371
+
372
+ // @ts-ignore
373
+ sender[E2EE_FLAG] = true;
374
+ }
375
+ }
@@ -0,0 +1,78 @@
1
+ import { EventEmitter } from 'events';
2
+ import type TypedEventEmitter from 'typed-emitter';
3
+ import { KEY_PROVIDER_DEFAULTS } from './constants';
4
+ import type { KeyInfo, KeyProviderCallbacks, KeyProviderOptions } from './types';
5
+ import { createKeyMaterialFromString } from './utils';
6
+
7
+ /**
8
+ * @experimental
9
+ */
10
+ export class BaseKeyProvider extends (EventEmitter as new () => TypedEventEmitter<KeyProviderCallbacks>) {
11
+ private keyInfoMap: Map<string, KeyInfo>;
12
+
13
+ private options: KeyProviderOptions;
14
+
15
+ constructor(options: Partial<KeyProviderOptions> = {}) {
16
+ super();
17
+ this.keyInfoMap = new Map();
18
+ this.options = { ...KEY_PROVIDER_DEFAULTS, ...options };
19
+ this.on('keyRatcheted', this.onKeyRatcheted);
20
+ }
21
+
22
+ /**
23
+ * callback to invoke once a key has been set for a participant
24
+ * @param key
25
+ * @param participantId
26
+ * @param keyIndex
27
+ */
28
+ protected onSetEncryptionKey(key: CryptoKey, participantId?: string, keyIndex?: number) {
29
+ const keyInfo: KeyInfo = { key, participantId, keyIndex };
30
+ this.keyInfoMap.set(`${participantId ?? 'shared'}-${keyIndex ?? 0}`, keyInfo);
31
+ this.emit('setKey', keyInfo);
32
+ }
33
+
34
+ /**
35
+ * callback being invoked after a ratchet request has been performed on the local participant
36
+ * that surfaces the new key material.
37
+ * @param material
38
+ * @param keyIndex
39
+ */
40
+ protected onKeyRatcheted = (material: CryptoKey, keyIndex?: number) => {
41
+ console.debug('key ratcheted event received', material, keyIndex);
42
+ };
43
+
44
+ getKeys() {
45
+ return Array.from(this.keyInfoMap.values());
46
+ }
47
+
48
+ getOptions() {
49
+ return this.options;
50
+ }
51
+
52
+ ratchetKey(participantId?: string, keyIndex?: number) {
53
+ this.emit('ratchetRequest', participantId, keyIndex);
54
+ }
55
+ }
56
+
57
+ /**
58
+ * A basic KeyProvider implementation intended for a single shared
59
+ * passphrase between all participants
60
+ * @experimental
61
+ */
62
+ export class ExternalE2EEKeyProvider extends BaseKeyProvider {
63
+ ratchetInterval: number | undefined;
64
+
65
+ constructor(options: Partial<Omit<KeyProviderOptions, 'sharedKey'>> = {}) {
66
+ const opts: Partial<KeyProviderOptions> = { ...options, sharedKey: true };
67
+ super(opts);
68
+ }
69
+
70
+ /**
71
+ * Accepts a passphrase that's used to create the crypto keys
72
+ * @param key
73
+ */
74
+ async setKey(key: string) {
75
+ const derivedKey = await createKeyMaterialFromString(key);
76
+ this.onSetEncryptionKey(derivedKey);
77
+ }
78
+ }
@@ -0,0 +1,44 @@
1
+ import type { KeyProviderOptions } from './types';
2
+
3
+ export const ENCRYPTION_ALGORITHM = 'AES-GCM';
4
+
5
+ // We use a ringbuffer of keys so we can change them and still decode packets that were
6
+ // encrypted with an old key. We use a size of 16 which corresponds to the four bits
7
+ // in the frame trailer.
8
+ export const KEYRING_SIZE = 16;
9
+
10
+ // How many consecutive frames can fail decrypting before a particular key gets marked as invalid
11
+ export const DECRYPTION_FAILURE_TOLERANCE = 10;
12
+
13
+ // We copy the first bytes of the VP8 payload unencrypted.
14
+ // For keyframes this is 10 bytes, for non-keyframes (delta) 3. See
15
+ // https://tools.ietf.org/html/rfc6386#section-9.1
16
+ // This allows the bridge to continue detecting keyframes (only one byte needed in the JVB)
17
+ // and is also a bit easier for the VP8 decoder (i.e. it generates funny garbage pictures
18
+ // instead of being unable to decode).
19
+ // This is a bit for show and we might want to reduce to 1 unconditionally in the final version.
20
+ //
21
+ // For audio (where frame.type is not set) we do not encrypt the opus TOC byte:
22
+ // https://tools.ietf.org/html/rfc6716#section-3.1
23
+ export const UNENCRYPTED_BYTES = {
24
+ key: 10,
25
+ delta: 3,
26
+ audio: 1, // frame.type is not set on audio, so this is set manually
27
+ empty: 0,
28
+ } as const;
29
+
30
+ /* We use a 12 byte bit IV. This is signalled in plain together with the
31
+ packet. See https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/encrypt#parameters */
32
+ export const IV_LENGTH = 12;
33
+
34
+ // flag set to indicate that e2ee has been setup for sender/receiver;
35
+ export const E2EE_FLAG = 'lk_e2ee';
36
+
37
+ export const SALT = 'LKFrameEncryptionKey';
38
+
39
+ export const KEY_PROVIDER_DEFAULTS: KeyProviderOptions = {
40
+ sharedKey: false,
41
+ ratchetSalt: SALT,
42
+ ratchetWindowSize: 8,
43
+ failureTolerance: DECRYPTION_FAILURE_TOLERANCE,
44
+ } as const;
@@ -0,0 +1,16 @@
1
+ import { LivekitError } from '../room/errors';
2
+
3
+ export enum CryptorErrorReason {
4
+ InvalidKey = 0,
5
+ MissingKey = 1,
6
+ InternalError = 2,
7
+ }
8
+
9
+ export class CryptorError extends LivekitError {
10
+ reason: CryptorErrorReason;
11
+
12
+ constructor(message?: string, reason: CryptorErrorReason = CryptorErrorReason.InternalError) {
13
+ super(40, message);
14
+ this.reason = reason;
15
+ }
16
+ }
@@ -0,0 +1,3 @@
1
+ export * from './KeyProvider';
2
+ export * from './utils';
3
+ export * from './types';
@@ -0,0 +1,161 @@
1
+ import type Participant from '../room/participant/Participant';
2
+ import type { VideoCodec } from '../room/track/options';
3
+ import type { BaseKeyProvider } from './KeyProvider';
4
+ import type { CryptorError } from './errors';
5
+
6
+ export interface BaseMessage {
7
+ kind: string;
8
+ data?: unknown;
9
+ }
10
+
11
+ export interface InitMessage extends BaseMessage {
12
+ kind: 'init';
13
+ data: {
14
+ keyProviderOptions: KeyProviderOptions;
15
+ };
16
+ }
17
+
18
+ export interface SetKeyMessage extends BaseMessage {
19
+ kind: 'setKey';
20
+ data: {
21
+ participantId?: string;
22
+ key: CryptoKey;
23
+ keyIndex?: number;
24
+ };
25
+ }
26
+
27
+ export interface RTPVideoMapMessage extends BaseMessage {
28
+ kind: 'setRTPMap';
29
+ data: {
30
+ map: Map<number, VideoCodec>;
31
+ };
32
+ }
33
+
34
+ export interface EncodeMessage extends BaseMessage {
35
+ kind: 'decode' | 'encode';
36
+ data: {
37
+ participantId: string;
38
+ readableStream: ReadableStream;
39
+ writableStream: WritableStream;
40
+ trackId: string;
41
+ codec?: VideoCodec;
42
+ };
43
+ }
44
+
45
+ export interface RemoveTransformMessage extends BaseMessage {
46
+ kind: 'removeTransform';
47
+ data: {
48
+ participantId: string;
49
+ trackId: string;
50
+ };
51
+ }
52
+
53
+ export interface UpdateCodecMessage extends BaseMessage {
54
+ kind: 'updateCodec';
55
+ data: {
56
+ participantId: string;
57
+ trackId: string;
58
+ codec: VideoCodec;
59
+ };
60
+ }
61
+
62
+ export interface RatchetRequestMessage extends BaseMessage {
63
+ kind: 'ratchetRequest';
64
+ data: {
65
+ participantId: string | undefined;
66
+ keyIndex?: number;
67
+ };
68
+ }
69
+
70
+ export interface RatchetMessage extends BaseMessage {
71
+ kind: 'ratchetKey';
72
+ data: {
73
+ // participantId: string | undefined;
74
+ keyIndex?: number;
75
+ material: CryptoKey;
76
+ };
77
+ }
78
+
79
+ export interface ErrorMessage extends BaseMessage {
80
+ kind: 'error';
81
+ data: {
82
+ error: Error;
83
+ };
84
+ }
85
+
86
+ export interface EnableMessage extends BaseMessage {
87
+ kind: 'enable';
88
+ data: {
89
+ // if no participant id is set it indicates publisher encryption enable/disable
90
+ participantId?: string;
91
+ enabled: boolean;
92
+ };
93
+ }
94
+
95
+ export type E2EEWorkerMessage =
96
+ | InitMessage
97
+ | SetKeyMessage
98
+ | EncodeMessage
99
+ | ErrorMessage
100
+ | EnableMessage
101
+ | RemoveTransformMessage
102
+ | RTPVideoMapMessage
103
+ | UpdateCodecMessage
104
+ | RatchetRequestMessage
105
+ | RatchetMessage;
106
+
107
+ export type KeySet = { material: CryptoKey; encryptionKey: CryptoKey };
108
+
109
+ export type KeyProviderOptions = {
110
+ sharedKey: boolean;
111
+ ratchetSalt: string;
112
+ ratchetWindowSize: number;
113
+ failureTolerance: number;
114
+ };
115
+
116
+ export type KeyProviderCallbacks = {
117
+ setKey: (keyInfo: KeyInfo) => void;
118
+ ratchetRequest: (participantId?: string, keyIndex?: number) => void;
119
+ /** currently only emitted for local participant */
120
+ keyRatcheted: (material: CryptoKey, keyIndex?: number) => void;
121
+ };
122
+
123
+ export type ParticipantKeyHandlerCallbacks = {
124
+ keyRatcheted: (material: CryptoKey, keyIndex?: number, participantId?: string) => void;
125
+ };
126
+
127
+ export type E2EEManagerCallbacks = {
128
+ participantEncryptionStatusChanged: (enabled: boolean, participant?: Participant) => void;
129
+ encryptionError: (error: Error) => void;
130
+ };
131
+
132
+ export const EncryptionEvent = {
133
+ ParticipantEncryptionStatusChanged: 'participantEncryptionStatusChanged',
134
+ Error: 'encryptionError',
135
+ } as const;
136
+
137
+ export type CryptorCallbacks = {
138
+ cryptorError: (error: CryptorError) => void;
139
+ };
140
+
141
+ export const CryptorEvent = {
142
+ Error: 'cryptorError',
143
+ } as const;
144
+
145
+ export type KeyInfo = {
146
+ key: CryptoKey;
147
+ participantId?: string;
148
+ keyIndex?: number;
149
+ };
150
+
151
+ export type E2EEOptions = {
152
+ keyProvider: BaseKeyProvider;
153
+ worker: Worker;
154
+ };
155
+
156
+ export type DecodeRatchetOptions = {
157
+ /** attempts */
158
+ ratchetCount: number;
159
+ /** ratcheted key to try */
160
+ encryptionKey?: CryptoKey;
161
+ };