@streamr/dht 103.1.2 → 103.2.0-experiment.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 (303) hide show
  1. package/dist/exports-browser.cjs +7636 -0
  2. package/dist/exports-browser.cjs.map +1 -0
  3. package/dist/exports-browser.d.ts +1321 -0
  4. package/dist/exports-browser.js +7611 -0
  5. package/dist/exports-browser.js.map +1 -0
  6. package/dist/exports-nodejs.cjs +7833 -0
  7. package/dist/exports-nodejs.cjs.map +1 -0
  8. package/dist/exports-nodejs.d.ts +1321 -0
  9. package/dist/exports-nodejs.js +7808 -0
  10. package/dist/exports-nodejs.js.map +1 -0
  11. package/package.json +41 -25
  12. package/dist/generated/google/protobuf/any.d.ts +0 -180
  13. package/dist/generated/google/protobuf/any.js +0 -155
  14. package/dist/generated/google/protobuf/any.js.map +0 -1
  15. package/dist/generated/google/protobuf/empty.d.ts +0 -31
  16. package/dist/generated/google/protobuf/empty.js +0 -45
  17. package/dist/generated/google/protobuf/empty.js.map +0 -1
  18. package/dist/generated/google/protobuf/timestamp.d.ts +0 -156
  19. package/dist/generated/google/protobuf/timestamp.js +0 -136
  20. package/dist/generated/google/protobuf/timestamp.js.map +0 -1
  21. package/dist/generated/packages/dht/protos/DhtRpc.client.d.ts +0 -371
  22. package/dist/generated/packages/dht/protos/DhtRpc.client.js +0 -292
  23. package/dist/generated/packages/dht/protos/DhtRpc.client.js.map +0 -1
  24. package/dist/generated/packages/dht/protos/DhtRpc.d.ts +0 -1031
  25. package/dist/generated/packages/dht/protos/DhtRpc.js +0 -702
  26. package/dist/generated/packages/dht/protos/DhtRpc.js.map +0 -1
  27. package/dist/generated/packages/dht/protos/DhtRpc.server.d.ts +0 -168
  28. package/dist/generated/packages/dht/protos/DhtRpc.server.js +0 -3
  29. package/dist/generated/packages/dht/protos/DhtRpc.server.js.map +0 -1
  30. package/dist/generated/packages/proto-rpc/protos/ProtoRpc.d.ts +0 -87
  31. package/dist/generated/packages/proto-rpc/protos/ProtoRpc.js +0 -66
  32. package/dist/generated/packages/proto-rpc/protos/ProtoRpc.js.map +0 -1
  33. package/dist/package.json +0 -61
  34. package/dist/src/connection/Connection.d.ts +0 -12
  35. package/dist/src/connection/Connection.js +0 -30
  36. package/dist/src/connection/Connection.js.map +0 -1
  37. package/dist/src/connection/ConnectionLockRpcLocal.d.ts +0 -22
  38. package/dist/src/connection/ConnectionLockRpcLocal.js +0 -54
  39. package/dist/src/connection/ConnectionLockRpcLocal.js.map +0 -1
  40. package/dist/src/connection/ConnectionLockRpcRemote.d.ts +0 -10
  41. package/dist/src/connection/ConnectionLockRpcRemote.js +0 -61
  42. package/dist/src/connection/ConnectionLockRpcRemote.js.map +0 -1
  43. package/dist/src/connection/ConnectionLockStates.d.ts +0 -27
  44. package/dist/src/connection/ConnectionLockStates.js +0 -114
  45. package/dist/src/connection/ConnectionLockStates.js.map +0 -1
  46. package/dist/src/connection/ConnectionManager.d.ts +0 -85
  47. package/dist/src/connection/ConnectionManager.js +0 -569
  48. package/dist/src/connection/ConnectionManager.js.map +0 -1
  49. package/dist/src/connection/ConnectionsView.d.ts +0 -7
  50. package/dist/src/connection/ConnectionsView.js +0 -3
  51. package/dist/src/connection/ConnectionsView.js.map +0 -1
  52. package/dist/src/connection/ConnectorFacade.d.ts +0 -58
  53. package/dist/src/connection/ConnectorFacade.js +0 -154
  54. package/dist/src/connection/ConnectorFacade.js.map +0 -1
  55. package/dist/src/connection/Handshaker.d.ts +0 -27
  56. package/dist/src/connection/Handshaker.js +0 -179
  57. package/dist/src/connection/Handshaker.js.map +0 -1
  58. package/dist/src/connection/IConnection.d.ts +0 -32
  59. package/dist/src/connection/IConnection.js +0 -12
  60. package/dist/src/connection/IConnection.js.map +0 -1
  61. package/dist/src/connection/ManagedConnection.d.ts +0 -30
  62. package/dist/src/connection/ManagedConnection.js +0 -129
  63. package/dist/src/connection/ManagedConnection.js.map +0 -1
  64. package/dist/src/connection/OutputBuffer.d.ts +0 -9
  65. package/dist/src/connection/OutputBuffer.js +0 -26
  66. package/dist/src/connection/OutputBuffer.js.map +0 -1
  67. package/dist/src/connection/PendingConnection.d.ts +0 -19
  68. package/dist/src/connection/PendingConnection.js +0 -59
  69. package/dist/src/connection/PendingConnection.js.map +0 -1
  70. package/dist/src/connection/connectivityChecker.d.ts +0 -9
  71. package/dist/src/connection/connectivityChecker.js +0 -138
  72. package/dist/src/connection/connectivityChecker.js.map +0 -1
  73. package/dist/src/connection/connectivityRequestHandler.d.ts +0 -4
  74. package/dist/src/connection/connectivityRequestHandler.js +0 -108
  75. package/dist/src/connection/connectivityRequestHandler.js.map +0 -1
  76. package/dist/src/connection/simulator/Simulator.d.ts +0 -36
  77. package/dist/src/connection/simulator/Simulator.js +0 -290
  78. package/dist/src/connection/simulator/Simulator.js.map +0 -1
  79. package/dist/src/connection/simulator/SimulatorConnection.d.ts +0 -18
  80. package/dist/src/connection/simulator/SimulatorConnection.js +0 -123
  81. package/dist/src/connection/simulator/SimulatorConnection.js.map +0 -1
  82. package/dist/src/connection/simulator/SimulatorConnector.d.ts +0 -16
  83. package/dist/src/connection/simulator/SimulatorConnector.js +0 -80
  84. package/dist/src/connection/simulator/SimulatorConnector.js.map +0 -1
  85. package/dist/src/connection/simulator/SimulatorTransport.d.ts +0 -6
  86. package/dist/src/connection/simulator/SimulatorTransport.js +0 -17
  87. package/dist/src/connection/simulator/SimulatorTransport.js.map +0 -1
  88. package/dist/src/connection/simulator/pings.d.ts +0 -21
  89. package/dist/src/connection/simulator/pings.js +0 -61
  90. package/dist/src/connection/simulator/pings.js.map +0 -1
  91. package/dist/src/connection/webrtc/BrowserWebrtcConnection.d.ts +0 -37
  92. package/dist/src/connection/webrtc/BrowserWebrtcConnection.js +0 -229
  93. package/dist/src/connection/webrtc/BrowserWebrtcConnection.js.map +0 -1
  94. package/dist/src/connection/webrtc/IWebrtcConnection.d.ts +0 -21
  95. package/dist/src/connection/webrtc/IWebrtcConnection.js +0 -9
  96. package/dist/src/connection/webrtc/IWebrtcConnection.js.map +0 -1
  97. package/dist/src/connection/webrtc/NodeWebrtcConnection.d.ts +0 -45
  98. package/dist/src/connection/webrtc/NodeWebrtcConnection.js +0 -229
  99. package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +0 -1
  100. package/dist/src/connection/webrtc/WebrtcConnector.d.ts +0 -43
  101. package/dist/src/connection/webrtc/WebrtcConnector.js +0 -208
  102. package/dist/src/connection/webrtc/WebrtcConnector.js.map +0 -1
  103. package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +0 -26
  104. package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +0 -82
  105. package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +0 -1
  106. package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.d.ts +0 -8
  107. package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js +0 -50
  108. package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js.map +0 -1
  109. package/dist/src/connection/webrtc/iceServerAsString.d.ts +0 -2
  110. package/dist/src/connection/webrtc/iceServerAsString.js +0 -17
  111. package/dist/src/connection/webrtc/iceServerAsString.js.map +0 -1
  112. package/dist/src/connection/websocket/AbstractWebsocketClientConnection.d.ts +0 -27
  113. package/dist/src/connection/websocket/AbstractWebsocketClientConnection.js +0 -107
  114. package/dist/src/connection/websocket/AbstractWebsocketClientConnection.js.map +0 -1
  115. package/dist/src/connection/websocket/AutoCertifierClientFacade.d.ts +0 -26
  116. package/dist/src/connection/websocket/AutoCertifierClientFacade.js +0 -39
  117. package/dist/src/connection/websocket/AutoCertifierClientFacade.js.map +0 -1
  118. package/dist/src/connection/websocket/BrowserWebsocketClientConnection.d.ts +0 -7
  119. package/dist/src/connection/websocket/BrowserWebsocketClientConnection.js +0 -44
  120. package/dist/src/connection/websocket/BrowserWebsocketClientConnection.js.map +0 -1
  121. package/dist/src/connection/websocket/NodeWebsocketClientConnection.d.ts +0 -7
  122. package/dist/src/connection/websocket/NodeWebsocketClientConnection.js +0 -39
  123. package/dist/src/connection/websocket/NodeWebsocketClientConnection.js.map +0 -1
  124. package/dist/src/connection/websocket/WebsocketClientConnector.d.ts +0 -26
  125. package/dist/src/connection/websocket/WebsocketClientConnector.js +0 -86
  126. package/dist/src/connection/websocket/WebsocketClientConnector.js.map +0 -1
  127. package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.d.ts +0 -18
  128. package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.js +0 -23
  129. package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.js.map +0 -1
  130. package/dist/src/connection/websocket/WebsocketClientConnectorRpcRemote.d.ts +0 -5
  131. package/dist/src/connection/websocket/WebsocketClientConnectorRpcRemote.js +0 -17
  132. package/dist/src/connection/websocket/WebsocketClientConnectorRpcRemote.js.map +0 -1
  133. package/dist/src/connection/websocket/WebsocketServer.d.ts +0 -25
  134. package/dist/src/connection/websocket/WebsocketServer.js +0 -146
  135. package/dist/src/connection/websocket/WebsocketServer.js.map +0 -1
  136. package/dist/src/connection/websocket/WebsocketServerConnection.d.ts +0 -22
  137. package/dist/src/connection/websocket/WebsocketServerConnection.js +0 -101
  138. package/dist/src/connection/websocket/WebsocketServerConnection.js.map +0 -1
  139. package/dist/src/connection/websocket/WebsocketServerConnector.d.ts +0 -44
  140. package/dist/src/connection/websocket/WebsocketServerConnector.js +0 -279
  141. package/dist/src/connection/websocket/WebsocketServerConnector.js.map +0 -1
  142. package/dist/src/dht/DhtNode.d.ts +0 -119
  143. package/dist/src/dht/DhtNode.js +0 -500
  144. package/dist/src/dht/DhtNode.js.map +0 -1
  145. package/dist/src/dht/DhtNodeRpcLocal.d.ts +0 -23
  146. package/dist/src/dht/DhtNodeRpcLocal.js +0 -54
  147. package/dist/src/dht/DhtNodeRpcLocal.js.map +0 -1
  148. package/dist/src/dht/DhtNodeRpcRemote.d.ts +0 -25
  149. package/dist/src/dht/DhtNodeRpcRemote.js +0 -83
  150. package/dist/src/dht/DhtNodeRpcRemote.js.map +0 -1
  151. package/dist/src/dht/ExternalApiRpcLocal.d.ts +0 -18
  152. package/dist/src/dht/ExternalApiRpcLocal.js +0 -32
  153. package/dist/src/dht/ExternalApiRpcLocal.js.map +0 -1
  154. package/dist/src/dht/ExternalApiRpcRemote.d.ts +0 -10
  155. package/dist/src/dht/ExternalApiRpcRemote.js +0 -58
  156. package/dist/src/dht/ExternalApiRpcRemote.js.map +0 -1
  157. package/dist/src/dht/PeerManager.d.ts +0 -63
  158. package/dist/src/dht/PeerManager.js +0 -251
  159. package/dist/src/dht/PeerManager.js.map +0 -1
  160. package/dist/src/dht/contact/Contact.d.ts +0 -8
  161. package/dist/src/dht/contact/Contact.js +0 -18
  162. package/dist/src/dht/contact/Contact.js.map +0 -1
  163. package/dist/src/dht/contact/ContactList.d.ts +0 -19
  164. package/dist/src/dht/contact/ContactList.js +0 -35
  165. package/dist/src/dht/contact/ContactList.js.map +0 -1
  166. package/dist/src/dht/contact/RandomContactList.d.ts +0 -11
  167. package/dist/src/dht/contact/RandomContactList.js +0 -47
  168. package/dist/src/dht/contact/RandomContactList.js.map +0 -1
  169. package/dist/src/dht/contact/RingContactList.d.ts +0 -28
  170. package/dist/src/dht/contact/RingContactList.js +0 -126
  171. package/dist/src/dht/contact/RingContactList.js.map +0 -1
  172. package/dist/src/dht/contact/RpcRemote.d.ts +0 -19
  173. package/dist/src/dht/contact/RpcRemote.js +0 -61
  174. package/dist/src/dht/contact/RpcRemote.js.map +0 -1
  175. package/dist/src/dht/contact/SortedContactList.d.ts +0 -37
  176. package/dist/src/dht/contact/SortedContactList.js +0 -134
  177. package/dist/src/dht/contact/SortedContactList.js.map +0 -1
  178. package/dist/src/dht/contact/getClosestNodes.d.ts +0 -6
  179. package/dist/src/dht/contact/getClosestNodes.js +0 -19
  180. package/dist/src/dht/contact/getClosestNodes.js.map +0 -1
  181. package/dist/src/dht/contact/ringIdentifiers.d.ts +0 -16
  182. package/dist/src/dht/contact/ringIdentifiers.js +0 -54
  183. package/dist/src/dht/contact/ringIdentifiers.js.map +0 -1
  184. package/dist/src/dht/discovery/DiscoverySession.d.ts +0 -29
  185. package/dist/src/dht/discovery/DiscoverySession.js +0 -102
  186. package/dist/src/dht/discovery/DiscoverySession.js.map +0 -1
  187. package/dist/src/dht/discovery/PeerDiscovery.d.ts +0 -42
  188. package/dist/src/dht/discovery/PeerDiscovery.js +0 -193
  189. package/dist/src/dht/discovery/PeerDiscovery.js.map +0 -1
  190. package/dist/src/dht/discovery/RingDiscoverySession.d.ts +0 -28
  191. package/dist/src/dht/discovery/RingDiscoverySession.js +0 -116
  192. package/dist/src/dht/discovery/RingDiscoverySession.js.map +0 -1
  193. package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +0 -38
  194. package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +0 -165
  195. package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +0 -1
  196. package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.d.ts +0 -14
  197. package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js +0 -26
  198. package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js.map +0 -1
  199. package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.d.ts +0 -6
  200. package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js +0 -44
  201. package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +0 -1
  202. package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +0 -45
  203. package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +0 -185
  204. package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +0 -1
  205. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.d.ts +0 -14
  206. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js +0 -20
  207. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js.map +0 -1
  208. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.d.ts +0 -6
  209. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.js +0 -21
  210. package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.js.map +0 -1
  211. package/dist/src/dht/routing/DuplicateDetector.d.ts +0 -10
  212. package/dist/src/dht/routing/DuplicateDetector.js +0 -31
  213. package/dist/src/dht/routing/DuplicateDetector.js.map +0 -1
  214. package/dist/src/dht/routing/Router.d.ts +0 -35
  215. package/dist/src/dht/routing/Router.js +0 -204
  216. package/dist/src/dht/routing/Router.js.map +0 -1
  217. package/dist/src/dht/routing/RouterRpcLocal.d.ts +0 -20
  218. package/dist/src/dht/routing/RouterRpcLocal.js +0 -67
  219. package/dist/src/dht/routing/RouterRpcLocal.js.map +0 -1
  220. package/dist/src/dht/routing/RouterRpcRemote.d.ts +0 -8
  221. package/dist/src/dht/routing/RouterRpcRemote.js +0 -81
  222. package/dist/src/dht/routing/RouterRpcRemote.js.map +0 -1
  223. package/dist/src/dht/routing/RoutingSession.d.ts +0 -56
  224. package/dist/src/dht/routing/RoutingSession.js +0 -201
  225. package/dist/src/dht/routing/RoutingSession.js.map +0 -1
  226. package/dist/src/dht/routing/RoutingTablesCache.d.ts +0 -24
  227. package/dist/src/dht/routing/RoutingTablesCache.js +0 -46
  228. package/dist/src/dht/routing/RoutingTablesCache.js.map +0 -1
  229. package/dist/src/dht/routing/getPreviousPeer.d.ts +0 -2
  230. package/dist/src/dht/routing/getPreviousPeer.js +0 -12
  231. package/dist/src/dht/routing/getPreviousPeer.js.map +0 -1
  232. package/dist/src/dht/store/LocalDataStore.d.ts +0 -14
  233. package/dist/src/dht/store/LocalDataStore.js +0 -78
  234. package/dist/src/dht/store/LocalDataStore.js.map +0 -1
  235. package/dist/src/dht/store/StoreManager.d.ts +0 -32
  236. package/dist/src/dht/store/StoreManager.js +0 -126
  237. package/dist/src/dht/store/StoreManager.js.map +0 -1
  238. package/dist/src/dht/store/StoreRpcLocal.d.ts +0 -21
  239. package/dist/src/dht/store/StoreRpcLocal.js +0 -65
  240. package/dist/src/dht/store/StoreRpcLocal.js.map +0 -1
  241. package/dist/src/dht/store/StoreRpcRemote.d.ts +0 -7
  242. package/dist/src/dht/store/StoreRpcRemote.js +0 -29
  243. package/dist/src/dht/store/StoreRpcRemote.js.map +0 -1
  244. package/dist/src/exports.d.ts +0 -25
  245. package/dist/src/exports.js +0 -48
  246. package/dist/src/exports.js.map +0 -1
  247. package/dist/src/helpers/AddressTools.d.ts +0 -2
  248. package/dist/src/helpers/AddressTools.js +0 -32
  249. package/dist/src/helpers/AddressTools.js.map +0 -1
  250. package/dist/src/helpers/Connectivity.d.ts +0 -4
  251. package/dist/src/helpers/Connectivity.js +0 -24
  252. package/dist/src/helpers/Connectivity.js.map +0 -1
  253. package/dist/src/helpers/browser/isBrowserEnvironment.d.ts +0 -1
  254. package/dist/src/helpers/browser/isBrowserEnvironment.js +0 -6
  255. package/dist/src/helpers/browser/isBrowserEnvironment.js.map +0 -1
  256. package/dist/src/helpers/browser/isBrowserEnvironment_override.d.ts +0 -1
  257. package/dist/src/helpers/browser/isBrowserEnvironment_override.js +0 -7
  258. package/dist/src/helpers/browser/isBrowserEnvironment_override.js.map +0 -1
  259. package/dist/src/helpers/createPeerDescriptor.d.ts +0 -3
  260. package/dist/src/helpers/createPeerDescriptor.js +0 -58
  261. package/dist/src/helpers/createPeerDescriptor.js.map +0 -1
  262. package/dist/src/helpers/createPeerDescriptorSignaturePayload.d.ts +0 -2
  263. package/dist/src/helpers/createPeerDescriptorSignaturePayload.js +0 -30
  264. package/dist/src/helpers/createPeerDescriptorSignaturePayload.js.map +0 -1
  265. package/dist/src/helpers/debugHelpers.d.ts +0 -3
  266. package/dist/src/helpers/debugHelpers.js +0 -11
  267. package/dist/src/helpers/debugHelpers.js.map +0 -1
  268. package/dist/src/helpers/errors.d.ts +0 -72
  269. package/dist/src/helpers/errors.js +0 -97
  270. package/dist/src/helpers/errors.js.map +0 -1
  271. package/dist/src/helpers/offering.d.ts +0 -4
  272. package/dist/src/helpers/offering.js +0 -18
  273. package/dist/src/helpers/offering.js.map +0 -1
  274. package/dist/src/helpers/protoClasses.d.ts +0 -2
  275. package/dist/src/helpers/protoClasses.js +0 -32
  276. package/dist/src/helpers/protoClasses.js.map +0 -1
  277. package/dist/src/helpers/protoToString.d.ts +0 -2
  278. package/dist/src/helpers/protoToString.js +0 -19
  279. package/dist/src/helpers/protoToString.js.map +0 -1
  280. package/dist/src/helpers/version.d.ts +0 -6
  281. package/dist/src/helpers/version.js +0 -38
  282. package/dist/src/helpers/version.js.map +0 -1
  283. package/dist/src/identifiers.d.ts +0 -10
  284. package/dist/src/identifiers.js +0 -31
  285. package/dist/src/identifiers.js.map +0 -1
  286. package/dist/src/rpc-protocol/DhtCallContext.d.ts +0 -12
  287. package/dist/src/rpc-protocol/DhtCallContext.js +0 -17
  288. package/dist/src/rpc-protocol/DhtCallContext.js.map +0 -1
  289. package/dist/src/rpc-protocol/DhtRpcOptions.d.ts +0 -10
  290. package/dist/src/rpc-protocol/DhtRpcOptions.js +0 -3
  291. package/dist/src/rpc-protocol/DhtRpcOptions.js.map +0 -1
  292. package/dist/src/transport/ITransport.d.ts +0 -31
  293. package/dist/src/transport/ITransport.js +0 -9
  294. package/dist/src/transport/ITransport.js.map +0 -1
  295. package/dist/src/transport/ListeningRpcCommunicator.d.ts +0 -11
  296. package/dist/src/transport/ListeningRpcCommunicator.js +0 -31
  297. package/dist/src/transport/ListeningRpcCommunicator.js.map +0 -1
  298. package/dist/src/transport/RoutingRpcCommunicator.d.ts +0 -10
  299. package/dist/src/transport/RoutingRpcCommunicator.js +0 -60
  300. package/dist/src/transport/RoutingRpcCommunicator.js.map +0 -1
  301. package/dist/src/types/ServiceID.d.ts +0 -1
  302. package/dist/src/types/ServiceID.js +0 -3
  303. package/dist/src/types/ServiceID.js.map +0 -1
@@ -1,61 +0,0 @@
1
- "use strict";
2
- /* eslint-disable max-len, @typescript-eslint/prefer-for-of */
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.regionPingMatrix = exports.RegionIndex = void 0;
5
- exports.getRegionDelayMatrix = getRegionDelayMatrix;
6
- exports.getRandomRegion = getRandomRegion;
7
- // This file contains a 16x16 matrix of ping times measured between
8
- // amazon regions. Converted to typescript from the file pings.csv
9
- // in order to make loading into browser easier.
10
- var RegionIndex;
11
- (function (RegionIndex) {
12
- RegionIndex[RegionIndex["eu_central_1"] = 0] = "eu_central_1";
13
- RegionIndex[RegionIndex["eu_west_1"] = 1] = "eu_west_1";
14
- RegionIndex[RegionIndex["eu_west_2"] = 2] = "eu_west_2";
15
- RegionIndex[RegionIndex["eu_west_3"] = 3] = "eu_west_3";
16
- RegionIndex[RegionIndex["eu_north_1"] = 4] = "eu_north_1";
17
- RegionIndex[RegionIndex["us_east_1"] = 5] = "us_east_1";
18
- RegionIndex[RegionIndex["us_east_2"] = 6] = "us_east_2";
19
- RegionIndex[RegionIndex["us_west_1"] = 7] = "us_west_1";
20
- RegionIndex[RegionIndex["us_west_2"] = 8] = "us_west_2";
21
- RegionIndex[RegionIndex["ca_central_1"] = 9] = "ca_central_1";
22
- RegionIndex[RegionIndex["ap_south_1"] = 10] = "ap_south_1";
23
- RegionIndex[RegionIndex["ap_northeast_2"] = 11] = "ap_northeast_2";
24
- RegionIndex[RegionIndex["ap_southeast_1"] = 12] = "ap_southeast_1";
25
- RegionIndex[RegionIndex["ap_southeast_2"] = 13] = "ap_southeast_2";
26
- RegionIndex[RegionIndex["ap_northeast_1"] = 14] = "ap_northeast_1";
27
- RegionIndex[RegionIndex["sa_east_1"] = 15] = "sa_east_1";
28
- })(RegionIndex || (exports.RegionIndex = RegionIndex = {}));
29
- exports.regionPingMatrix = [
30
- [0.325, 23.163, 12.942, 8.923, 20.699, 89.208, 99.98, 150.077, 139.224, 90.454, 117.0, 226.823, 154.592, 286.753, 222.719, 205.563],
31
- [24.911, 0.195, 10.022, 18.544, 39.802, 66.161, 93.877, 136.271, 127.362, 73.733, 122.187, 229.064, 177.256, 254.277, 200.207, 186.817],
32
- [12.879, 9.994, 0.167, 8.626, 31.896, 74.663, 85.231, 136.185, 125.328, 77.811, 111.29, 236.34, 164.357, 262.577, 207.745, 187.383],
33
- [9.007, 16.823, 8.761, 0.191, 28.449, 81.969, 92.599, 140.961, 132.269, 85.444, 107.421, 243.981, 167.17, 279.322, 214.088, 197.986],
34
- [20.661, 40.0, 31.176, 27.645, 0.137, 104.171, 115.704, 165.01, 155.741, 107.635, 136.75, 267.321, 173.951, 292.266, 238.492, 216.048],
35
- [89.076, 67.701, 75.414, 81.598, 104.866, 0.284, 11.501, 61.662, 78.612, 14.115, 186.697, 174.546, 210.93, 196.071, 145.622, 114.919],
36
- [100.018, 93.968, 85.06, 92.582, 115.719, 11.514, 0.184, 51.668, 48.447, 25.808, 195.433, 160.031, 197.27, 186.913, 133.115, 127.954],
37
- [148.544, 137.18, 136.137, 141.333, 164.73, 60.257, 50.886, 0.197, 21.509, 77.668, 229.32, 134.858, 174.472, 137.329, 107.566, 175.944],
38
- [137.885, 128.304, 125.316, 132.271, 155.726, 63.376, 48.457, 20.743, 0.293, 59.645, 218.285, 126.988, 162.72, 138.599, 100.203, 174.612],
39
- [90.494, 78.203, 77.998, 84.348, 109.549, 14.136, 25.917, 77.323, 59.692, 0.163, 187.854, 169.253, 206.944, 195.467, 141.054, 126.962],
40
- [120.19, 119.978, 112.023, 107.434, 139.361, 185.043, 195.679, 233.008, 216.025, 186.888, 0.177, 130.21, 56.019, 145.643, 128.57, 298.98],
41
- [226.296, 229.187, 237.024, 243.839, 266.919, 174.727, 160.066, 136.623, 124.799, 169.854, 129.131, 0.189, 81.065, 139.967, 33.24, 284.578],
42
- [154.691, 178.279, 170.997, 154.261, 173.776, 211.511, 197.551, 173.735, 162.834, 206.659, 56.964, 68.853, 0.215, 91.601, 69.684, 323.146],
43
- [289.784, 253.234, 261.752, 277.504, 292.125, 198.099, 185.709, 136.413, 138.613, 194.986, 142.484, 147.706, 91.615, 0.156, 114.518, 311.12],
44
- [223.926, 201.084, 210.133, 216.779, 237.762, 145.336, 132.887, 108.26, 98.057, 142.613, 122.716, 33.185, 68.547, 114.901, 0.162, 257.403],
45
- [205.555, 178.082, 186.533, 195.774, 216.701, 117.089, 128.001, 175.761, 176.018, 125.551, 303.904, 285.782, 323.15, 309.618, 255.904, 0.262]
46
- ];
47
- function getRegionDelayMatrix() {
48
- const ret = [];
49
- for (let i = 0; i < exports.regionPingMatrix.length; i++) {
50
- const row = [];
51
- for (let j = 0; j < exports.regionPingMatrix[i].length; j++) {
52
- row.push(exports.regionPingMatrix[i][j] / 2);
53
- }
54
- ret.push(row);
55
- }
56
- return ret;
57
- }
58
- function getRandomRegion() {
59
- return Math.floor(Math.random() * 15);
60
- }
61
- //# sourceMappingURL=pings.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pings.js","sourceRoot":"","sources":["../../../../src/connection/simulator/pings.ts"],"names":[],"mappings":";AAAA,8DAA8D;;;AA2B9D,oDAUC;AAED,0CAEC;AAvCD,mEAAmE;AACnE,kEAAkE;AAClE,gDAAgD;AAEhD,IAAY,WAA0N;AAAtO,WAAY,WAAW;IAAG,6DAAY,CAAA;IAAE,uDAAS,CAAA;IAAE,uDAAS,CAAA;IAAE,uDAAS,CAAA;IAAE,yDAAU,CAAA;IAAE,uDAAS,CAAA;IAAE,uDAAS,CAAA;IAAE,uDAAS,CAAA;IAAE,uDAAS,CAAA;IAAE,6DAAY,CAAA;IAAE,0DAAU,CAAA;IAAE,kEAAc,CAAA;IAAE,kEAAc,CAAA;IAAE,kEAAc,CAAA;IAAE,kEAAc,CAAA;IAAE,wDAAS,CAAA;AAAC,CAAC,EAA1N,WAAW,2BAAX,WAAW,QAA+M;AAEzN,QAAA,gBAAgB,GAAG;IAC5B,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,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e;IAC3B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA;AACzC,CAAC"}
@@ -1,37 +0,0 @@
1
- import EventEmitter from 'eventemitter3';
2
- import { WebrtcConnectionEvents, IWebrtcConnection } from './IWebrtcConnection';
3
- import { IConnection, ConnectionID, ConnectionType } from '../IConnection';
4
- import { IceServer } from './WebrtcConnector';
5
- interface Params {
6
- iceServers?: IceServer[];
7
- }
8
- export declare class NodeWebrtcConnection extends EventEmitter<WebrtcConnectionEvents> implements IWebrtcConnection, IConnection {
9
- connectionId: ConnectionID;
10
- readonly connectionType: ConnectionType;
11
- private lastState;
12
- private readonly iceServers;
13
- private peerConnection?;
14
- private readonly bufferThresholdHigh;
15
- private readonly bufferThresholdLow;
16
- private dataChannel?;
17
- private makingOffer;
18
- private isOffering;
19
- private closed;
20
- private earlyTimeout;
21
- private readonly messageQueue;
22
- constructor(params: Params);
23
- start(isOffering: boolean): void;
24
- setRemoteDescription(description: string, type: string): Promise<void>;
25
- addRemoteCandidate(candidate: string, mid: string): void;
26
- isOpen(): boolean;
27
- close(gracefulLeave: boolean, reason?: string): Promise<void>;
28
- private doClose;
29
- destroy(): void;
30
- send(data: Uint8Array): void;
31
- private setupDataChannel;
32
- private stopListening;
33
- private onDataChannelOpen;
34
- private onStateChange;
35
- setConnectionId(connectionId: ConnectionID): void;
36
- }
37
- export {};
@@ -1,229 +0,0 @@
1
- "use strict";
2
- /// <reference lib="dom" />
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.NodeWebrtcConnection = void 0;
8
- const eventemitter3_1 = __importDefault(require("eventemitter3"));
9
- const IWebrtcConnection_1 = require("./IWebrtcConnection");
10
- const IConnection_1 = require("../IConnection");
11
- const utils_1 = require("@streamr/utils");
12
- const WebrtcConnector_1 = require("./WebrtcConnector");
13
- const Connection_1 = require("../Connection");
14
- var DisconnectedRtcPeerConnectionStateEnum;
15
- (function (DisconnectedRtcPeerConnectionStateEnum) {
16
- DisconnectedRtcPeerConnectionStateEnum["DISCONNECTED"] = "disconnected";
17
- DisconnectedRtcPeerConnectionStateEnum["FAILED"] = "failed";
18
- DisconnectedRtcPeerConnectionStateEnum["CLOSED"] = "closed";
19
- })(DisconnectedRtcPeerConnectionStateEnum || (DisconnectedRtcPeerConnectionStateEnum = {}));
20
- const logger = new utils_1.Logger(module);
21
- class NodeWebrtcConnection extends eventemitter3_1.default {
22
- connectionId;
23
- connectionType = IConnection_1.ConnectionType.WEBRTC;
24
- // We need to keep track of connection state ourselves because
25
- // RTCPeerConnection.connectionState is not supported on Firefox
26
- lastState = 'connecting';
27
- iceServers;
28
- peerConnection;
29
- bufferThresholdHigh = 2 ** 17;
30
- bufferThresholdLow = 2 ** 15;
31
- dataChannel;
32
- makingOffer = false;
33
- isOffering = false;
34
- closed = false;
35
- earlyTimeout;
36
- messageQueue = [];
37
- constructor(params) {
38
- super();
39
- this.connectionId = (0, Connection_1.createRandomConnectionId)();
40
- this.iceServers = params.iceServers ?? [];
41
- this.earlyTimeout = setTimeout(() => {
42
- this.doClose(false, 'timed out due to remote descriptor not being set');
43
- }, WebrtcConnector_1.EARLY_TIMEOUT);
44
- }
45
- start(isOffering) {
46
- this.isOffering = isOffering;
47
- const urls = this.iceServers.map(({ url, port, username, password }) => ({
48
- urls: `${url}:${port}`,
49
- username,
50
- credential: password
51
- }));
52
- this.peerConnection = new RTCPeerConnection({ iceServers: urls });
53
- this.peerConnection.onicecandidate = (event) => {
54
- if ((event.candidate !== null) && (event.candidate.sdpMid !== null)) {
55
- this.emit('localCandidate', event.candidate.candidate, event.candidate.sdpMid);
56
- }
57
- };
58
- this.peerConnection.onicegatheringstatechange = () => {
59
- logger.trace(`conn.onGatheringStateChange: ${this.peerConnection?.iceGatheringState}`);
60
- };
61
- this.peerConnection.onconnectionstatechange = () => this.onStateChange();
62
- if (isOffering) {
63
- this.peerConnection.onnegotiationneeded = async () => {
64
- if (this.peerConnection !== undefined) {
65
- this.makingOffer = true;
66
- try {
67
- await this.peerConnection.setLocalDescription();
68
- }
69
- catch (err) {
70
- logger.warn('Failed to set local description', { err });
71
- }
72
- if (this.peerConnection.localDescription !== null) {
73
- this.emit('localDescription', this.peerConnection.localDescription?.sdp, this.peerConnection.localDescription?.type);
74
- }
75
- }
76
- this.makingOffer = false;
77
- };
78
- const dataChannel = this.peerConnection.createDataChannel('streamrDataChannel');
79
- this.setupDataChannel(dataChannel);
80
- }
81
- else {
82
- this.peerConnection.ondatachannel = (event) => {
83
- this.setupDataChannel(event.channel);
84
- };
85
- }
86
- }
87
- async setRemoteDescription(description, type) {
88
- const offerCollision = (type.toLowerCase() === IWebrtcConnection_1.RtcDescription.OFFER) && (this.makingOffer || this.peerConnection?.signalingState != 'stable');
89
- const ignoreOffer = this.isOffering && offerCollision;
90
- if (ignoreOffer) {
91
- return;
92
- }
93
- try {
94
- await this.peerConnection?.setRemoteDescription({ sdp: description, type: type.toLowerCase() });
95
- clearTimeout(this.earlyTimeout);
96
- }
97
- catch (err) {
98
- logger.warn('Failed to set remote description', { err });
99
- }
100
- if ((type.toLowerCase() === IWebrtcConnection_1.RtcDescription.OFFER) && (this.peerConnection !== undefined)) {
101
- try {
102
- await this.peerConnection.setLocalDescription();
103
- }
104
- catch (err) {
105
- logger.warn('Failed to set local description', { err });
106
- }
107
- if (this.peerConnection.localDescription !== null) {
108
- this.emit('localDescription', this.peerConnection.localDescription.sdp, this.peerConnection.localDescription.type);
109
- }
110
- }
111
- }
112
- addRemoteCandidate(candidate, mid) {
113
- this.peerConnection?.addIceCandidate({ candidate: candidate, sdpMid: mid })
114
- .catch((err) => {
115
- logger.warn('Failed to add ICE candidate', { err });
116
- });
117
- }
118
- isOpen() {
119
- return this.lastState === 'connected';
120
- }
121
- // IConnection implementation
122
- async close(gracefulLeave, reason) {
123
- this.doClose(gracefulLeave, reason);
124
- }
125
- doClose(gracefulLeave, reason) {
126
- if (!this.closed) {
127
- this.closed = true;
128
- this.lastState = 'closed';
129
- clearTimeout(this.earlyTimeout);
130
- this.stopListening();
131
- this.emit('disconnected', gracefulLeave, undefined, reason);
132
- this.removeAllListeners();
133
- if (this.dataChannel !== undefined) {
134
- try {
135
- this.dataChannel.close();
136
- }
137
- catch (err) {
138
- logger.warn('Failed to close data channel', { err });
139
- }
140
- }
141
- this.dataChannel = undefined;
142
- if (this.peerConnection !== undefined) {
143
- try {
144
- this.peerConnection.close();
145
- }
146
- catch (err) {
147
- logger.warn('Failed to close connection', { err });
148
- }
149
- }
150
- this.peerConnection = undefined;
151
- }
152
- }
153
- destroy() {
154
- this.removeAllListeners();
155
- this.doClose(false);
156
- }
157
- send(data) {
158
- if (this.lastState === 'connected') {
159
- if (this.dataChannel.bufferedAmount > this.bufferThresholdHigh) {
160
- this.messageQueue.push(data);
161
- }
162
- else {
163
- this.dataChannel?.send(data);
164
- }
165
- }
166
- else {
167
- logger.warn('Tried to send on a connection with last state ' + this.lastState);
168
- }
169
- }
170
- setupDataChannel(dataChannel) {
171
- this.dataChannel = dataChannel;
172
- this.dataChannel.binaryType = 'arraybuffer';
173
- this.dataChannel.bufferedAmountLowThreshold = this.bufferThresholdLow;
174
- dataChannel.onopen = () => {
175
- logger.trace('dc.onOpen');
176
- this.onDataChannelOpen();
177
- };
178
- dataChannel.onclose = () => {
179
- logger.trace('dc.onClosed');
180
- this.doClose(false);
181
- };
182
- dataChannel.onerror = (err) => {
183
- logger.warn('Data channel error', { err });
184
- };
185
- dataChannel.onmessage = (msg) => {
186
- logger.trace('dc.onmessage');
187
- this.emit('data', new Uint8Array(msg.data));
188
- };
189
- dataChannel.onbufferedamountlow = () => {
190
- logger.trace('dc.onBufferedAmountLow');
191
- while (this.messageQueue.length > 0 && this.dataChannel.bufferedAmount < this.bufferThresholdHigh) {
192
- const data = this.messageQueue.shift();
193
- this.dataChannel.send(data);
194
- }
195
- };
196
- }
197
- stopListening() {
198
- if (this.dataChannel !== undefined) {
199
- this.dataChannel.onopen = null;
200
- this.dataChannel.onclose = null;
201
- this.dataChannel.onerror = null;
202
- this.dataChannel.onbufferedamountlow = null;
203
- this.dataChannel.onmessage = null;
204
- }
205
- if (this.peerConnection !== undefined) {
206
- this.peerConnection.onconnectionstatechange = null;
207
- this.peerConnection.onicecandidate = null;
208
- this.peerConnection.onicegatheringstatechange = null;
209
- this.peerConnection.onnegotiationneeded = null;
210
- this.peerConnection.ondatachannel = null;
211
- }
212
- }
213
- onDataChannelOpen() {
214
- this.lastState = 'connected';
215
- this.emit('connected');
216
- }
217
- onStateChange() {
218
- if (this.peerConnection.connectionState === DisconnectedRtcPeerConnectionStateEnum.CLOSED
219
- || this.peerConnection.connectionState === DisconnectedRtcPeerConnectionStateEnum.DISCONNECTED
220
- || this.peerConnection.connectionState === DisconnectedRtcPeerConnectionStateEnum.FAILED) {
221
- this.doClose(false);
222
- }
223
- }
224
- setConnectionId(connectionId) {
225
- this.connectionId = connectionId;
226
- }
227
- }
228
- exports.NodeWebrtcConnection = NodeWebrtcConnection;
229
- //# sourceMappingURL=BrowserWebrtcConnection.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BrowserWebrtcConnection.js","sourceRoot":"","sources":["../../../../src/connection/webrtc/BrowserWebrtcConnection.ts"],"names":[],"mappings":";AAAA,2BAA2B;;;;;;AAE3B,kEAAwC;AACxC,2DAA+F;AAC/F,gDAA0E;AAC1E,0CAAuC;AACvC,uDAA4D;AAC5D,8CAAwD;AAExD,IAAK,sCAIJ;AAJD,WAAK,sCAAsC;IACvC,uEAA6B,CAAA;IAC7B,2DAAiB,CAAA;IACjB,2DAAiB,CAAA;AACrB,CAAC,EAJI,sCAAsC,KAAtC,sCAAsC,QAI1C;AAED,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAMjC,MAAa,oBAAqB,SAAQ,uBAAoC;IAEnE,YAAY,CAAc;IACjB,cAAc,GA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ents } from '../IConnection';
2
- export interface WebrtcConnectionEvents extends ConnectionEvents {
3
- localDescription: (description: string, type: string) => void;
4
- localCandidate: (candidate: string, mid: string) => void;
5
- }
6
- export declare enum RtcDescription {
7
- OFFER = "offer",
8
- ANSWER = "answer"
9
- }
10
- export interface IWebrtcConnection {
11
- start(isOffering: boolean): void;
12
- on(event: 'localDescription', listener: (description: string, type: string) => void): this;
13
- on(event: 'localCandidate', listener: (candidate: string, mid: string) => void): this;
14
- once(event: 'localDescription', listener: (description: string, type: string) => void): this;
15
- once(event: 'localCandidate', listener: (candidate: string, mid: string) => void): this;
16
- off(event: 'localDescription', listener: (description: string, type: string) => void): this;
17
- off(event: 'localCandidate', listener: (candidate: string, mid: string) => void): this;
18
- setRemoteDescription(description: string, type: string): Promise<void>;
19
- addRemoteCandidate(candidate: string, mid: string): void;
20
- isOpen(): boolean;
21
- }
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RtcDescription = void 0;
4
- var RtcDescription;
5
- (function (RtcDescription) {
6
- RtcDescription["OFFER"] = "offer";
7
- RtcDescription["ANSWER"] = "answer";
8
- })(RtcDescription || (exports.RtcDescription = RtcDescription = {}));
9
- //# sourceMappingURL=IWebrtcConnection.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IWebrtcConnection.js","sourceRoot":"","sources":["../../../../src/connection/webrtc/IWebrtcConnection.ts"],"names":[],"mappings":";;;AAOA,IAAY,cAGX;AAHD,WAAY,cAAc;IACtB,iCAAe,CAAA;IACf,mCAAiB,CAAA;AACrB,CAAC,EAHW,cAAc,8BAAd,cAAc,QAGzB"}
@@ -1,45 +0,0 @@
1
- import { IWebrtcConnection, WebrtcConnectionEvents } from './IWebrtcConnection';
2
- import { ConnectionType, IConnection, ConnectionID } from '../IConnection';
3
- import { PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc';
4
- import EventEmitter from 'eventemitter3';
5
- import { IceServer } from './WebrtcConnector';
6
- import { PortRange } from '../ConnectionManager';
7
- export interface Params {
8
- remotePeerDescriptor: PeerDescriptor;
9
- bufferThresholdHigh?: number;
10
- bufferThresholdLow?: number;
11
- maxMessageSize?: number;
12
- iceServers?: IceServer[];
13
- portRange?: PortRange;
14
- }
15
- export declare class NodeWebrtcConnection extends EventEmitter<WebrtcConnectionEvents> implements IConnection, IWebrtcConnection {
16
- connectionId: ConnectionID;
17
- private connection?;
18
- private dataChannel?;
19
- private lastState;
20
- private remoteDescriptionSet;
21
- readonly connectionType: ConnectionType;
22
- private readonly iceServers;
23
- private readonly bufferThresholdHigh;
24
- private readonly bufferThresholdLow;
25
- private readonly remotePeerDescriptor;
26
- private readonly portRange?;
27
- private readonly maxMessageSize?;
28
- private readonly messageQueue;
29
- private closed;
30
- private offering?;
31
- private readonly earlyTimeout;
32
- constructor(params: Params);
33
- start(isOffering: boolean): void;
34
- setRemoteDescription(description: string, type: string): Promise<void>;
35
- addRemoteCandidate(candidate: string, mid: string): void;
36
- send(data: Uint8Array): void;
37
- close(gracefulLeave: boolean, reason?: string): Promise<void>;
38
- private doClose;
39
- destroy(): void;
40
- private setupDataChannel;
41
- private onDataChannelOpen;
42
- private onStateChange;
43
- isOpen(): boolean;
44
- setConnectionId(connectionId: ConnectionID): void;
45
- }
@@ -1,229 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.NodeWebrtcConnection = void 0;
7
- const IConnection_1 = require("../IConnection");
8
- const eventemitter3_1 = __importDefault(require("eventemitter3"));
9
- const node_datachannel_1 = require("node-datachannel");
10
- const utils_1 = require("@streamr/utils");
11
- const errors_1 = require("../../helpers/errors");
12
- const iceServerAsString_1 = require("./iceServerAsString");
13
- const WebrtcConnector_1 = require("./WebrtcConnector");
14
- const identifiers_1 = require("../../identifiers");
15
- const Connection_1 = require("../Connection");
16
- const logger = new utils_1.Logger(module);
17
- // Re-defined accoring to https://github.com/microsoft/TypeScript/blob/main/src/lib/dom.generated.d.ts
18
- // because importing single dom definitions in not possible
19
- var RtcPeerConnectionStateEnum;
20
- (function (RtcPeerConnectionStateEnum) {
21
- RtcPeerConnectionStateEnum["closed"] = "closed";
22
- RtcPeerConnectionStateEnum["connected"] = "connected";
23
- RtcPeerConnectionStateEnum["connecting"] = "connecting";
24
- RtcPeerConnectionStateEnum["disconnected"] = "disconnected";
25
- RtcPeerConnectionStateEnum["failed"] = "failed";
26
- RtcPeerConnectionStateEnum["new"] = "new";
27
- })(RtcPeerConnectionStateEnum || (RtcPeerConnectionStateEnum = {}));
28
- (0, node_datachannel_1.initLogger)('Fatal');
29
- class NodeWebrtcConnection extends eventemitter3_1.default {
30
- connectionId;
31
- connection;
32
- dataChannel;
33
- lastState = 'connecting';
34
- remoteDescriptionSet = false;
35
- connectionType = IConnection_1.ConnectionType.WEBRTC;
36
- iceServers;
37
- bufferThresholdHigh;
38
- bufferThresholdLow;
39
- remotePeerDescriptor;
40
- portRange;
41
- maxMessageSize;
42
- messageQueue = [];
43
- closed = false;
44
- offering;
45
- earlyTimeout;
46
- constructor(params) {
47
- super();
48
- this.connectionId = (0, Connection_1.createRandomConnectionId)();
49
- this.iceServers = params.iceServers ?? [];
50
- this.bufferThresholdHigh = params.bufferThresholdHigh ?? 2 ** 17;
51
- this.bufferThresholdLow = params.bufferThresholdLow ?? 2 ** 15;
52
- this.remotePeerDescriptor = params.remotePeerDescriptor;
53
- this.maxMessageSize = params.maxMessageSize ?? 1048576;
54
- this.portRange = params.portRange;
55
- this.earlyTimeout = setTimeout(() => {
56
- this.doClose(false, 'timed out due to remote descriptor not being set');
57
- }, WebrtcConnector_1.EARLY_TIMEOUT);
58
- }
59
- start(isOffering) {
60
- const nodeId = (0, identifiers_1.toNodeId)(this.remotePeerDescriptor);
61
- this.offering = isOffering;
62
- logger.trace(`Starting new connection for peer ${nodeId}`, { isOffering });
63
- this.connection = new node_datachannel_1.PeerConnection(nodeId, {
64
- iceServers: this.iceServers.map(iceServerAsString_1.iceServerAsString),
65
- maxMessageSize: this.maxMessageSize,
66
- portRangeBegin: this.portRange?.min,
67
- portRangeEnd: this.portRange?.max,
68
- });
69
- this.connection.onStateChange((state) => this.onStateChange(state));
70
- this.connection.onGatheringStateChange(() => { });
71
- this.connection.onLocalDescription((description, type) => {
72
- this.emit('localDescription', description, type.toString());
73
- });
74
- this.connection.onLocalCandidate((candidate, mid) => {
75
- this.emit('localCandidate', candidate, mid);
76
- });
77
- if (isOffering) {
78
- const dataChannel = this.connection.createDataChannel('streamrDataChannel');
79
- this.setupDataChannel(dataChannel);
80
- }
81
- else {
82
- this.connection.onDataChannel((dataChannel) => this.setupDataChannel(dataChannel));
83
- }
84
- }
85
- async setRemoteDescription(description, type) {
86
- if (this.connection) {
87
- clearTimeout(this.earlyTimeout);
88
- const remoteNodeId = (0, identifiers_1.toNodeId)(this.remotePeerDescriptor);
89
- try {
90
- logger.trace(`Setting remote descriptor for peer: ${remoteNodeId}`);
91
- this.connection.setRemoteDescription(description, type);
92
- this.remoteDescriptionSet = true;
93
- }
94
- catch {
95
- logger.debug(`Failed to set remote descriptor for peer ${remoteNodeId}`);
96
- }
97
- }
98
- else {
99
- this.doClose(false, `Tried to set description for non-existent connection`);
100
- }
101
- }
102
- addRemoteCandidate(candidate, mid) {
103
- if (this.connection) {
104
- if (this.remoteDescriptionSet) {
105
- const remoteNodeId = (0, identifiers_1.toNodeId)(this.remotePeerDescriptor);
106
- try {
107
- logger.trace(`Setting remote candidate for peer: ${remoteNodeId}`);
108
- this.connection.addRemoteCandidate(candidate, mid);
109
- }
110
- catch {
111
- logger.debug(`Failed to set remote candidate for peer ${remoteNodeId}`);
112
- }
113
- }
114
- else {
115
- // TODO: should queue candidates until remote description is set?
116
- this.doClose(false, `Tried to set candidate before description`);
117
- }
118
- }
119
- else {
120
- this.doClose(false, `Tried to set candidate for non-existent connection`);
121
- }
122
- }
123
- send(data) {
124
- if (this.isOpen()) {
125
- try {
126
- if (this.dataChannel.bufferedAmount() < this.bufferThresholdHigh) {
127
- this.dataChannel.sendMessageBinary(data);
128
- }
129
- else {
130
- this.messageQueue.push(data);
131
- }
132
- }
133
- catch (err) {
134
- const remoteNodeId = (0, identifiers_1.toNodeId)(this.remotePeerDescriptor);
135
- logger.debug('Failed to send binary message to ' + remoteNodeId + err);
136
- }
137
- }
138
- }
139
- async close(gracefulLeave, reason) {
140
- this.doClose(gracefulLeave, reason);
141
- }
142
- doClose(gracefulLeave, reason) {
143
- if (!this.closed) {
144
- clearTimeout(this.earlyTimeout);
145
- const remoteNodeId = (0, identifiers_1.toNodeId)(this.remotePeerDescriptor);
146
- logger.trace(`Closing Node WebRTC Connection to ${remoteNodeId}` + `${(reason !== undefined) ? `, reason: ${reason}` : ''}`);
147
- this.closed = true;
148
- this.emit('disconnected', gracefulLeave, undefined, reason);
149
- this.removeAllListeners();
150
- if (this.dataChannel) {
151
- try {
152
- logger.trace('closing datachannel');
153
- this.dataChannel.close();
154
- }
155
- catch (e) {
156
- logger.trace('dc.close() errored: %s', e);
157
- }
158
- }
159
- if (this.connection) {
160
- try {
161
- this.connection.close();
162
- }
163
- catch (e) {
164
- logger.trace('conn.close() errored: %s', e);
165
- }
166
- }
167
- this.connection = undefined;
168
- this.dataChannel = undefined;
169
- }
170
- }
171
- destroy() {
172
- this.removeAllListeners();
173
- this.doClose(false);
174
- }
175
- setupDataChannel(dataChannel) {
176
- this.dataChannel = dataChannel;
177
- dataChannel.setBufferedAmountLowThreshold(this.bufferThresholdLow);
178
- dataChannel.onOpen(() => {
179
- logger.trace(`dc.onOpened`);
180
- this.onDataChannelOpen();
181
- });
182
- dataChannel.onClosed(() => {
183
- logger.trace(`dc.closed`);
184
- this.doClose(false, 'DataChannel closed');
185
- });
186
- dataChannel.onError((err) => logger.error('error', { err }));
187
- dataChannel.onBufferedAmountLow(() => {
188
- while (this.messageQueue.length > 0 && dataChannel.bufferedAmount() < this.bufferThresholdHigh) {
189
- const data = this.messageQueue.shift();
190
- try {
191
- dataChannel.sendMessageBinary(data);
192
- }
193
- catch (err) {
194
- logger.debug('Failed to send binary message', { err });
195
- }
196
- }
197
- });
198
- dataChannel.onMessage((msg) => {
199
- logger.trace(`dc.onMessage`);
200
- this.emit('data', msg);
201
- });
202
- }
203
- onDataChannelOpen() {
204
- logger.trace(`DataChannel opened for peer ${(0, identifiers_1.toNodeId)(this.remotePeerDescriptor)}`);
205
- this.emit('connected');
206
- }
207
- onStateChange(state) {
208
- logger.trace('onStateChange ' + state);
209
- if (!Object.keys(RtcPeerConnectionStateEnum).filter((s) => isNaN(+s)).includes(state)) {
210
- throw new errors_1.IllegalRtcPeerConnectionState('NodeWebrtcConnection used an unknown state: ' + state);
211
- }
212
- else {
213
- this.lastState = state;
214
- }
215
- if (state === RtcPeerConnectionStateEnum.closed
216
- || state === RtcPeerConnectionStateEnum.disconnected
217
- || state === RtcPeerConnectionStateEnum.failed) {
218
- this.doClose(false);
219
- }
220
- }
221
- isOpen() {
222
- return !this.closed && this.lastState === 'connected' && !!this.dataChannel;
223
- }
224
- setConnectionId(connectionId) {
225
- this.connectionId = connectionId;
226
- }
227
- }
228
- exports.NodeWebrtcConnection = NodeWebrtcConnection;
229
- //# sourceMappingURL=NodeWebrtcConnection.js.map