@nice2dev/game-engine 1.3.15 → 1.3.16

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 (434) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/accessibility/Accessibility.js +152 -165
  3. package/dist/cjs/ai/AI.js +292 -294
  4. package/dist/cjs/ai/BehaviorTree.js +1029 -1113
  5. package/dist/cjs/ai/StateMachine.js +694 -756
  6. package/dist/cjs/animation/Animation.js +232 -241
  7. package/dist/cjs/audio/AudioAdvanced.js +221 -236
  8. package/dist/cjs/audio/AudioBridge.js +441 -435
  9. package/dist/cjs/audio/AudioManager.js +242 -259
  10. package/dist/cjs/build-cloud/BuildOrchestration.js +1059 -1098
  11. package/dist/cjs/build-cloud/GodotBuildCloud.js +641 -670
  12. package/dist/cjs/build-cloud/UnityBuildCloud.js +563 -610
  13. package/dist/cjs/build-cloud/UnrealBuildCloud.js +610 -635
  14. package/dist/cjs/core/EventBus.js +51 -56
  15. package/dist/cjs/core/GameClock.js +62 -66
  16. package/dist/cjs/core/GameConfig.js +72 -79
  17. package/dist/cjs/core/GameLoop.js +80 -89
  18. package/dist/cjs/core/ServiceLocator.js +61 -65
  19. package/dist/cjs/core/Validation.js +72 -82
  20. package/dist/cjs/core/math.js +108 -112
  21. package/dist/cjs/devtools/DevTools.js +542 -563
  22. package/dist/cjs/devtools/DeveloperExperience.js +521 -559
  23. package/dist/cjs/devtools/GameplayAnalytics.js +636 -646
  24. package/dist/cjs/dialogue/DialogueSystem.js +984 -986
  25. package/dist/cjs/docs/DocGenerator.js +339 -364
  26. package/dist/cjs/ecs/World.js +355 -371
  27. package/dist/cjs/editor/AchievementEditor.js +580 -636
  28. package/dist/cjs/editor/AdvancedEditor.js +184 -191
  29. package/dist/cjs/editor/AnimationRetargeting.js +696 -741
  30. package/dist/cjs/editor/AssetBrowser.js +1072 -1160
  31. package/dist/cjs/editor/AssetManager.js +187 -192
  32. package/dist/cjs/editor/ConsolePro.js +971 -1061
  33. package/dist/cjs/editor/CraftingEditor.js +680 -730
  34. package/dist/cjs/editor/DebugTools.js +187 -185
  35. package/dist/cjs/editor/DialogueSystem.js +844 -901
  36. package/dist/cjs/editor/LeaderboardSystem.js +429 -483
  37. package/dist/cjs/editor/NiceGameEditor.js +1903 -1201
  38. package/dist/cjs/editor/PrefabSystem.js +772 -838
  39. package/dist/cjs/editor/ProfilerPanel.js +649 -700
  40. package/dist/cjs/editor/QuestEditor.js +792 -839
  41. package/dist/cjs/editor/ReplaySystem.js +585 -634
  42. package/dist/cjs/editor/SceneEditor.js +176 -200
  43. package/dist/cjs/editor/ScreenshotMode.js +621 -688
  44. package/dist/cjs/editor/ShaderGraph.js +1556 -1582
  45. package/dist/cjs/editor/TimelineEditor.js +715 -778
  46. package/dist/cjs/editor/UndoRedoPro.js +830 -904
  47. package/dist/cjs/editor/VRARMode.js +582 -645
  48. package/dist/cjs/engine/NiceGameEngine.js +141 -164
  49. package/dist/cjs/engine/SaveSystem.js +441 -495
  50. package/dist/cjs/enterprise/Enterprise.js +254 -261
  51. package/dist/cjs/export/BevyExporter.js +927 -967
  52. package/dist/cjs/export/CocosExporter.js +644 -673
  53. package/dist/cjs/export/Construct3Exporter.js +783 -794
  54. package/dist/cjs/export/DefoldExporter.js +1028 -1069
  55. package/dist/cjs/export/GDevelopExporter.js +674 -708
  56. package/dist/cjs/export/GameMakerExporter.js +791 -805
  57. package/dist/cjs/export/GodotExporter.js +1003 -1045
  58. package/dist/cjs/export/MinecraftBedrockExporter.js +573 -578
  59. package/dist/cjs/export/MonoGameExporter.js +1265 -1293
  60. package/dist/cjs/export/Pico8Exporter.js +766 -812
  61. package/dist/cjs/export/PlatformExporter.js +188 -206
  62. package/dist/cjs/export/RPGMakerExporter.js +860 -879
  63. package/dist/cjs/export/RobloxExporter.js +883 -919
  64. package/dist/cjs/export/Solar2DExporter.js +1218 -1256
  65. package/dist/cjs/export/ThreeJSExporter.js +1006 -1073
  66. package/dist/cjs/export/Tic80Exporter.js +1210 -1267
  67. package/dist/cjs/export/UnityExporter.js +1116 -1131
  68. package/dist/cjs/export/UnrealExporter.js +889 -919
  69. package/dist/cjs/export/WebExporter.js +931 -970
  70. package/dist/cjs/export/index.js +42 -65
  71. package/dist/cjs/godot-integration/GodotAssetLibrary.js +659 -692
  72. package/dist/cjs/godot-integration/GodotImport.js +929 -1027
  73. package/dist/cjs/godot-integration/GodotLiveLink.js +915 -945
  74. package/dist/cjs/godot-integration/components/GodotProjectBrowser.js +911 -611
  75. package/dist/cjs/i18n/I18n.js +860 -900
  76. package/dist/cjs/i18n/useTranslation.js +84 -89
  77. package/dist/cjs/import/AsepriteImporter.js +658 -716
  78. package/dist/cjs/import/DragonBonesImporter.js +437 -461
  79. package/dist/cjs/import/GameMakerImporter.js +511 -521
  80. package/dist/cjs/import/GodotSceneImporter.js +788 -822
  81. package/dist/cjs/import/LDtkImporter.js +436 -454
  82. package/dist/cjs/import/Live2DImporter.js +497 -518
  83. package/dist/cjs/import/NdgFormat.js +424 -457
  84. package/dist/cjs/import/OgmoImporter.js +466 -493
  85. package/dist/cjs/import/RPGMakerImporter.js +451 -477
  86. package/dist/cjs/import/SceneImporter.js +378 -423
  87. package/dist/cjs/import/SpineImporter.js +511 -546
  88. package/dist/cjs/import/SpriterImporter.js +590 -613
  89. package/dist/cjs/import/TiledMapImporter.js +811 -846
  90. package/dist/cjs/import/UnitySceneImporter.js +687 -703
  91. package/dist/cjs/import/index.js +206 -251
  92. package/dist/cjs/index.js +275 -278
  93. package/dist/cjs/input/GamepadNavigation.js +185 -205
  94. package/dist/cjs/input/InputManager.js +397 -421
  95. package/dist/cjs/input/useGamepads.js +70 -81
  96. package/dist/cjs/integration/IconSprite.js +129 -256
  97. package/dist/cjs/inventory/InventorySystem.js +920 -995
  98. package/dist/cjs/kids/KidMode.js +997 -1022
  99. package/dist/cjs/kids/KidTools.js +570 -594
  100. package/dist/cjs/monetization/Monetization.js +170 -177
  101. package/dist/cjs/multiplayer/LocalMultiplayer.js +287 -287
  102. package/dist/cjs/multiplayer/MiniGameTypes.js +49 -59
  103. package/dist/cjs/native-engine/AnimationSystem.js +731 -806
  104. package/dist/cjs/native-engine/AssetPipeline.js +454 -515
  105. package/dist/cjs/native-engine/AudioEngine.js +763 -804
  106. package/dist/cjs/native-engine/InputSystem.js +1075 -1145
  107. package/dist/cjs/native-engine/NetworkingSystem.js +733 -793
  108. package/dist/cjs/native-engine/PhysicsEngine.js +583 -607
  109. package/dist/cjs/native-engine/RenderingEngine.js +302 -350
  110. package/dist/cjs/native-engine/SceneGraph.js +769 -808
  111. package/dist/cjs/network/MultiplayerTransport.js +97 -132
  112. package/dist/cjs/network/Networking.js +549 -564
  113. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/AbortController.js +21 -29
  114. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/AccessTokenHttpClient.js +40 -48
  115. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +35 -43
  116. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +10 -15
  117. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Errors.js +103 -135
  118. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +131 -158
  119. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +39 -53
  120. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +5 -8
  121. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +40 -48
  122. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +494 -572
  123. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +826 -953
  124. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +125 -146
  125. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +13 -23
  126. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ILogger.js +11 -25
  127. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ITransport.js +13 -24
  128. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +108 -121
  129. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Loggers.js +10 -14
  130. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +150 -185
  131. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/MessageBuffer.js +158 -196
  132. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +90 -105
  133. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Subject.js +30 -35
  134. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +16 -21
  135. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Utils.js +215 -248
  136. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +135 -157
  137. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +76 -85
  138. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/index.js +24 -27
  139. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/pkg-version.js +3 -4
  140. package/dist/cjs/pathfinding/Pathfinding.js +245 -263
  141. package/dist/cjs/performance/AssetStreaming.js +561 -635
  142. package/dist/cjs/performance/BenchmarkSuite.js +283 -311
  143. package/dist/cjs/performance/DeltaCompression.js +467 -526
  144. package/dist/cjs/performance/DeterministicPhysics.js +450 -498
  145. package/dist/cjs/performance/ECSOptimization.js +644 -695
  146. package/dist/cjs/performance/GameSaveSystem.js +509 -556
  147. package/dist/cjs/performance/HotReload.js +447 -500
  148. package/dist/cjs/performance/InputRecording.js +511 -561
  149. package/dist/cjs/performance/InterestManagement.js +453 -500
  150. package/dist/cjs/performance/LocalizationRuntime.js +376 -423
  151. package/dist/cjs/performance/MemoryManagement.js +410 -470
  152. package/dist/cjs/performance/ModSupport.js +445 -496
  153. package/dist/cjs/performance/MultiThreadedPhysics.js +400 -443
  154. package/dist/cjs/performance/NetworkPrediction.js +424 -482
  155. package/dist/cjs/performance/ObjectPooling.js +569 -617
  156. package/dist/cjs/performance/Performance.js +174 -190
  157. package/dist/cjs/performance/PerformanceAdvanced.js +614 -637
  158. package/dist/cjs/performance/WebGPURenderer.js +656 -683
  159. package/dist/cjs/physics/PhysicsAdvanced.js +345 -379
  160. package/dist/cjs/physics/PhysicsEngine2D.js +391 -427
  161. package/dist/cjs/plugins/PluginSDK.js +432 -466
  162. package/dist/cjs/plugins/PluginTestKit.js +307 -330
  163. package/dist/cjs/procedural/Procedural.js +243 -254
  164. package/dist/cjs/procedural/WorldBuilding.js +297 -314
  165. package/dist/cjs/quest/QuestSystem.js +975 -932
  166. package/dist/cjs/release/MobileExport.js +157 -163
  167. package/dist/cjs/release/Release.js +225 -238
  168. package/dist/cjs/rendering/Camera2D.js +121 -124
  169. package/dist/cjs/rendering/Renderer2D.js +321 -335
  170. package/dist/cjs/rendering/WebGPURenderPipeline.js +632 -651
  171. package/dist/cjs/runtime3d/Runtime3D.js +359 -378
  172. package/dist/cjs/runtime3d/SceneEditor3D.js +252 -263
  173. package/dist/cjs/scene/SceneManager.js +177 -193
  174. package/dist/cjs/scripting/GraphToAST.js +574 -547
  175. package/dist/cjs/scripting/LanguageExporter.js +254 -279
  176. package/dist/cjs/scripting/NodeGraph.js +546 -570
  177. package/dist/cjs/scripting/ScriptAST.js +31 -39
  178. package/dist/cjs/scripting/VisualScripting2.js +1016 -1065
  179. package/dist/cjs/scripting/exporters/CSharpExporter.js +464 -496
  180. package/dist/cjs/scripting/exporters/GDScriptExporter.js +390 -442
  181. package/dist/cjs/scripting/exporters/LuaExporter.js +406 -447
  182. package/dist/cjs/scripting/exporters/PythonExporter.js +484 -549
  183. package/dist/cjs/scripting/exporters/RustExporter.js +459 -512
  184. package/dist/cjs/scripting/exporters/TypeScriptExporter.js +505 -556
  185. package/dist/cjs/social/Social.js +72 -80
  186. package/dist/cjs/systems/LightingSystem.js +844 -931
  187. package/dist/cjs/systems/ParticleSystem2.js +1447 -1451
  188. package/dist/cjs/systems/PhysicsDebugSystem.js +1070 -1141
  189. package/dist/cjs/systems/TerrainSystem.js +985 -1098
  190. package/dist/cjs/templates/ActionTemplates.js +296 -309
  191. package/dist/cjs/templates/FightingTemplate.js +417 -463
  192. package/dist/cjs/templates/MetroidvaniaTemplate.js +353 -405
  193. package/dist/cjs/templates/PartyTemplates.js +190 -202
  194. package/dist/cjs/templates/PuzzleTemplates.js +245 -261
  195. package/dist/cjs/templates/RPGTemplates.js +160 -178
  196. package/dist/cjs/templates/SportsTemplates.js +237 -250
  197. package/dist/cjs/templates/StrategyTemplates.js +143 -153
  198. package/dist/cjs/templates/SurvivalTemplate.js +336 -380
  199. package/dist/cjs/templates/WaveDefense.js +499 -526
  200. package/dist/cjs/tilemap/Tilemap.js +207 -214
  201. package/dist/cjs/tutorials/TutorialBranching.js +396 -417
  202. package/dist/cjs/tutorials/TutorialEngine.js +888 -931
  203. package/dist/cjs/tutorials/TutorialOverlay.js +602 -640
  204. package/dist/cjs/tutorials/content/Tutorials_T05_T08.js +787 -809
  205. package/dist/cjs/tutorials/content/Tutorials_T09_T11.js +736 -756
  206. package/dist/cjs/tutorials/content/Tutorials_T12_T15.js +754 -778
  207. package/dist/cjs/ui/GameUI.js +295 -312
  208. package/dist/cjs/unity-integration/UnityAssetStore.js +700 -741
  209. package/dist/cjs/unity-integration/UnityImport.js +1066 -1176
  210. package/dist/cjs/unity-integration/UnityLiveLink.js +934 -981
  211. package/dist/cjs/unity-integration/components/UnityAssetStoreBrowser.js +1233 -757
  212. package/dist/cjs/unity-integration/components/UnityProjectBrowser.js +1240 -768
  213. package/dist/cjs/unreal-integration/UnrealImport.js +391 -412
  214. package/dist/cjs/unreal-integration/UnrealLiveLink.js +1102 -1137
  215. package/dist/cjs/unreal-integration/UnrealMarketplace.js +436 -473
  216. package/dist/cjs/unreal-integration/components/UnrealProjectBrowser.js +1150 -767
  217. package/dist/cjs/xr/ARVR.js +167 -175
  218. package/dist/esm/accessibility/Accessibility.js +160 -164
  219. package/dist/esm/ai/AI.js +310 -293
  220. package/dist/esm/ai/BehaviorTree.js +1057 -1112
  221. package/dist/esm/ai/StateMachine.js +709 -755
  222. package/dist/esm/animation/Animation.js +237 -240
  223. package/dist/esm/audio/AudioAdvanced.js +239 -235
  224. package/dist/esm/audio/AudioBridge.js +448 -434
  225. package/dist/esm/audio/AudioManager.js +243 -258
  226. package/dist/esm/build-cloud/BuildOrchestration.js +1071 -1097
  227. package/dist/esm/build-cloud/GodotBuildCloud.js +647 -669
  228. package/dist/esm/build-cloud/UnityBuildCloud.js +571 -609
  229. package/dist/esm/build-cloud/UnrealBuildCloud.js +615 -634
  230. package/dist/esm/core/EventBus.js +52 -55
  231. package/dist/esm/core/GameClock.js +63 -65
  232. package/dist/esm/core/GameConfig.js +77 -78
  233. package/dist/esm/core/GameLoop.js +81 -88
  234. package/dist/esm/core/ServiceLocator.js +63 -64
  235. package/dist/esm/core/Validation.js +82 -81
  236. package/dist/esm/core/math.js +109 -111
  237. package/dist/esm/devtools/DevTools.js +546 -562
  238. package/dist/esm/devtools/DeveloperExperience.js +535 -558
  239. package/dist/esm/devtools/GameplayAnalytics.js +647 -645
  240. package/dist/esm/dialogue/DialogueSystem.js +998 -985
  241. package/dist/esm/docs/DocGenerator.js +342 -363
  242. package/dist/esm/ecs/World.js +358 -370
  243. package/dist/esm/editor/AchievementEditor.js +584 -635
  244. package/dist/esm/editor/AdvancedEditor.js +191 -190
  245. package/dist/esm/editor/AnimationRetargeting.js +700 -740
  246. package/dist/esm/editor/AssetBrowser.js +1078 -1159
  247. package/dist/esm/editor/AssetManager.js +188 -191
  248. package/dist/esm/editor/ConsolePro.js +977 -1060
  249. package/dist/esm/editor/CraftingEditor.js +684 -729
  250. package/dist/esm/editor/DebugTools.js +194 -184
  251. package/dist/esm/editor/DialogueSystem.js +849 -900
  252. package/dist/esm/editor/LeaderboardSystem.js +433 -482
  253. package/dist/esm/editor/NiceGameEditor.js +1908 -1200
  254. package/dist/esm/editor/PrefabSystem.js +777 -837
  255. package/dist/esm/editor/ProfilerPanel.js +654 -699
  256. package/dist/esm/editor/QuestEditor.js +795 -838
  257. package/dist/esm/editor/ReplaySystem.js +591 -633
  258. package/dist/esm/editor/SceneEditor.js +189 -199
  259. package/dist/esm/editor/ScreenshotMode.js +628 -687
  260. package/dist/esm/editor/ShaderGraph.js +1565 -1581
  261. package/dist/esm/editor/TimelineEditor.js +733 -777
  262. package/dist/esm/editor/UndoRedoPro.js +835 -903
  263. package/dist/esm/editor/VRARMode.js +586 -644
  264. package/dist/esm/engine/NiceGameEngine.js +142 -163
  265. package/dist/esm/engine/SaveSystem.js +447 -494
  266. package/dist/esm/enterprise/Enterprise.js +265 -260
  267. package/dist/esm/export/BevyExporter.js +929 -966
  268. package/dist/esm/export/CocosExporter.js +646 -672
  269. package/dist/esm/export/Construct3Exporter.js +785 -793
  270. package/dist/esm/export/DefoldExporter.js +1030 -1068
  271. package/dist/esm/export/GDevelopExporter.js +676 -707
  272. package/dist/esm/export/GameMakerExporter.js +793 -804
  273. package/dist/esm/export/GodotExporter.js +1004 -1044
  274. package/dist/esm/export/MinecraftBedrockExporter.js +575 -577
  275. package/dist/esm/export/MonoGameExporter.js +1267 -1292
  276. package/dist/esm/export/Pico8Exporter.js +768 -811
  277. package/dist/esm/export/PlatformExporter.js +193 -205
  278. package/dist/esm/export/RPGMakerExporter.js +862 -878
  279. package/dist/esm/export/RobloxExporter.js +885 -918
  280. package/dist/esm/export/Solar2DExporter.js +1220 -1255
  281. package/dist/esm/export/ThreeJSExporter.js +1007 -1072
  282. package/dist/esm/export/Tic80Exporter.js +1212 -1266
  283. package/dist/esm/export/UnityExporter.js +1117 -1130
  284. package/dist/esm/export/UnrealExporter.js +891 -918
  285. package/dist/esm/export/WebExporter.js +933 -969
  286. package/dist/esm/export/index.js +86 -71
  287. package/dist/esm/godot-integration/GodotAssetLibrary.js +663 -691
  288. package/dist/esm/godot-integration/GodotImport.js +935 -1026
  289. package/dist/esm/godot-integration/GodotLiveLink.js +918 -944
  290. package/dist/esm/godot-integration/components/GodotProjectBrowser.js +912 -610
  291. package/dist/esm/i18n/I18n.js +871 -899
  292. package/dist/esm/i18n/useTranslation.js +88 -88
  293. package/dist/esm/import/AsepriteImporter.js +637 -715
  294. package/dist/esm/import/DragonBonesImporter.js +417 -460
  295. package/dist/esm/import/GameMakerImporter.js +491 -520
  296. package/dist/esm/import/GodotSceneImporter.js +767 -821
  297. package/dist/esm/import/LDtkImporter.js +415 -453
  298. package/dist/esm/import/Live2DImporter.js +477 -517
  299. package/dist/esm/import/NdgFormat.js +410 -456
  300. package/dist/esm/import/OgmoImporter.js +446 -492
  301. package/dist/esm/import/RPGMakerImporter.js +431 -476
  302. package/dist/esm/import/SceneImporter.js +385 -422
  303. package/dist/esm/import/SpineImporter.js +491 -545
  304. package/dist/esm/import/SpriterImporter.js +570 -612
  305. package/dist/esm/import/TiledMapImporter.js +790 -845
  306. package/dist/esm/import/UnitySceneImporter.js +666 -702
  307. package/dist/esm/import/index.js +247 -258
  308. package/dist/esm/index.js +1332 -188
  309. package/dist/esm/input/GamepadNavigation.js +187 -204
  310. package/dist/esm/input/InputManager.js +401 -420
  311. package/dist/esm/input/useGamepads.js +72 -80
  312. package/dist/esm/integration/IconSprite.js +143 -255
  313. package/dist/esm/inventory/InventorySystem.js +925 -994
  314. package/dist/esm/kids/KidMode.js +1003 -1021
  315. package/dist/esm/kids/KidTools.js +573 -593
  316. package/dist/esm/monetization/Monetization.js +180 -176
  317. package/dist/esm/multiplayer/LocalMultiplayer.js +290 -286
  318. package/dist/esm/multiplayer/MiniGameTypes.js +58 -58
  319. package/dist/esm/native-engine/AnimationSystem.js +735 -805
  320. package/dist/esm/native-engine/AssetPipeline.js +456 -514
  321. package/dist/esm/native-engine/AudioEngine.js +765 -803
  322. package/dist/esm/native-engine/InputSystem.js +1079 -1144
  323. package/dist/esm/native-engine/NetworkingSystem.js +740 -792
  324. package/dist/esm/native-engine/PhysicsEngine.js +585 -606
  325. package/dist/esm/native-engine/RenderingEngine.js +304 -349
  326. package/dist/esm/native-engine/SceneGraph.js +773 -807
  327. package/dist/esm/network/MultiplayerTransport.js +99 -131
  328. package/dist/esm/network/Networking.js +556 -563
  329. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/AbortController.js +22 -28
  330. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/AccessTokenHttpClient.js +41 -47
  331. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +36 -42
  332. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +11 -14
  333. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Errors.js +111 -134
  334. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +132 -157
  335. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +40 -52
  336. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +6 -7
  337. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +42 -47
  338. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +496 -571
  339. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +828 -952
  340. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +126 -145
  341. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +14 -23
  342. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ILogger.js +12 -25
  343. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ITransport.js +15 -24
  344. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +109 -120
  345. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Loggers.js +11 -13
  346. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +151 -184
  347. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/MessageBuffer.js +159 -195
  348. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +91 -104
  349. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Subject.js +31 -34
  350. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +17 -20
  351. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Utils.js +230 -248
  352. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +136 -156
  353. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +77 -84
  354. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/index.js +31 -12
  355. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/pkg-version.js +4 -3
  356. package/dist/esm/pathfinding/Pathfinding.js +249 -262
  357. package/dist/esm/performance/AssetStreaming.js +567 -634
  358. package/dist/esm/performance/BenchmarkSuite.js +285 -310
  359. package/dist/esm/performance/DeltaCompression.js +478 -525
  360. package/dist/esm/performance/DeterministicPhysics.js +479 -497
  361. package/dist/esm/performance/ECSOptimization.js +653 -694
  362. package/dist/esm/performance/GameSaveSystem.js +515 -555
  363. package/dist/esm/performance/HotReload.js +454 -499
  364. package/dist/esm/performance/InputRecording.js +520 -560
  365. package/dist/esm/performance/InterestManagement.js +460 -499
  366. package/dist/esm/performance/LocalizationRuntime.js +382 -422
  367. package/dist/esm/performance/MemoryManagement.js +415 -469
  368. package/dist/esm/performance/ModSupport.js +455 -495
  369. package/dist/esm/performance/MultiThreadedPhysics.js +408 -442
  370. package/dist/esm/performance/NetworkPrediction.js +436 -481
  371. package/dist/esm/performance/ObjectPooling.js +582 -616
  372. package/dist/esm/performance/Performance.js +182 -189
  373. package/dist/esm/performance/PerformanceAdvanced.js +621 -636
  374. package/dist/esm/performance/WebGPURenderer.js +660 -682
  375. package/dist/esm/physics/PhysicsAdvanced.js +359 -378
  376. package/dist/esm/physics/PhysicsEngine2D.js +393 -426
  377. package/dist/esm/plugins/PluginSDK.js +435 -465
  378. package/dist/esm/plugins/PluginTestKit.js +315 -329
  379. package/dist/esm/procedural/Procedural.js +248 -253
  380. package/dist/esm/procedural/WorldBuilding.js +316 -313
  381. package/dist/esm/quest/QuestSystem.js +982 -931
  382. package/dist/esm/release/MobileExport.js +163 -162
  383. package/dist/esm/release/Release.js +234 -237
  384. package/dist/esm/rendering/Camera2D.js +122 -123
  385. package/dist/esm/rendering/Renderer2D.js +323 -334
  386. package/dist/esm/rendering/WebGPURenderPipeline.js +647 -650
  387. package/dist/esm/runtime3d/Runtime3D.js +368 -377
  388. package/dist/esm/runtime3d/SceneEditor3D.js +268 -262
  389. package/dist/esm/scene/SceneManager.js +178 -192
  390. package/dist/esm/scripting/GraphToAST.js +576 -546
  391. package/dist/esm/scripting/LanguageExporter.js +263 -278
  392. package/dist/esm/scripting/NodeGraph.js +550 -569
  393. package/dist/esm/scripting/ScriptAST.js +45 -38
  394. package/dist/esm/scripting/VisualScripting2.js +1025 -1064
  395. package/dist/esm/scripting/exporters/CSharpExporter.js +465 -495
  396. package/dist/esm/scripting/exporters/GDScriptExporter.js +391 -441
  397. package/dist/esm/scripting/exporters/LuaExporter.js +407 -446
  398. package/dist/esm/scripting/exporters/PythonExporter.js +485 -548
  399. package/dist/esm/scripting/exporters/RustExporter.js +460 -511
  400. package/dist/esm/scripting/exporters/TypeScriptExporter.js +506 -555
  401. package/dist/esm/social/Social.js +77 -79
  402. package/dist/esm/systems/LightingSystem.js +855 -930
  403. package/dist/esm/systems/ParticleSystem2.js +1453 -1450
  404. package/dist/esm/systems/PhysicsDebugSystem.js +1078 -1140
  405. package/dist/esm/systems/TerrainSystem.js +996 -1097
  406. package/dist/esm/templates/ActionTemplates.js +307 -308
  407. package/dist/esm/templates/FightingTemplate.js +439 -462
  408. package/dist/esm/templates/MetroidvaniaTemplate.js +391 -404
  409. package/dist/esm/templates/PartyTemplates.js +206 -201
  410. package/dist/esm/templates/PuzzleTemplates.js +260 -260
  411. package/dist/esm/templates/RPGTemplates.js +172 -177
  412. package/dist/esm/templates/SportsTemplates.js +251 -249
  413. package/dist/esm/templates/StrategyTemplates.js +158 -152
  414. package/dist/esm/templates/SurvivalTemplate.js +367 -379
  415. package/dist/esm/templates/WaveDefense.js +501 -525
  416. package/dist/esm/tilemap/Tilemap.js +209 -213
  417. package/dist/esm/tutorials/TutorialBranching.js +399 -416
  418. package/dist/esm/tutorials/TutorialEngine.js +893 -930
  419. package/dist/esm/tutorials/TutorialOverlay.js +603 -639
  420. package/dist/esm/tutorials/content/Tutorials_T05_T08.js +792 -808
  421. package/dist/esm/tutorials/content/Tutorials_T09_T11.js +740 -755
  422. package/dist/esm/tutorials/content/Tutorials_T12_T15.js +759 -777
  423. package/dist/esm/ui/GameUI.js +296 -311
  424. package/dist/esm/unity-integration/UnityAssetStore.js +704 -740
  425. package/dist/esm/unity-integration/UnityImport.js +1071 -1175
  426. package/dist/esm/unity-integration/UnityLiveLink.js +938 -980
  427. package/dist/esm/unity-integration/components/UnityAssetStoreBrowser.js +1234 -756
  428. package/dist/esm/unity-integration/components/UnityProjectBrowser.js +1241 -767
  429. package/dist/esm/unreal-integration/UnrealImport.js +395 -411
  430. package/dist/esm/unreal-integration/UnrealLiveLink.js +1105 -1136
  431. package/dist/esm/unreal-integration/UnrealMarketplace.js +442 -472
  432. package/dist/esm/unreal-integration/components/UnrealProjectBrowser.js +1151 -766
  433. package/dist/esm/xr/ARVR.js +181 -174
  434. package/package.json +7 -12
@@ -1,572 +1,497 @@
1
- import { AccessTokenHttpClient } from './AccessTokenHttpClient.js';
2
- import { DefaultHttpClient } from './DefaultHttpClient.js';
3
- import { AbortError, FailedToNegotiateWithServerError, HttpError, FailedToStartTransportError, AggregateErrors, UnsupportedTransportError, DisabledTransportError } from './Errors.js';
4
- import { LogLevel } from './ILogger.js';
5
- import { TransferFormat, HttpTransportType } from './ITransport.js';
6
- import { LongPollingTransport } from './LongPollingTransport.js';
7
- import { ServerSentEventsTransport } from './ServerSentEventsTransport.js';
8
- import { Arg, createLogger, Platform, getUserAgentHeader } from './Utils.js';
9
- import { WebSocketTransport } from './WebSocketTransport.js';
10
-
11
- // Licensed to the .NET Foundation under one or more agreements.
12
- // The .NET Foundation licenses this file to you under the MIT license.
13
- const MAX_REDIRECTS = 100;
14
- /** @private */
15
- class HttpConnection {
16
- constructor(url, options = {}) {
17
- this._stopPromiseResolver = () => { };
18
- this.features = {};
19
- this._negotiateVersion = 1;
20
- Arg.isRequired(url, "url");
21
- this._logger = createLogger(options.logger);
22
- this.baseUrl = this._resolveUrl(url);
23
- options = options || {};
24
- options.logMessageContent = options.logMessageContent === undefined ? false : options.logMessageContent;
25
- if (typeof options.withCredentials === "boolean" || options.withCredentials === undefined) {
26
- options.withCredentials = options.withCredentials === undefined ? true : options.withCredentials;
27
- }
28
- else {
29
- throw new Error("withCredentials option was not a 'boolean' or 'undefined' value");
30
- }
31
- options.timeout = options.timeout === undefined ? 100 * 1000 : options.timeout;
32
- let webSocketModule = null;
33
- let eventSourceModule = null;
34
- if (Platform.isNode && typeof require !== "undefined") {
35
- // In order to ignore the dynamic require in webpack builds we need to do this magic
36
- // @ts-ignore: TS doesn't know about these names
37
- const requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
38
- webSocketModule = requireFunc("ws");
39
- eventSourceModule = requireFunc("eventsource");
40
- }
41
- if (!Platform.isNode && typeof WebSocket !== "undefined" && !options.WebSocket) {
42
- options.WebSocket = WebSocket;
43
- }
44
- else if (Platform.isNode && !options.WebSocket) {
45
- if (webSocketModule) {
46
- options.WebSocket = webSocketModule;
47
- }
48
- }
49
- if (!Platform.isNode && typeof EventSource !== "undefined" && !options.EventSource) {
50
- options.EventSource = EventSource;
51
- }
52
- else if (Platform.isNode && !options.EventSource) {
53
- if (typeof eventSourceModule !== "undefined") {
54
- options.EventSource = eventSourceModule;
55
- }
56
- }
57
- this._httpClient = new AccessTokenHttpClient(options.httpClient || new DefaultHttpClient(this._logger), options.accessTokenFactory);
58
- this._connectionState = "Disconnected" /* ConnectionState.Disconnected */;
59
- this._connectionStarted = false;
60
- this._options = options;
61
- this.onreceive = null;
62
- this.onclose = null;
63
- }
64
- async start(transferFormat) {
65
- transferFormat = transferFormat || TransferFormat.Binary;
66
- Arg.isIn(transferFormat, TransferFormat, "transferFormat");
67
- this._logger.log(LogLevel.Debug, `Starting connection with transfer format '${TransferFormat[transferFormat]}'.`);
68
- if (this._connectionState !== "Disconnected" /* ConnectionState.Disconnected */) {
69
- return Promise.reject(new Error("Cannot start an HttpConnection that is not in the 'Disconnected' state."));
70
- }
71
- this._connectionState = "Connecting" /* ConnectionState.Connecting */;
72
- this._startInternalPromise = this._startInternal(transferFormat);
73
- await this._startInternalPromise;
74
- // The TypeScript compiler thinks that connectionState must be Connecting here. The TypeScript compiler is wrong.
75
- if (this._connectionState === "Disconnecting" /* ConnectionState.Disconnecting */) {
76
- // stop() was called and transitioned the client into the Disconnecting state.
77
- const message = "Failed to start the HttpConnection before stop() was called.";
78
- this._logger.log(LogLevel.Error, message);
79
- // We cannot await stopPromise inside startInternal since stopInternal awaits the startInternalPromise.
80
- await this._stopPromise;
81
- return Promise.reject(new AbortError(message));
82
- }
83
- else if (this._connectionState !== "Connected" /* ConnectionState.Connected */) {
84
- // stop() was called and transitioned the client into the Disconnecting state.
85
- const message = "HttpConnection.startInternal completed gracefully but didn't enter the connection into the connected state!";
86
- this._logger.log(LogLevel.Error, message);
87
- return Promise.reject(new AbortError(message));
88
- }
89
- this._connectionStarted = true;
90
- }
91
- send(data) {
92
- if (this._connectionState !== "Connected" /* ConnectionState.Connected */) {
93
- return Promise.reject(new Error("Cannot send data if the connection is not in the 'Connected' State."));
94
- }
95
- if (!this._sendQueue) {
96
- this._sendQueue = new TransportSendQueue(this.transport);
97
- }
98
- // Transport will not be null if state is connected
99
- return this._sendQueue.send(data);
100
- }
101
- async stop(error) {
102
- if (this._connectionState === "Disconnected" /* ConnectionState.Disconnected */) {
103
- this._logger.log(LogLevel.Debug, `Call to HttpConnection.stop(${error}) ignored because the connection is already in the disconnected state.`);
104
- return Promise.resolve();
105
- }
106
- if (this._connectionState === "Disconnecting" /* ConnectionState.Disconnecting */) {
107
- this._logger.log(LogLevel.Debug, `Call to HttpConnection.stop(${error}) ignored because the connection is already in the disconnecting state.`);
108
- return this._stopPromise;
109
- }
110
- this._connectionState = "Disconnecting" /* ConnectionState.Disconnecting */;
111
- this._stopPromise = new Promise((resolve) => {
112
- // Don't complete stop() until stopConnection() completes.
113
- this._stopPromiseResolver = resolve;
114
- });
115
- // stopInternal should never throw so just observe it.
116
- await this._stopInternal(error);
117
- await this._stopPromise;
118
- }
119
- async _stopInternal(error) {
120
- // Set error as soon as possible otherwise there is a race between
121
- // the transport closing and providing an error and the error from a close message
122
- // We would prefer the close message error.
123
- this._stopError = error;
124
- try {
125
- await this._startInternalPromise;
126
- }
127
- catch (e) {
128
- // This exception is returned to the user as a rejected Promise from the start method.
129
- }
130
- // The transport's onclose will trigger stopConnection which will run our onclose event.
131
- // The transport should always be set if currently connected. If it wasn't set, it's likely because
132
- // stop was called during start() and start() failed.
133
- if (this.transport) {
134
- try {
135
- await this.transport.stop();
136
- }
137
- catch (e) {
138
- this._logger.log(LogLevel.Error, `HttpConnection.transport.stop() threw error '${e}'.`);
139
- this._stopConnection();
140
- }
141
- this.transport = undefined;
142
- }
143
- else {
144
- this._logger.log(LogLevel.Debug, "HttpConnection.transport is undefined in HttpConnection.stop() because start() failed.");
145
- }
146
- }
147
- async _startInternal(transferFormat) {
148
- // Store the original base url and the access token factory since they may change
149
- // as part of negotiating
150
- let url = this.baseUrl;
151
- this._accessTokenFactory = this._options.accessTokenFactory;
152
- this._httpClient._accessTokenFactory = this._accessTokenFactory;
153
- try {
154
- if (this._options.skipNegotiation) {
155
- if (this._options.transport === HttpTransportType.WebSockets) {
156
- // No need to add a connection ID in this case
157
- this.transport = this._constructTransport(HttpTransportType.WebSockets);
158
- // We should just call connect directly in this case.
159
- // No fallback or negotiate in this case.
160
- await this._startTransport(url, transferFormat);
161
- }
162
- else {
163
- throw new Error("Negotiation can only be skipped when using the WebSocket transport directly.");
164
- }
165
- }
166
- else {
167
- let negotiateResponse = null;
168
- let redirects = 0;
169
- do {
170
- negotiateResponse = await this._getNegotiationResponse(url);
171
- // the user tries to stop the connection when it is being started
172
- if (this._connectionState === "Disconnecting" /* ConnectionState.Disconnecting */ || this._connectionState === "Disconnected" /* ConnectionState.Disconnected */) {
173
- throw new AbortError("The connection was stopped during negotiation.");
174
- }
175
- if (negotiateResponse.error) {
176
- throw new Error(negotiateResponse.error);
177
- }
178
- if (negotiateResponse.ProtocolVersion) {
179
- throw new Error("Detected a connection attempt to an ASP.NET SignalR Server. This client only supports connecting to an ASP.NET Core SignalR Server. See https://aka.ms/signalr-core-differences for details.");
180
- }
181
- if (negotiateResponse.url) {
182
- url = negotiateResponse.url;
183
- }
184
- if (negotiateResponse.accessToken) {
185
- // Replace the current access token factory with one that uses
186
- // the returned access token
187
- const accessToken = negotiateResponse.accessToken;
188
- this._accessTokenFactory = () => accessToken;
189
- // set the factory to undefined so the AccessTokenHttpClient won't retry with the same token, since we know it won't change until a connection restart
190
- this._httpClient._accessToken = accessToken;
191
- this._httpClient._accessTokenFactory = undefined;
192
- }
193
- redirects++;
194
- } while (negotiateResponse.url && redirects < MAX_REDIRECTS);
195
- if (redirects === MAX_REDIRECTS && negotiateResponse.url) {
196
- throw new Error("Negotiate redirection limit exceeded.");
197
- }
198
- await this._createTransport(url, this._options.transport, negotiateResponse, transferFormat);
199
- }
200
- if (this.transport instanceof LongPollingTransport) {
201
- this.features.inherentKeepAlive = true;
202
- }
203
- if (this._connectionState === "Connecting" /* ConnectionState.Connecting */) {
204
- // Ensure the connection transitions to the connected state prior to completing this.startInternalPromise.
205
- // start() will handle the case when stop was called and startInternal exits still in the disconnecting state.
206
- this._logger.log(LogLevel.Debug, "The HttpConnection connected successfully.");
207
- this._connectionState = "Connected" /* ConnectionState.Connected */;
208
- }
209
- // stop() is waiting on us via this.startInternalPromise so keep this.transport around so it can clean up.
210
- // This is the only case startInternal can exit in neither the connected nor disconnected state because stopConnection()
211
- // will transition to the disconnected state. start() will wait for the transition using the stopPromise.
212
- }
213
- catch (e) {
214
- this._logger.log(LogLevel.Error, "Failed to start the connection: " + e);
215
- this._connectionState = "Disconnected" /* ConnectionState.Disconnected */;
216
- this.transport = undefined;
217
- // if start fails, any active calls to stop assume that start will complete the stop promise
218
- this._stopPromiseResolver();
219
- return Promise.reject(e);
220
- }
221
- }
222
- async _getNegotiationResponse(url) {
223
- const headers = {};
224
- const [name, value] = getUserAgentHeader();
225
- headers[name] = value;
226
- const negotiateUrl = this._resolveNegotiateUrl(url);
227
- this._logger.log(LogLevel.Debug, `Sending negotiation request: ${negotiateUrl}.`);
228
- try {
229
- const response = await this._httpClient.post(negotiateUrl, {
230
- content: "",
231
- headers: { ...headers, ...this._options.headers },
232
- timeout: this._options.timeout,
233
- withCredentials: this._options.withCredentials,
234
- });
235
- if (response.statusCode !== 200) {
236
- return Promise.reject(new Error(`Unexpected status code returned from negotiate '${response.statusCode}'`));
237
- }
238
- const negotiateResponse = JSON.parse(response.content);
239
- if (!negotiateResponse.negotiateVersion || negotiateResponse.negotiateVersion < 1) {
240
- // Negotiate version 0 doesn't use connectionToken
241
- // So we set it equal to connectionId so all our logic can use connectionToken without being aware of the negotiate version
242
- negotiateResponse.connectionToken = negotiateResponse.connectionId;
243
- }
244
- if (negotiateResponse.useStatefulReconnect && this._options._useStatefulReconnect !== true) {
245
- return Promise.reject(new FailedToNegotiateWithServerError("Client didn't negotiate Stateful Reconnect but the server did."));
246
- }
247
- return negotiateResponse;
248
- }
249
- catch (e) {
250
- let errorMessage = "Failed to complete negotiation with the server: " + e;
251
- if (e instanceof HttpError) {
252
- if (e.statusCode === 404) {
253
- errorMessage = errorMessage + " Either this is not a SignalR endpoint or there is a proxy blocking the connection.";
254
- }
255
- }
256
- this._logger.log(LogLevel.Error, errorMessage);
257
- return Promise.reject(new FailedToNegotiateWithServerError(errorMessage));
258
- }
259
- }
260
- _createConnectUrl(url, connectionToken) {
261
- if (!connectionToken) {
262
- return url;
263
- }
264
- return url + (url.indexOf("?") === -1 ? "?" : "&") + `id=${connectionToken}`;
265
- }
266
- async _createTransport(url, requestedTransport, negotiateResponse, requestedTransferFormat) {
267
- let connectUrl = this._createConnectUrl(url, negotiateResponse.connectionToken);
268
- if (this._isITransport(requestedTransport)) {
269
- this._logger.log(LogLevel.Debug, "Connection was provided an instance of ITransport, using that directly.");
270
- this.transport = requestedTransport;
271
- await this._startTransport(connectUrl, requestedTransferFormat);
272
- this.connectionId = negotiateResponse.connectionId;
273
- return;
274
- }
275
- const transportExceptions = [];
276
- const transports = negotiateResponse.availableTransports || [];
277
- let negotiate = negotiateResponse;
278
- for (const endpoint of transports) {
279
- const transportOrError = this._resolveTransportOrError(endpoint, requestedTransport, requestedTransferFormat, (negotiate === null || negotiate === void 0 ? void 0 : negotiate.useStatefulReconnect) === true);
280
- if (transportOrError instanceof Error) {
281
- // Store the error and continue, we don't want to cause a re-negotiate in these cases
282
- transportExceptions.push(`${endpoint.transport} failed:`);
283
- transportExceptions.push(transportOrError);
284
- }
285
- else if (this._isITransport(transportOrError)) {
286
- this.transport = transportOrError;
287
- if (!negotiate) {
288
- try {
289
- negotiate = await this._getNegotiationResponse(url);
290
- }
291
- catch (ex) {
292
- return Promise.reject(ex);
293
- }
294
- connectUrl = this._createConnectUrl(url, negotiate.connectionToken);
295
- }
296
- try {
297
- await this._startTransport(connectUrl, requestedTransferFormat);
298
- this.connectionId = negotiate.connectionId;
299
- return;
300
- }
301
- catch (ex) {
302
- this._logger.log(LogLevel.Error, `Failed to start the transport '${endpoint.transport}': ${ex}`);
303
- negotiate = undefined;
304
- transportExceptions.push(new FailedToStartTransportError(`${endpoint.transport} failed: ${ex}`, HttpTransportType[endpoint.transport]));
305
- if (this._connectionState !== "Connecting" /* ConnectionState.Connecting */) {
306
- const message = "Failed to select transport before stop() was called.";
307
- this._logger.log(LogLevel.Debug, message);
308
- return Promise.reject(new AbortError(message));
309
- }
310
- }
311
- }
312
- }
313
- if (transportExceptions.length > 0) {
314
- return Promise.reject(new AggregateErrors(`Unable to connect to the server with any of the available transports. ${transportExceptions.join(" ")}`, transportExceptions));
315
- }
316
- return Promise.reject(new Error("None of the transports supported by the client are supported by the server."));
317
- }
318
- _constructTransport(transport) {
319
- switch (transport) {
320
- case HttpTransportType.WebSockets:
321
- if (!this._options.WebSocket) {
322
- throw new Error("'WebSocket' is not supported in your environment.");
323
- }
324
- return new WebSocketTransport(this._httpClient, this._accessTokenFactory, this._logger, this._options.logMessageContent, this._options.WebSocket, this._options.headers || {});
325
- case HttpTransportType.ServerSentEvents:
326
- if (!this._options.EventSource) {
327
- throw new Error("'EventSource' is not supported in your environment.");
328
- }
329
- return new ServerSentEventsTransport(this._httpClient, this._httpClient._accessToken, this._logger, this._options);
330
- case HttpTransportType.LongPolling:
331
- return new LongPollingTransport(this._httpClient, this._logger, this._options);
332
- default:
333
- throw new Error(`Unknown transport: ${transport}.`);
334
- }
335
- }
336
- _startTransport(url, transferFormat) {
337
- this.transport.onreceive = this.onreceive;
338
- if (this.features.reconnect) {
339
- this.transport.onclose = async (e) => {
340
- let callStop = false;
341
- if (this.features.reconnect) {
342
- try {
343
- this.features.disconnected();
344
- await this.transport.connect(url, transferFormat);
345
- await this.features.resend();
346
- }
347
- catch {
348
- callStop = true;
349
- }
350
- }
351
- else {
352
- this._stopConnection(e);
353
- return;
354
- }
355
- if (callStop) {
356
- this._stopConnection(e);
357
- }
358
- };
359
- }
360
- else {
361
- this.transport.onclose = (e) => this._stopConnection(e);
362
- }
363
- return this.transport.connect(url, transferFormat);
364
- }
365
- _resolveTransportOrError(endpoint, requestedTransport, requestedTransferFormat, useStatefulReconnect) {
366
- const transport = HttpTransportType[endpoint.transport];
367
- if (transport === null || transport === undefined) {
368
- this._logger.log(LogLevel.Debug, `Skipping transport '${endpoint.transport}' because it is not supported by this client.`);
369
- return new Error(`Skipping transport '${endpoint.transport}' because it is not supported by this client.`);
370
- }
371
- else {
372
- if (transportMatches(requestedTransport, transport)) {
373
- const transferFormats = endpoint.transferFormats.map((s) => TransferFormat[s]);
374
- if (transferFormats.indexOf(requestedTransferFormat) >= 0) {
375
- if ((transport === HttpTransportType.WebSockets && !this._options.WebSocket) ||
376
- (transport === HttpTransportType.ServerSentEvents && !this._options.EventSource)) {
377
- this._logger.log(LogLevel.Debug, `Skipping transport '${HttpTransportType[transport]}' because it is not supported in your environment.'`);
378
- return new UnsupportedTransportError(`'${HttpTransportType[transport]}' is not supported in your environment.`, transport);
379
- }
380
- else {
381
- this._logger.log(LogLevel.Debug, `Selecting transport '${HttpTransportType[transport]}'.`);
382
- try {
383
- this.features.reconnect = transport === HttpTransportType.WebSockets ? useStatefulReconnect : undefined;
384
- return this._constructTransport(transport);
385
- }
386
- catch (ex) {
387
- return ex;
388
- }
389
- }
390
- }
391
- else {
392
- this._logger.log(LogLevel.Debug, `Skipping transport '${HttpTransportType[transport]}' because it does not support the requested transfer format '${TransferFormat[requestedTransferFormat]}'.`);
393
- return new Error(`'${HttpTransportType[transport]}' does not support ${TransferFormat[requestedTransferFormat]}.`);
394
- }
395
- }
396
- else {
397
- this._logger.log(LogLevel.Debug, `Skipping transport '${HttpTransportType[transport]}' because it was disabled by the client.`);
398
- return new DisabledTransportError(`'${HttpTransportType[transport]}' is disabled by the client.`, transport);
399
- }
400
- }
401
- }
402
- _isITransport(transport) {
403
- return transport && typeof (transport) === "object" && "connect" in transport;
404
- }
405
- _stopConnection(error) {
406
- this._logger.log(LogLevel.Debug, `HttpConnection.stopConnection(${error}) called while in state ${this._connectionState}.`);
407
- this.transport = undefined;
408
- // If we have a stopError, it takes precedence over the error from the transport
409
- error = this._stopError || error;
410
- this._stopError = undefined;
411
- if (this._connectionState === "Disconnected" /* ConnectionState.Disconnected */) {
412
- this._logger.log(LogLevel.Debug, `Call to HttpConnection.stopConnection(${error}) was ignored because the connection is already in the disconnected state.`);
413
- return;
414
- }
415
- if (this._connectionState === "Connecting" /* ConnectionState.Connecting */) {
416
- this._logger.log(LogLevel.Warning, `Call to HttpConnection.stopConnection(${error}) was ignored because the connection is still in the connecting state.`);
417
- throw new Error(`HttpConnection.stopConnection(${error}) was called while the connection is still in the connecting state.`);
418
- }
419
- if (this._connectionState === "Disconnecting" /* ConnectionState.Disconnecting */) {
420
- // A call to stop() induced this call to stopConnection and needs to be completed.
421
- // Any stop() awaiters will be scheduled to continue after the onclose callback fires.
422
- this._stopPromiseResolver();
423
- }
424
- if (error) {
425
- this._logger.log(LogLevel.Error, `Connection disconnected with error '${error}'.`);
426
- }
427
- else {
428
- this._logger.log(LogLevel.Information, "Connection disconnected.");
429
- }
430
- if (this._sendQueue) {
431
- this._sendQueue.stop().catch((e) => {
432
- this._logger.log(LogLevel.Error, `TransportSendQueue.stop() threw error '${e}'.`);
433
- });
434
- this._sendQueue = undefined;
435
- }
436
- this.connectionId = undefined;
437
- this._connectionState = "Disconnected" /* ConnectionState.Disconnected */;
438
- if (this._connectionStarted) {
439
- this._connectionStarted = false;
440
- try {
441
- if (this.onclose) {
442
- this.onclose(error);
443
- }
444
- }
445
- catch (e) {
446
- this._logger.log(LogLevel.Error, `HttpConnection.onclose(${error}) threw error '${e}'.`);
447
- }
448
- }
449
- }
450
- _resolveUrl(url) {
451
- // startsWith is not supported in IE
452
- if (url.lastIndexOf("https://", 0) === 0 || url.lastIndexOf("http://", 0) === 0) {
453
- return url;
454
- }
455
- if (!Platform.isBrowser) {
456
- throw new Error(`Cannot resolve '${url}'.`);
457
- }
458
- // Setting the url to the href propery of an anchor tag handles normalization
459
- // for us. There are 3 main cases.
460
- // 1. Relative path normalization e.g "b" -> "http://localhost:5000/a/b"
461
- // 2. Absolute path normalization e.g "/a/b" -> "http://localhost:5000/a/b"
462
- // 3. Networkpath reference normalization e.g "//localhost:5000/a/b" -> "http://localhost:5000/a/b"
463
- const aTag = window.document.createElement("a");
464
- aTag.href = url;
465
- this._logger.log(LogLevel.Information, `Normalizing '${url}' to '${aTag.href}'.`);
466
- return aTag.href;
467
- }
468
- _resolveNegotiateUrl(url) {
469
- const negotiateUrl = new URL(url);
470
- if (negotiateUrl.pathname.endsWith('/')) {
471
- negotiateUrl.pathname += "negotiate";
472
- }
473
- else {
474
- negotiateUrl.pathname += "/negotiate";
475
- }
476
- const searchParams = new URLSearchParams(negotiateUrl.searchParams);
477
- if (!searchParams.has("negotiateVersion")) {
478
- searchParams.append("negotiateVersion", this._negotiateVersion.toString());
479
- }
480
- if (searchParams.has("useStatefulReconnect")) {
481
- if (searchParams.get("useStatefulReconnect") === "true") {
482
- this._options._useStatefulReconnect = true;
483
- }
484
- }
485
- else if (this._options._useStatefulReconnect === true) {
486
- searchParams.append("useStatefulReconnect", "true");
487
- }
488
- negotiateUrl.search = searchParams.toString();
489
- return negotiateUrl.toString();
490
- }
491
- }
492
- function transportMatches(requestedTransport, actualTransport) {
493
- return !requestedTransport || ((actualTransport & requestedTransport) !== 0);
494
- }
495
- /** @private */
496
- class TransportSendQueue {
497
- constructor(_transport) {
498
- this._transport = _transport;
499
- this._buffer = [];
500
- this._executing = true;
501
- this._sendBufferedData = new PromiseSource();
502
- this._transportResult = new PromiseSource();
503
- this._sendLoopPromise = this._sendLoop();
504
- }
505
- send(data) {
506
- this._bufferData(data);
507
- if (!this._transportResult) {
508
- this._transportResult = new PromiseSource();
509
- }
510
- return this._transportResult.promise;
511
- }
512
- stop() {
513
- this._executing = false;
514
- this._sendBufferedData.resolve();
515
- return this._sendLoopPromise;
516
- }
517
- _bufferData(data) {
518
- if (this._buffer.length && typeof (this._buffer[0]) !== typeof (data)) {
519
- throw new Error(`Expected data to be of type ${typeof (this._buffer)} but was of type ${typeof (data)}`);
520
- }
521
- this._buffer.push(data);
522
- this._sendBufferedData.resolve();
523
- }
524
- async _sendLoop() {
525
- while (true) {
526
- await this._sendBufferedData.promise;
527
- if (!this._executing) {
528
- if (this._transportResult) {
529
- this._transportResult.reject("Connection stopped.");
530
- }
531
- break;
532
- }
533
- this._sendBufferedData = new PromiseSource();
534
- const transportResult = this._transportResult;
535
- this._transportResult = undefined;
536
- const data = typeof (this._buffer[0]) === "string" ?
537
- this._buffer.join("") :
538
- TransportSendQueue._concatBuffers(this._buffer);
539
- this._buffer.length = 0;
540
- try {
541
- await this._transport.send(data);
542
- transportResult.resolve();
543
- }
544
- catch (error) {
545
- transportResult.reject(error);
546
- }
547
- }
548
- }
549
- static _concatBuffers(arrayBuffers) {
550
- const totalLength = arrayBuffers.map((b) => b.byteLength).reduce((a, b) => a + b);
551
- const result = new Uint8Array(totalLength);
552
- let offset = 0;
553
- for (const item of arrayBuffers) {
554
- result.set(new Uint8Array(item), offset);
555
- offset += item.byteLength;
556
- }
557
- return result.buffer;
558
- }
559
- }
560
- class PromiseSource {
561
- constructor() {
562
- this.promise = new Promise((resolve, reject) => [this._resolver, this._rejecter] = [resolve, reject]);
563
- }
564
- resolve() {
565
- this._resolver();
566
- }
567
- reject(reason) {
568
- this._rejecter(reason);
569
- }
1
+ import { AccessTokenHttpClient } from "./AccessTokenHttpClient.js";
2
+ import { DefaultHttpClient } from "./DefaultHttpClient.js";
3
+ import { AbortError, FailedToNegotiateWithServerError, HttpError, FailedToStartTransportError, AggregateErrors, UnsupportedTransportError, DisabledTransportError } from "./Errors.js";
4
+ import { LogLevel } from "./ILogger.js";
5
+ import { TransferFormat, HttpTransportType } from "./ITransport.js";
6
+ import { LongPollingTransport } from "./LongPollingTransport.js";
7
+ import { ServerSentEventsTransport } from "./ServerSentEventsTransport.js";
8
+ import { Arg, createLogger, Platform, getUserAgentHeader } from "./Utils.js";
9
+ import { WebSocketTransport } from "./WebSocketTransport.js";
10
+ const MAX_REDIRECTS = 100;
11
+ class HttpConnection {
12
+ constructor(url, options = {}) {
13
+ this._stopPromiseResolver = () => {
14
+ };
15
+ this.features = {};
16
+ this._negotiateVersion = 1;
17
+ Arg.isRequired(url, "url");
18
+ this._logger = createLogger(options.logger);
19
+ this.baseUrl = this._resolveUrl(url);
20
+ options = options || {};
21
+ options.logMessageContent = options.logMessageContent === void 0 ? false : options.logMessageContent;
22
+ if (typeof options.withCredentials === "boolean" || options.withCredentials === void 0) {
23
+ options.withCredentials = options.withCredentials === void 0 ? true : options.withCredentials;
24
+ } else {
25
+ throw new Error("withCredentials option was not a 'boolean' or 'undefined' value");
26
+ }
27
+ options.timeout = options.timeout === void 0 ? 100 * 1e3 : options.timeout;
28
+ let webSocketModule = null;
29
+ let eventSourceModule = null;
30
+ if (Platform.isNode && typeof require !== "undefined") {
31
+ const requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
32
+ webSocketModule = requireFunc("ws");
33
+ eventSourceModule = requireFunc("eventsource");
34
+ }
35
+ if (!Platform.isNode && typeof WebSocket !== "undefined" && !options.WebSocket) {
36
+ options.WebSocket = WebSocket;
37
+ } else if (Platform.isNode && !options.WebSocket) {
38
+ if (webSocketModule) {
39
+ options.WebSocket = webSocketModule;
40
+ }
41
+ }
42
+ if (!Platform.isNode && typeof EventSource !== "undefined" && !options.EventSource) {
43
+ options.EventSource = EventSource;
44
+ } else if (Platform.isNode && !options.EventSource) {
45
+ if (typeof eventSourceModule !== "undefined") {
46
+ options.EventSource = eventSourceModule;
47
+ }
48
+ }
49
+ this._httpClient = new AccessTokenHttpClient(options.httpClient || new DefaultHttpClient(this._logger), options.accessTokenFactory);
50
+ this._connectionState = "Disconnected";
51
+ this._connectionStarted = false;
52
+ this._options = options;
53
+ this.onreceive = null;
54
+ this.onclose = null;
55
+ }
56
+ async start(transferFormat) {
57
+ transferFormat = transferFormat || TransferFormat.Binary;
58
+ Arg.isIn(transferFormat, TransferFormat, "transferFormat");
59
+ this._logger.log(LogLevel.Debug, `Starting connection with transfer format '${TransferFormat[transferFormat]}'.`);
60
+ if (this._connectionState !== "Disconnected") {
61
+ return Promise.reject(new Error("Cannot start an HttpConnection that is not in the 'Disconnected' state."));
62
+ }
63
+ this._connectionState = "Connecting";
64
+ this._startInternalPromise = this._startInternal(transferFormat);
65
+ await this._startInternalPromise;
66
+ if (this._connectionState === "Disconnecting") {
67
+ const message = "Failed to start the HttpConnection before stop() was called.";
68
+ this._logger.log(LogLevel.Error, message);
69
+ await this._stopPromise;
70
+ return Promise.reject(new AbortError(message));
71
+ } else if (this._connectionState !== "Connected") {
72
+ const message = "HttpConnection.startInternal completed gracefully but didn't enter the connection into the connected state!";
73
+ this._logger.log(LogLevel.Error, message);
74
+ return Promise.reject(new AbortError(message));
75
+ }
76
+ this._connectionStarted = true;
77
+ }
78
+ send(data) {
79
+ if (this._connectionState !== "Connected") {
80
+ return Promise.reject(new Error("Cannot send data if the connection is not in the 'Connected' State."));
81
+ }
82
+ if (!this._sendQueue) {
83
+ this._sendQueue = new TransportSendQueue(this.transport);
84
+ }
85
+ return this._sendQueue.send(data);
86
+ }
87
+ async stop(error) {
88
+ if (this._connectionState === "Disconnected") {
89
+ this._logger.log(LogLevel.Debug, `Call to HttpConnection.stop(${error}) ignored because the connection is already in the disconnected state.`);
90
+ return Promise.resolve();
91
+ }
92
+ if (this._connectionState === "Disconnecting") {
93
+ this._logger.log(LogLevel.Debug, `Call to HttpConnection.stop(${error}) ignored because the connection is already in the disconnecting state.`);
94
+ return this._stopPromise;
95
+ }
96
+ this._connectionState = "Disconnecting";
97
+ this._stopPromise = new Promise((resolve) => {
98
+ this._stopPromiseResolver = resolve;
99
+ });
100
+ await this._stopInternal(error);
101
+ await this._stopPromise;
102
+ }
103
+ async _stopInternal(error) {
104
+ this._stopError = error;
105
+ try {
106
+ await this._startInternalPromise;
107
+ } catch (e) {
108
+ }
109
+ if (this.transport) {
110
+ try {
111
+ await this.transport.stop();
112
+ } catch (e) {
113
+ this._logger.log(LogLevel.Error, `HttpConnection.transport.stop() threw error '${e}'.`);
114
+ this._stopConnection();
115
+ }
116
+ this.transport = void 0;
117
+ } else {
118
+ this._logger.log(LogLevel.Debug, "HttpConnection.transport is undefined in HttpConnection.stop() because start() failed.");
119
+ }
120
+ }
121
+ async _startInternal(transferFormat) {
122
+ let url = this.baseUrl;
123
+ this._accessTokenFactory = this._options.accessTokenFactory;
124
+ this._httpClient._accessTokenFactory = this._accessTokenFactory;
125
+ try {
126
+ if (this._options.skipNegotiation) {
127
+ if (this._options.transport === HttpTransportType.WebSockets) {
128
+ this.transport = this._constructTransport(HttpTransportType.WebSockets);
129
+ await this._startTransport(url, transferFormat);
130
+ } else {
131
+ throw new Error("Negotiation can only be skipped when using the WebSocket transport directly.");
132
+ }
133
+ } else {
134
+ let negotiateResponse = null;
135
+ let redirects = 0;
136
+ do {
137
+ negotiateResponse = await this._getNegotiationResponse(url);
138
+ if (this._connectionState === "Disconnecting" || this._connectionState === "Disconnected") {
139
+ throw new AbortError("The connection was stopped during negotiation.");
140
+ }
141
+ if (negotiateResponse.error) {
142
+ throw new Error(negotiateResponse.error);
143
+ }
144
+ if (negotiateResponse.ProtocolVersion) {
145
+ throw new Error("Detected a connection attempt to an ASP.NET SignalR Server. This client only supports connecting to an ASP.NET Core SignalR Server. See https://aka.ms/signalr-core-differences for details.");
146
+ }
147
+ if (negotiateResponse.url) {
148
+ url = negotiateResponse.url;
149
+ }
150
+ if (negotiateResponse.accessToken) {
151
+ const accessToken = negotiateResponse.accessToken;
152
+ this._accessTokenFactory = () => accessToken;
153
+ this._httpClient._accessToken = accessToken;
154
+ this._httpClient._accessTokenFactory = void 0;
155
+ }
156
+ redirects++;
157
+ } while (negotiateResponse.url && redirects < MAX_REDIRECTS);
158
+ if (redirects === MAX_REDIRECTS && negotiateResponse.url) {
159
+ throw new Error("Negotiate redirection limit exceeded.");
160
+ }
161
+ await this._createTransport(url, this._options.transport, negotiateResponse, transferFormat);
162
+ }
163
+ if (this.transport instanceof LongPollingTransport) {
164
+ this.features.inherentKeepAlive = true;
165
+ }
166
+ if (this._connectionState === "Connecting") {
167
+ this._logger.log(LogLevel.Debug, "The HttpConnection connected successfully.");
168
+ this._connectionState = "Connected";
169
+ }
170
+ } catch (e) {
171
+ this._logger.log(LogLevel.Error, "Failed to start the connection: " + e);
172
+ this._connectionState = "Disconnected";
173
+ this.transport = void 0;
174
+ this._stopPromiseResolver();
175
+ return Promise.reject(e);
176
+ }
177
+ }
178
+ async _getNegotiationResponse(url) {
179
+ const headers = {};
180
+ const [name, value] = getUserAgentHeader();
181
+ headers[name] = value;
182
+ const negotiateUrl = this._resolveNegotiateUrl(url);
183
+ this._logger.log(LogLevel.Debug, `Sending negotiation request: ${negotiateUrl}.`);
184
+ try {
185
+ const response = await this._httpClient.post(negotiateUrl, {
186
+ content: "",
187
+ headers: { ...headers, ...this._options.headers },
188
+ timeout: this._options.timeout,
189
+ withCredentials: this._options.withCredentials
190
+ });
191
+ if (response.statusCode !== 200) {
192
+ return Promise.reject(new Error(`Unexpected status code returned from negotiate '${response.statusCode}'`));
193
+ }
194
+ const negotiateResponse = JSON.parse(response.content);
195
+ if (!negotiateResponse.negotiateVersion || negotiateResponse.negotiateVersion < 1) {
196
+ negotiateResponse.connectionToken = negotiateResponse.connectionId;
197
+ }
198
+ if (negotiateResponse.useStatefulReconnect && this._options._useStatefulReconnect !== true) {
199
+ return Promise.reject(new FailedToNegotiateWithServerError("Client didn't negotiate Stateful Reconnect but the server did."));
200
+ }
201
+ return negotiateResponse;
202
+ } catch (e) {
203
+ let errorMessage = "Failed to complete negotiation with the server: " + e;
204
+ if (e instanceof HttpError) {
205
+ if (e.statusCode === 404) {
206
+ errorMessage = errorMessage + " Either this is not a SignalR endpoint or there is a proxy blocking the connection.";
207
+ }
208
+ }
209
+ this._logger.log(LogLevel.Error, errorMessage);
210
+ return Promise.reject(new FailedToNegotiateWithServerError(errorMessage));
211
+ }
212
+ }
213
+ _createConnectUrl(url, connectionToken) {
214
+ if (!connectionToken) {
215
+ return url;
216
+ }
217
+ return url + (url.indexOf("?") === -1 ? "?" : "&") + `id=${connectionToken}`;
218
+ }
219
+ async _createTransport(url, requestedTransport, negotiateResponse, requestedTransferFormat) {
220
+ let connectUrl = this._createConnectUrl(url, negotiateResponse.connectionToken);
221
+ if (this._isITransport(requestedTransport)) {
222
+ this._logger.log(LogLevel.Debug, "Connection was provided an instance of ITransport, using that directly.");
223
+ this.transport = requestedTransport;
224
+ await this._startTransport(connectUrl, requestedTransferFormat);
225
+ this.connectionId = negotiateResponse.connectionId;
226
+ return;
227
+ }
228
+ const transportExceptions = [];
229
+ const transports = negotiateResponse.availableTransports || [];
230
+ let negotiate = negotiateResponse;
231
+ for (const endpoint of transports) {
232
+ const transportOrError = this._resolveTransportOrError(endpoint, requestedTransport, requestedTransferFormat, (negotiate === null || negotiate === void 0 ? void 0 : negotiate.useStatefulReconnect) === true);
233
+ if (transportOrError instanceof Error) {
234
+ transportExceptions.push(`${endpoint.transport} failed:`);
235
+ transportExceptions.push(transportOrError);
236
+ } else if (this._isITransport(transportOrError)) {
237
+ this.transport = transportOrError;
238
+ if (!negotiate) {
239
+ try {
240
+ negotiate = await this._getNegotiationResponse(url);
241
+ } catch (ex) {
242
+ return Promise.reject(ex);
243
+ }
244
+ connectUrl = this._createConnectUrl(url, negotiate.connectionToken);
245
+ }
246
+ try {
247
+ await this._startTransport(connectUrl, requestedTransferFormat);
248
+ this.connectionId = negotiate.connectionId;
249
+ return;
250
+ } catch (ex) {
251
+ this._logger.log(LogLevel.Error, `Failed to start the transport '${endpoint.transport}': ${ex}`);
252
+ negotiate = void 0;
253
+ transportExceptions.push(new FailedToStartTransportError(`${endpoint.transport} failed: ${ex}`, HttpTransportType[endpoint.transport]));
254
+ if (this._connectionState !== "Connecting") {
255
+ const message = "Failed to select transport before stop() was called.";
256
+ this._logger.log(LogLevel.Debug, message);
257
+ return Promise.reject(new AbortError(message));
258
+ }
259
+ }
260
+ }
261
+ }
262
+ if (transportExceptions.length > 0) {
263
+ return Promise.reject(new AggregateErrors(`Unable to connect to the server with any of the available transports. ${transportExceptions.join(" ")}`, transportExceptions));
264
+ }
265
+ return Promise.reject(new Error("None of the transports supported by the client are supported by the server."));
266
+ }
267
+ _constructTransport(transport) {
268
+ switch (transport) {
269
+ case HttpTransportType.WebSockets:
270
+ if (!this._options.WebSocket) {
271
+ throw new Error("'WebSocket' is not supported in your environment.");
272
+ }
273
+ return new WebSocketTransport(this._httpClient, this._accessTokenFactory, this._logger, this._options.logMessageContent, this._options.WebSocket, this._options.headers || {});
274
+ case HttpTransportType.ServerSentEvents:
275
+ if (!this._options.EventSource) {
276
+ throw new Error("'EventSource' is not supported in your environment.");
277
+ }
278
+ return new ServerSentEventsTransport(this._httpClient, this._httpClient._accessToken, this._logger, this._options);
279
+ case HttpTransportType.LongPolling:
280
+ return new LongPollingTransport(this._httpClient, this._logger, this._options);
281
+ default:
282
+ throw new Error(`Unknown transport: ${transport}.`);
283
+ }
284
+ }
285
+ _startTransport(url, transferFormat) {
286
+ this.transport.onreceive = this.onreceive;
287
+ if (this.features.reconnect) {
288
+ this.transport.onclose = async (e) => {
289
+ let callStop = false;
290
+ if (this.features.reconnect) {
291
+ try {
292
+ this.features.disconnected();
293
+ await this.transport.connect(url, transferFormat);
294
+ await this.features.resend();
295
+ } catch {
296
+ callStop = true;
297
+ }
298
+ } else {
299
+ this._stopConnection(e);
300
+ return;
301
+ }
302
+ if (callStop) {
303
+ this._stopConnection(e);
304
+ }
305
+ };
306
+ } else {
307
+ this.transport.onclose = (e) => this._stopConnection(e);
308
+ }
309
+ return this.transport.connect(url, transferFormat);
310
+ }
311
+ _resolveTransportOrError(endpoint, requestedTransport, requestedTransferFormat, useStatefulReconnect) {
312
+ const transport = HttpTransportType[endpoint.transport];
313
+ if (transport === null || transport === void 0) {
314
+ this._logger.log(LogLevel.Debug, `Skipping transport '${endpoint.transport}' because it is not supported by this client.`);
315
+ return new Error(`Skipping transport '${endpoint.transport}' because it is not supported by this client.`);
316
+ } else {
317
+ if (transportMatches(requestedTransport, transport)) {
318
+ const transferFormats = endpoint.transferFormats.map((s) => TransferFormat[s]);
319
+ if (transferFormats.indexOf(requestedTransferFormat) >= 0) {
320
+ if (transport === HttpTransportType.WebSockets && !this._options.WebSocket || transport === HttpTransportType.ServerSentEvents && !this._options.EventSource) {
321
+ this._logger.log(LogLevel.Debug, `Skipping transport '${HttpTransportType[transport]}' because it is not supported in your environment.'`);
322
+ return new UnsupportedTransportError(`'${HttpTransportType[transport]}' is not supported in your environment.`, transport);
323
+ } else {
324
+ this._logger.log(LogLevel.Debug, `Selecting transport '${HttpTransportType[transport]}'.`);
325
+ try {
326
+ this.features.reconnect = transport === HttpTransportType.WebSockets ? useStatefulReconnect : void 0;
327
+ return this._constructTransport(transport);
328
+ } catch (ex) {
329
+ return ex;
330
+ }
331
+ }
332
+ } else {
333
+ this._logger.log(LogLevel.Debug, `Skipping transport '${HttpTransportType[transport]}' because it does not support the requested transfer format '${TransferFormat[requestedTransferFormat]}'.`);
334
+ return new Error(`'${HttpTransportType[transport]}' does not support ${TransferFormat[requestedTransferFormat]}.`);
335
+ }
336
+ } else {
337
+ this._logger.log(LogLevel.Debug, `Skipping transport '${HttpTransportType[transport]}' because it was disabled by the client.`);
338
+ return new DisabledTransportError(`'${HttpTransportType[transport]}' is disabled by the client.`, transport);
339
+ }
340
+ }
341
+ }
342
+ _isITransport(transport) {
343
+ return transport && typeof transport === "object" && "connect" in transport;
344
+ }
345
+ _stopConnection(error) {
346
+ this._logger.log(LogLevel.Debug, `HttpConnection.stopConnection(${error}) called while in state ${this._connectionState}.`);
347
+ this.transport = void 0;
348
+ error = this._stopError || error;
349
+ this._stopError = void 0;
350
+ if (this._connectionState === "Disconnected") {
351
+ this._logger.log(LogLevel.Debug, `Call to HttpConnection.stopConnection(${error}) was ignored because the connection is already in the disconnected state.`);
352
+ return;
353
+ }
354
+ if (this._connectionState === "Connecting") {
355
+ this._logger.log(LogLevel.Warning, `Call to HttpConnection.stopConnection(${error}) was ignored because the connection is still in the connecting state.`);
356
+ throw new Error(`HttpConnection.stopConnection(${error}) was called while the connection is still in the connecting state.`);
357
+ }
358
+ if (this._connectionState === "Disconnecting") {
359
+ this._stopPromiseResolver();
360
+ }
361
+ if (error) {
362
+ this._logger.log(LogLevel.Error, `Connection disconnected with error '${error}'.`);
363
+ } else {
364
+ this._logger.log(LogLevel.Information, "Connection disconnected.");
365
+ }
366
+ if (this._sendQueue) {
367
+ this._sendQueue.stop().catch((e) => {
368
+ this._logger.log(LogLevel.Error, `TransportSendQueue.stop() threw error '${e}'.`);
369
+ });
370
+ this._sendQueue = void 0;
371
+ }
372
+ this.connectionId = void 0;
373
+ this._connectionState = "Disconnected";
374
+ if (this._connectionStarted) {
375
+ this._connectionStarted = false;
376
+ try {
377
+ if (this.onclose) {
378
+ this.onclose(error);
379
+ }
380
+ } catch (e) {
381
+ this._logger.log(LogLevel.Error, `HttpConnection.onclose(${error}) threw error '${e}'.`);
382
+ }
383
+ }
384
+ }
385
+ _resolveUrl(url) {
386
+ if (url.lastIndexOf("https://", 0) === 0 || url.lastIndexOf("http://", 0) === 0) {
387
+ return url;
388
+ }
389
+ if (!Platform.isBrowser) {
390
+ throw new Error(`Cannot resolve '${url}'.`);
391
+ }
392
+ const aTag = window.document.createElement("a");
393
+ aTag.href = url;
394
+ this._logger.log(LogLevel.Information, `Normalizing '${url}' to '${aTag.href}'.`);
395
+ return aTag.href;
396
+ }
397
+ _resolveNegotiateUrl(url) {
398
+ const negotiateUrl = new URL(url);
399
+ if (negotiateUrl.pathname.endsWith("/")) {
400
+ negotiateUrl.pathname += "negotiate";
401
+ } else {
402
+ negotiateUrl.pathname += "/negotiate";
403
+ }
404
+ const searchParams = new URLSearchParams(negotiateUrl.searchParams);
405
+ if (!searchParams.has("negotiateVersion")) {
406
+ searchParams.append("negotiateVersion", this._negotiateVersion.toString());
407
+ }
408
+ if (searchParams.has("useStatefulReconnect")) {
409
+ if (searchParams.get("useStatefulReconnect") === "true") {
410
+ this._options._useStatefulReconnect = true;
411
+ }
412
+ } else if (this._options._useStatefulReconnect === true) {
413
+ searchParams.append("useStatefulReconnect", "true");
414
+ }
415
+ negotiateUrl.search = searchParams.toString();
416
+ return negotiateUrl.toString();
417
+ }
570
418
  }
571
-
572
- export { HttpConnection, TransportSendQueue };
419
+ function transportMatches(requestedTransport, actualTransport) {
420
+ return !requestedTransport || (actualTransport & requestedTransport) !== 0;
421
+ }
422
+ class TransportSendQueue {
423
+ constructor(_transport) {
424
+ this._transport = _transport;
425
+ this._buffer = [];
426
+ this._executing = true;
427
+ this._sendBufferedData = new PromiseSource();
428
+ this._transportResult = new PromiseSource();
429
+ this._sendLoopPromise = this._sendLoop();
430
+ }
431
+ send(data) {
432
+ this._bufferData(data);
433
+ if (!this._transportResult) {
434
+ this._transportResult = new PromiseSource();
435
+ }
436
+ return this._transportResult.promise;
437
+ }
438
+ stop() {
439
+ this._executing = false;
440
+ this._sendBufferedData.resolve();
441
+ return this._sendLoopPromise;
442
+ }
443
+ _bufferData(data) {
444
+ if (this._buffer.length && typeof this._buffer[0] !== typeof data) {
445
+ throw new Error(`Expected data to be of type ${typeof this._buffer} but was of type ${typeof data}`);
446
+ }
447
+ this._buffer.push(data);
448
+ this._sendBufferedData.resolve();
449
+ }
450
+ async _sendLoop() {
451
+ while (true) {
452
+ await this._sendBufferedData.promise;
453
+ if (!this._executing) {
454
+ if (this._transportResult) {
455
+ this._transportResult.reject("Connection stopped.");
456
+ }
457
+ break;
458
+ }
459
+ this._sendBufferedData = new PromiseSource();
460
+ const transportResult = this._transportResult;
461
+ this._transportResult = void 0;
462
+ const data = typeof this._buffer[0] === "string" ? this._buffer.join("") : TransportSendQueue._concatBuffers(this._buffer);
463
+ this._buffer.length = 0;
464
+ try {
465
+ await this._transport.send(data);
466
+ transportResult.resolve();
467
+ } catch (error) {
468
+ transportResult.reject(error);
469
+ }
470
+ }
471
+ }
472
+ static _concatBuffers(arrayBuffers) {
473
+ const totalLength = arrayBuffers.map((b) => b.byteLength).reduce((a, b) => a + b);
474
+ const result = new Uint8Array(totalLength);
475
+ let offset = 0;
476
+ for (const item of arrayBuffers) {
477
+ result.set(new Uint8Array(item), offset);
478
+ offset += item.byteLength;
479
+ }
480
+ return result.buffer;
481
+ }
482
+ }
483
+ class PromiseSource {
484
+ constructor() {
485
+ this.promise = new Promise((resolve, reject) => [this._resolver, this._rejecter] = [resolve, reject]);
486
+ }
487
+ resolve() {
488
+ this._resolver();
489
+ }
490
+ reject(reason) {
491
+ this._rejecter(reason);
492
+ }
493
+ }
494
+ export {
495
+ HttpConnection,
496
+ TransportSendQueue
497
+ };