@nice2dev/game-engine 1.3.15 → 1.3.17
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.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/accessibility/Accessibility.js +152 -165
- package/dist/cjs/ai/AI.js +292 -294
- package/dist/cjs/ai/BehaviorTree.js +1029 -1113
- package/dist/cjs/ai/StateMachine.js +694 -756
- package/dist/cjs/animation/Animation.js +232 -241
- package/dist/cjs/audio/AudioAdvanced.js +221 -236
- package/dist/cjs/audio/AudioBridge.js +441 -435
- package/dist/cjs/audio/AudioManager.js +242 -259
- package/dist/cjs/build-cloud/BuildOrchestration.js +1059 -1098
- package/dist/cjs/build-cloud/GodotBuildCloud.js +641 -670
- package/dist/cjs/build-cloud/UnityBuildCloud.js +563 -610
- package/dist/cjs/build-cloud/UnrealBuildCloud.js +610 -635
- package/dist/cjs/core/EventBus.js +51 -56
- package/dist/cjs/core/GameClock.js +62 -66
- package/dist/cjs/core/GameConfig.js +72 -79
- package/dist/cjs/core/GameLoop.js +80 -89
- package/dist/cjs/core/ServiceLocator.js +61 -65
- package/dist/cjs/core/Validation.js +72 -82
- package/dist/cjs/core/math.js +108 -112
- package/dist/cjs/devtools/DevTools.js +542 -563
- package/dist/cjs/devtools/DeveloperExperience.js +521 -559
- package/dist/cjs/devtools/GameplayAnalytics.js +636 -646
- package/dist/cjs/dialogue/DialogueSystem.js +984 -986
- package/dist/cjs/docs/DocGenerator.js +339 -364
- package/dist/cjs/ecs/World.js +355 -371
- package/dist/cjs/editor/AchievementEditor.js +580 -636
- package/dist/cjs/editor/AdvancedEditor.js +184 -191
- package/dist/cjs/editor/AnimationRetargeting.js +696 -741
- package/dist/cjs/editor/AssetBrowser.js +1072 -1160
- package/dist/cjs/editor/AssetManager.js +187 -192
- package/dist/cjs/editor/ConsolePro.js +971 -1061
- package/dist/cjs/editor/CraftingEditor.js +680 -730
- package/dist/cjs/editor/DebugTools.js +187 -185
- package/dist/cjs/editor/DialogueSystem.js +844 -901
- package/dist/cjs/editor/LeaderboardSystem.js +429 -483
- package/dist/cjs/editor/NiceGameEditor.js +1903 -1201
- package/dist/cjs/editor/PrefabSystem.js +772 -838
- package/dist/cjs/editor/ProfilerPanel.js +649 -700
- package/dist/cjs/editor/QuestEditor.js +792 -839
- package/dist/cjs/editor/ReplaySystem.js +585 -634
- package/dist/cjs/editor/SceneEditor.js +176 -200
- package/dist/cjs/editor/ScreenshotMode.js +621 -688
- package/dist/cjs/editor/ShaderGraph.js +1556 -1582
- package/dist/cjs/editor/TimelineEditor.js +715 -778
- package/dist/cjs/editor/UndoRedoPro.js +830 -904
- package/dist/cjs/editor/VRARMode.js +582 -645
- package/dist/cjs/engine/NiceGameEngine.js +141 -164
- package/dist/cjs/engine/SaveSystem.js +441 -495
- package/dist/cjs/enterprise/Enterprise.js +254 -261
- package/dist/cjs/export/BevyExporter.js +927 -967
- package/dist/cjs/export/CocosExporter.js +644 -673
- package/dist/cjs/export/Construct3Exporter.js +783 -794
- package/dist/cjs/export/DefoldExporter.js +1028 -1069
- package/dist/cjs/export/GDevelopExporter.js +674 -708
- package/dist/cjs/export/GameMakerExporter.js +791 -805
- package/dist/cjs/export/GodotExporter.js +1003 -1045
- package/dist/cjs/export/MinecraftBedrockExporter.js +573 -578
- package/dist/cjs/export/MonoGameExporter.js +1265 -1293
- package/dist/cjs/export/Pico8Exporter.js +766 -812
- package/dist/cjs/export/PlatformExporter.js +188 -206
- package/dist/cjs/export/RPGMakerExporter.js +860 -879
- package/dist/cjs/export/RobloxExporter.js +883 -919
- package/dist/cjs/export/Solar2DExporter.js +1218 -1256
- package/dist/cjs/export/ThreeJSExporter.js +1006 -1073
- package/dist/cjs/export/Tic80Exporter.js +1210 -1267
- package/dist/cjs/export/UnityExporter.js +1116 -1131
- package/dist/cjs/export/UnrealExporter.js +889 -919
- package/dist/cjs/export/WebExporter.js +931 -970
- package/dist/cjs/export/index.js +42 -65
- package/dist/cjs/godot-integration/GodotAssetLibrary.js +659 -692
- package/dist/cjs/godot-integration/GodotImport.js +929 -1027
- package/dist/cjs/godot-integration/GodotLiveLink.js +915 -945
- package/dist/cjs/godot-integration/components/GodotProjectBrowser.js +911 -611
- package/dist/cjs/i18n/I18n.js +860 -900
- package/dist/cjs/i18n/useTranslation.js +84 -89
- package/dist/cjs/import/AsepriteImporter.js +658 -716
- package/dist/cjs/import/DragonBonesImporter.js +437 -461
- package/dist/cjs/import/GameMakerImporter.js +511 -521
- package/dist/cjs/import/GodotSceneImporter.js +788 -822
- package/dist/cjs/import/LDtkImporter.js +436 -454
- package/dist/cjs/import/Live2DImporter.js +497 -518
- package/dist/cjs/import/NdgFormat.js +424 -457
- package/dist/cjs/import/OgmoImporter.js +466 -493
- package/dist/cjs/import/RPGMakerImporter.js +451 -477
- package/dist/cjs/import/SceneImporter.js +378 -423
- package/dist/cjs/import/SpineImporter.js +511 -546
- package/dist/cjs/import/SpriterImporter.js +590 -613
- package/dist/cjs/import/TiledMapImporter.js +811 -846
- package/dist/cjs/import/UnitySceneImporter.js +687 -703
- package/dist/cjs/import/index.js +206 -251
- package/dist/cjs/index.js +275 -278
- package/dist/cjs/input/GamepadNavigation.js +185 -205
- package/dist/cjs/input/InputManager.js +397 -421
- package/dist/cjs/input/useGamepads.js +70 -81
- package/dist/cjs/integration/IconSprite.js +129 -256
- package/dist/cjs/inventory/InventorySystem.js +920 -995
- package/dist/cjs/kids/KidMode.js +997 -1022
- package/dist/cjs/kids/KidTools.js +570 -594
- package/dist/cjs/monetization/Monetization.js +170 -177
- package/dist/cjs/multiplayer/LocalMultiplayer.js +287 -287
- package/dist/cjs/multiplayer/MiniGameTypes.js +49 -59
- package/dist/cjs/native-engine/AnimationSystem.js +731 -806
- package/dist/cjs/native-engine/AssetPipeline.js +454 -515
- package/dist/cjs/native-engine/AudioEngine.js +763 -804
- package/dist/cjs/native-engine/InputSystem.js +1075 -1145
- package/dist/cjs/native-engine/NetworkingSystem.js +733 -793
- package/dist/cjs/native-engine/PhysicsEngine.js +583 -607
- package/dist/cjs/native-engine/RenderingEngine.js +302 -350
- package/dist/cjs/native-engine/SceneGraph.js +769 -808
- package/dist/cjs/network/MultiplayerTransport.js +97 -132
- package/dist/cjs/network/Networking.js +549 -564
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/AbortController.js +21 -29
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/AccessTokenHttpClient.js +40 -48
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +35 -43
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +10 -15
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Errors.js +103 -135
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +131 -158
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +39 -53
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +5 -8
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +40 -48
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +494 -572
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +826 -953
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +125 -146
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +13 -23
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ILogger.js +11 -25
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ITransport.js +13 -24
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +108 -121
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Loggers.js +10 -14
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +150 -185
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/MessageBuffer.js +158 -196
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +90 -105
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Subject.js +30 -35
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +16 -21
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Utils.js +215 -248
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +135 -157
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +76 -85
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/index.js +24 -27
- package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/pkg-version.js +3 -4
- package/dist/cjs/pathfinding/Pathfinding.js +245 -263
- package/dist/cjs/performance/AssetStreaming.js +561 -635
- package/dist/cjs/performance/BenchmarkSuite.js +283 -311
- package/dist/cjs/performance/DeltaCompression.js +467 -526
- package/dist/cjs/performance/DeterministicPhysics.js +450 -498
- package/dist/cjs/performance/ECSOptimization.js +644 -695
- package/dist/cjs/performance/GameSaveSystem.js +509 -556
- package/dist/cjs/performance/HotReload.js +447 -500
- package/dist/cjs/performance/InputRecording.js +511 -561
- package/dist/cjs/performance/InterestManagement.js +453 -500
- package/dist/cjs/performance/LocalizationRuntime.js +376 -423
- package/dist/cjs/performance/MemoryManagement.js +410 -470
- package/dist/cjs/performance/ModSupport.js +445 -496
- package/dist/cjs/performance/MultiThreadedPhysics.js +400 -443
- package/dist/cjs/performance/NetworkPrediction.js +424 -482
- package/dist/cjs/performance/ObjectPooling.js +569 -617
- package/dist/cjs/performance/Performance.js +174 -190
- package/dist/cjs/performance/PerformanceAdvanced.js +614 -637
- package/dist/cjs/performance/WebGPURenderer.js +656 -683
- package/dist/cjs/physics/PhysicsAdvanced.js +345 -379
- package/dist/cjs/physics/PhysicsEngine2D.js +391 -427
- package/dist/cjs/plugins/PluginSDK.js +432 -466
- package/dist/cjs/plugins/PluginTestKit.js +307 -330
- package/dist/cjs/procedural/Procedural.js +243 -254
- package/dist/cjs/procedural/WorldBuilding.js +297 -314
- package/dist/cjs/quest/QuestSystem.js +975 -932
- package/dist/cjs/release/MobileExport.js +157 -163
- package/dist/cjs/release/Release.js +225 -238
- package/dist/cjs/rendering/Camera2D.js +121 -124
- package/dist/cjs/rendering/Renderer2D.js +321 -335
- package/dist/cjs/rendering/WebGPURenderPipeline.js +632 -651
- package/dist/cjs/runtime3d/Runtime3D.js +359 -378
- package/dist/cjs/runtime3d/SceneEditor3D.js +252 -263
- package/dist/cjs/scene/SceneManager.js +177 -193
- package/dist/cjs/scripting/GraphToAST.js +574 -547
- package/dist/cjs/scripting/LanguageExporter.js +254 -279
- package/dist/cjs/scripting/NodeGraph.js +546 -570
- package/dist/cjs/scripting/ScriptAST.js +31 -39
- package/dist/cjs/scripting/VisualScripting2.js +1016 -1065
- package/dist/cjs/scripting/exporters/CSharpExporter.js +464 -496
- package/dist/cjs/scripting/exporters/GDScriptExporter.js +390 -442
- package/dist/cjs/scripting/exporters/LuaExporter.js +406 -447
- package/dist/cjs/scripting/exporters/PythonExporter.js +484 -549
- package/dist/cjs/scripting/exporters/RustExporter.js +459 -512
- package/dist/cjs/scripting/exporters/TypeScriptExporter.js +505 -556
- package/dist/cjs/social/Social.js +72 -80
- package/dist/cjs/systems/LightingSystem.js +844 -931
- package/dist/cjs/systems/ParticleSystem2.js +1447 -1451
- package/dist/cjs/systems/PhysicsDebugSystem.js +1070 -1141
- package/dist/cjs/systems/TerrainSystem.js +985 -1098
- package/dist/cjs/templates/ActionTemplates.js +296 -309
- package/dist/cjs/templates/FightingTemplate.js +417 -463
- package/dist/cjs/templates/MetroidvaniaTemplate.js +353 -405
- package/dist/cjs/templates/PartyTemplates.js +190 -202
- package/dist/cjs/templates/PuzzleTemplates.js +245 -261
- package/dist/cjs/templates/RPGTemplates.js +160 -178
- package/dist/cjs/templates/SportsTemplates.js +237 -250
- package/dist/cjs/templates/StrategyTemplates.js +143 -153
- package/dist/cjs/templates/SurvivalTemplate.js +336 -380
- package/dist/cjs/templates/WaveDefense.js +499 -526
- package/dist/cjs/tilemap/Tilemap.js +207 -214
- package/dist/cjs/tutorials/TutorialBranching.js +396 -417
- package/dist/cjs/tutorials/TutorialEngine.js +888 -931
- package/dist/cjs/tutorials/TutorialOverlay.js +602 -640
- package/dist/cjs/tutorials/content/Tutorials_T05_T08.js +787 -809
- package/dist/cjs/tutorials/content/Tutorials_T09_T11.js +736 -756
- package/dist/cjs/tutorials/content/Tutorials_T12_T15.js +754 -778
- package/dist/cjs/ui/GameUI.js +295 -312
- package/dist/cjs/unity-integration/UnityAssetStore.js +700 -741
- package/dist/cjs/unity-integration/UnityImport.js +1066 -1176
- package/dist/cjs/unity-integration/UnityLiveLink.js +934 -981
- package/dist/cjs/unity-integration/components/UnityAssetStoreBrowser.js +1233 -757
- package/dist/cjs/unity-integration/components/UnityProjectBrowser.js +1240 -768
- package/dist/cjs/unreal-integration/UnrealImport.js +391 -412
- package/dist/cjs/unreal-integration/UnrealLiveLink.js +1102 -1137
- package/dist/cjs/unreal-integration/UnrealMarketplace.js +436 -473
- package/dist/cjs/unreal-integration/components/UnrealProjectBrowser.js +1150 -767
- package/dist/cjs/xr/ARVR.js +167 -175
- package/dist/esm/accessibility/Accessibility.js +160 -164
- package/dist/esm/ai/AI.js +310 -293
- package/dist/esm/ai/BehaviorTree.js +1057 -1112
- package/dist/esm/ai/StateMachine.js +709 -755
- package/dist/esm/animation/Animation.js +237 -240
- package/dist/esm/audio/AudioAdvanced.js +239 -235
- package/dist/esm/audio/AudioBridge.js +448 -434
- package/dist/esm/audio/AudioManager.js +243 -258
- package/dist/esm/build-cloud/BuildOrchestration.js +1071 -1097
- package/dist/esm/build-cloud/GodotBuildCloud.js +647 -669
- package/dist/esm/build-cloud/UnityBuildCloud.js +571 -609
- package/dist/esm/build-cloud/UnrealBuildCloud.js +615 -634
- package/dist/esm/core/EventBus.js +52 -55
- package/dist/esm/core/GameClock.js +63 -65
- package/dist/esm/core/GameConfig.js +77 -78
- package/dist/esm/core/GameLoop.js +81 -88
- package/dist/esm/core/ServiceLocator.js +63 -64
- package/dist/esm/core/Validation.js +82 -81
- package/dist/esm/core/math.js +109 -111
- package/dist/esm/devtools/DevTools.js +546 -562
- package/dist/esm/devtools/DeveloperExperience.js +535 -558
- package/dist/esm/devtools/GameplayAnalytics.js +647 -645
- package/dist/esm/dialogue/DialogueSystem.js +998 -985
- package/dist/esm/docs/DocGenerator.js +342 -363
- package/dist/esm/ecs/World.js +358 -370
- package/dist/esm/editor/AchievementEditor.js +584 -635
- package/dist/esm/editor/AdvancedEditor.js +191 -190
- package/dist/esm/editor/AnimationRetargeting.js +700 -740
- package/dist/esm/editor/AssetBrowser.js +1078 -1159
- package/dist/esm/editor/AssetManager.js +188 -191
- package/dist/esm/editor/ConsolePro.js +977 -1060
- package/dist/esm/editor/CraftingEditor.js +684 -729
- package/dist/esm/editor/DebugTools.js +194 -184
- package/dist/esm/editor/DialogueSystem.js +849 -900
- package/dist/esm/editor/LeaderboardSystem.js +433 -482
- package/dist/esm/editor/NiceGameEditor.js +1908 -1200
- package/dist/esm/editor/PrefabSystem.js +777 -837
- package/dist/esm/editor/ProfilerPanel.js +654 -699
- package/dist/esm/editor/QuestEditor.js +795 -838
- package/dist/esm/editor/ReplaySystem.js +591 -633
- package/dist/esm/editor/SceneEditor.js +189 -199
- package/dist/esm/editor/ScreenshotMode.js +628 -687
- package/dist/esm/editor/ShaderGraph.js +1565 -1581
- package/dist/esm/editor/TimelineEditor.js +733 -777
- package/dist/esm/editor/UndoRedoPro.js +835 -903
- package/dist/esm/editor/VRARMode.js +586 -644
- package/dist/esm/engine/NiceGameEngine.js +142 -163
- package/dist/esm/engine/SaveSystem.js +447 -494
- package/dist/esm/enterprise/Enterprise.js +265 -260
- package/dist/esm/export/BevyExporter.js +929 -966
- package/dist/esm/export/CocosExporter.js +646 -672
- package/dist/esm/export/Construct3Exporter.js +785 -793
- package/dist/esm/export/DefoldExporter.js +1030 -1068
- package/dist/esm/export/GDevelopExporter.js +676 -707
- package/dist/esm/export/GameMakerExporter.js +793 -804
- package/dist/esm/export/GodotExporter.js +1004 -1044
- package/dist/esm/export/MinecraftBedrockExporter.js +575 -577
- package/dist/esm/export/MonoGameExporter.js +1267 -1292
- package/dist/esm/export/Pico8Exporter.js +768 -811
- package/dist/esm/export/PlatformExporter.js +193 -205
- package/dist/esm/export/RPGMakerExporter.js +862 -878
- package/dist/esm/export/RobloxExporter.js +885 -918
- package/dist/esm/export/Solar2DExporter.js +1220 -1255
- package/dist/esm/export/ThreeJSExporter.js +1007 -1072
- package/dist/esm/export/Tic80Exporter.js +1212 -1266
- package/dist/esm/export/UnityExporter.js +1117 -1130
- package/dist/esm/export/UnrealExporter.js +891 -918
- package/dist/esm/export/WebExporter.js +933 -969
- package/dist/esm/export/index.js +86 -71
- package/dist/esm/godot-integration/GodotAssetLibrary.js +663 -691
- package/dist/esm/godot-integration/GodotImport.js +935 -1026
- package/dist/esm/godot-integration/GodotLiveLink.js +918 -944
- package/dist/esm/godot-integration/components/GodotProjectBrowser.js +912 -610
- package/dist/esm/i18n/I18n.js +871 -899
- package/dist/esm/i18n/useTranslation.js +88 -88
- package/dist/esm/import/AsepriteImporter.js +637 -715
- package/dist/esm/import/DragonBonesImporter.js +417 -460
- package/dist/esm/import/GameMakerImporter.js +491 -520
- package/dist/esm/import/GodotSceneImporter.js +767 -821
- package/dist/esm/import/LDtkImporter.js +415 -453
- package/dist/esm/import/Live2DImporter.js +477 -517
- package/dist/esm/import/NdgFormat.js +410 -456
- package/dist/esm/import/OgmoImporter.js +446 -492
- package/dist/esm/import/RPGMakerImporter.js +431 -476
- package/dist/esm/import/SceneImporter.js +385 -422
- package/dist/esm/import/SpineImporter.js +491 -545
- package/dist/esm/import/SpriterImporter.js +570 -612
- package/dist/esm/import/TiledMapImporter.js +790 -845
- package/dist/esm/import/UnitySceneImporter.js +666 -702
- package/dist/esm/import/index.js +247 -258
- package/dist/esm/index.js +1332 -188
- package/dist/esm/input/GamepadNavigation.js +187 -204
- package/dist/esm/input/InputManager.js +401 -420
- package/dist/esm/input/useGamepads.js +72 -80
- package/dist/esm/integration/IconSprite.js +143 -255
- package/dist/esm/inventory/InventorySystem.js +925 -994
- package/dist/esm/kids/KidMode.js +1003 -1021
- package/dist/esm/kids/KidTools.js +573 -593
- package/dist/esm/monetization/Monetization.js +180 -176
- package/dist/esm/multiplayer/LocalMultiplayer.js +290 -286
- package/dist/esm/multiplayer/MiniGameTypes.js +58 -58
- package/dist/esm/native-engine/AnimationSystem.js +735 -805
- package/dist/esm/native-engine/AssetPipeline.js +456 -514
- package/dist/esm/native-engine/AudioEngine.js +765 -803
- package/dist/esm/native-engine/InputSystem.js +1079 -1144
- package/dist/esm/native-engine/NetworkingSystem.js +740 -792
- package/dist/esm/native-engine/PhysicsEngine.js +585 -606
- package/dist/esm/native-engine/RenderingEngine.js +304 -349
- package/dist/esm/native-engine/SceneGraph.js +773 -807
- package/dist/esm/network/MultiplayerTransport.js +99 -131
- package/dist/esm/network/Networking.js +556 -563
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/AbortController.js +22 -28
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/AccessTokenHttpClient.js +41 -47
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +36 -42
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +11 -14
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Errors.js +111 -134
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +132 -157
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +40 -52
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +6 -7
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +42 -47
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +496 -571
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +828 -952
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +126 -145
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +14 -23
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ILogger.js +12 -25
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ITransport.js +15 -24
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +109 -120
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Loggers.js +11 -13
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +151 -184
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/MessageBuffer.js +159 -195
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +91 -104
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Subject.js +31 -34
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +17 -20
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Utils.js +230 -248
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +136 -156
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +77 -84
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/index.js +31 -12
- package/dist/esm/node_modules/@microsoft/signalr/dist/esm/pkg-version.js +4 -3
- package/dist/esm/pathfinding/Pathfinding.js +249 -262
- package/dist/esm/performance/AssetStreaming.js +567 -634
- package/dist/esm/performance/BenchmarkSuite.js +285 -310
- package/dist/esm/performance/DeltaCompression.js +478 -525
- package/dist/esm/performance/DeterministicPhysics.js +479 -497
- package/dist/esm/performance/ECSOptimization.js +653 -694
- package/dist/esm/performance/GameSaveSystem.js +515 -555
- package/dist/esm/performance/HotReload.js +454 -499
- package/dist/esm/performance/InputRecording.js +520 -560
- package/dist/esm/performance/InterestManagement.js +460 -499
- package/dist/esm/performance/LocalizationRuntime.js +382 -422
- package/dist/esm/performance/MemoryManagement.js +415 -469
- package/dist/esm/performance/ModSupport.js +455 -495
- package/dist/esm/performance/MultiThreadedPhysics.js +408 -442
- package/dist/esm/performance/NetworkPrediction.js +436 -481
- package/dist/esm/performance/ObjectPooling.js +582 -616
- package/dist/esm/performance/Performance.js +182 -189
- package/dist/esm/performance/PerformanceAdvanced.js +621 -636
- package/dist/esm/performance/WebGPURenderer.js +660 -682
- package/dist/esm/physics/PhysicsAdvanced.js +359 -378
- package/dist/esm/physics/PhysicsEngine2D.js +393 -426
- package/dist/esm/plugins/PluginSDK.js +435 -465
- package/dist/esm/plugins/PluginTestKit.js +315 -329
- package/dist/esm/procedural/Procedural.js +248 -253
- package/dist/esm/procedural/WorldBuilding.js +316 -313
- package/dist/esm/quest/QuestSystem.js +982 -931
- package/dist/esm/release/MobileExport.js +163 -162
- package/dist/esm/release/Release.js +234 -237
- package/dist/esm/rendering/Camera2D.js +122 -123
- package/dist/esm/rendering/Renderer2D.js +323 -334
- package/dist/esm/rendering/WebGPURenderPipeline.js +647 -650
- package/dist/esm/runtime3d/Runtime3D.js +368 -377
- package/dist/esm/runtime3d/SceneEditor3D.js +268 -262
- package/dist/esm/scene/SceneManager.js +178 -192
- package/dist/esm/scripting/GraphToAST.js +576 -546
- package/dist/esm/scripting/LanguageExporter.js +263 -278
- package/dist/esm/scripting/NodeGraph.js +550 -569
- package/dist/esm/scripting/ScriptAST.js +45 -38
- package/dist/esm/scripting/VisualScripting2.js +1025 -1064
- package/dist/esm/scripting/exporters/CSharpExporter.js +465 -495
- package/dist/esm/scripting/exporters/GDScriptExporter.js +391 -441
- package/dist/esm/scripting/exporters/LuaExporter.js +407 -446
- package/dist/esm/scripting/exporters/PythonExporter.js +485 -548
- package/dist/esm/scripting/exporters/RustExporter.js +460 -511
- package/dist/esm/scripting/exporters/TypeScriptExporter.js +506 -555
- package/dist/esm/social/Social.js +77 -79
- package/dist/esm/systems/LightingSystem.js +855 -930
- package/dist/esm/systems/ParticleSystem2.js +1453 -1450
- package/dist/esm/systems/PhysicsDebugSystem.js +1078 -1140
- package/dist/esm/systems/TerrainSystem.js +996 -1097
- package/dist/esm/templates/ActionTemplates.js +307 -308
- package/dist/esm/templates/FightingTemplate.js +439 -462
- package/dist/esm/templates/MetroidvaniaTemplate.js +391 -404
- package/dist/esm/templates/PartyTemplates.js +206 -201
- package/dist/esm/templates/PuzzleTemplates.js +260 -260
- package/dist/esm/templates/RPGTemplates.js +172 -177
- package/dist/esm/templates/SportsTemplates.js +251 -249
- package/dist/esm/templates/StrategyTemplates.js +158 -152
- package/dist/esm/templates/SurvivalTemplate.js +367 -379
- package/dist/esm/templates/WaveDefense.js +501 -525
- package/dist/esm/tilemap/Tilemap.js +209 -213
- package/dist/esm/tutorials/TutorialBranching.js +399 -416
- package/dist/esm/tutorials/TutorialEngine.js +893 -930
- package/dist/esm/tutorials/TutorialOverlay.js +603 -639
- package/dist/esm/tutorials/content/Tutorials_T05_T08.js +792 -808
- package/dist/esm/tutorials/content/Tutorials_T09_T11.js +740 -755
- package/dist/esm/tutorials/content/Tutorials_T12_T15.js +759 -777
- package/dist/esm/ui/GameUI.js +296 -311
- package/dist/esm/unity-integration/UnityAssetStore.js +704 -740
- package/dist/esm/unity-integration/UnityImport.js +1071 -1175
- package/dist/esm/unity-integration/UnityLiveLink.js +938 -980
- package/dist/esm/unity-integration/components/UnityAssetStoreBrowser.js +1234 -756
- package/dist/esm/unity-integration/components/UnityProjectBrowser.js +1241 -767
- package/dist/esm/unreal-integration/UnrealImport.js +395 -411
- package/dist/esm/unreal-integration/UnrealLiveLink.js +1105 -1136
- package/dist/esm/unreal-integration/UnrealMarketplace.js +442 -472
- package/dist/esm/unreal-integration/components/UnrealProjectBrowser.js +1151 -766
- package/dist/esm/xr/ARVR.js +181 -174
- package/package.json +7 -12
|
@@ -1,953 +1,829 @@
|
|
|
1
|
-
import { HandshakeProtocol } from
|
|
2
|
-
import { AbortError } from
|
|
3
|
-
import { MessageType } from
|
|
4
|
-
import { LogLevel } from
|
|
5
|
-
import { Subject } from
|
|
6
|
-
import { Arg, Platform, getErrorString } from
|
|
7
|
-
import { MessageBuffer } from
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
this.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
}
|
|
507
|
-
this.
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
else {
|
|
826
|
-
return {
|
|
827
|
-
target: methodName,
|
|
828
|
-
arguments: args,
|
|
829
|
-
invocationId: invocationId.toString(),
|
|
830
|
-
type: MessageType.Invocation,
|
|
831
|
-
};
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
_launchStreams(streams, promiseQueue) {
|
|
836
|
-
if (streams.length === 0) {
|
|
837
|
-
return;
|
|
838
|
-
}
|
|
839
|
-
// Synchronize stream data so they arrive in-order on the server
|
|
840
|
-
if (!promiseQueue) {
|
|
841
|
-
promiseQueue = Promise.resolve();
|
|
842
|
-
}
|
|
843
|
-
// We want to iterate over the keys, since the keys are the stream ids
|
|
844
|
-
// eslint-disable-next-line guard-for-in
|
|
845
|
-
for (const streamId in streams) {
|
|
846
|
-
streams[streamId].subscribe({
|
|
847
|
-
complete: () => {
|
|
848
|
-
promiseQueue = promiseQueue.then(() => this._sendWithProtocol(this._createCompletionMessage(streamId)));
|
|
849
|
-
},
|
|
850
|
-
error: (err) => {
|
|
851
|
-
let message;
|
|
852
|
-
if (err instanceof Error) {
|
|
853
|
-
message = err.message;
|
|
854
|
-
}
|
|
855
|
-
else if (err && err.toString) {
|
|
856
|
-
message = err.toString();
|
|
857
|
-
}
|
|
858
|
-
else {
|
|
859
|
-
message = "Unknown error";
|
|
860
|
-
}
|
|
861
|
-
promiseQueue = promiseQueue.then(() => this._sendWithProtocol(this._createCompletionMessage(streamId, message)));
|
|
862
|
-
},
|
|
863
|
-
next: (item) => {
|
|
864
|
-
promiseQueue = promiseQueue.then(() => this._sendWithProtocol(this._createStreamItemMessage(streamId, item)));
|
|
865
|
-
},
|
|
866
|
-
});
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
_replaceStreamingParams(args) {
|
|
870
|
-
const streams = [];
|
|
871
|
-
const streamIds = [];
|
|
872
|
-
for (let i = 0; i < args.length; i++) {
|
|
873
|
-
const argument = args[i];
|
|
874
|
-
if (this._isObservable(argument)) {
|
|
875
|
-
const streamId = this._invocationId;
|
|
876
|
-
this._invocationId++;
|
|
877
|
-
// Store the stream for later use
|
|
878
|
-
streams[streamId] = argument;
|
|
879
|
-
streamIds.push(streamId.toString());
|
|
880
|
-
// remove stream from args
|
|
881
|
-
args.splice(i, 1);
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
return [streams, streamIds];
|
|
885
|
-
}
|
|
886
|
-
_isObservable(arg) {
|
|
887
|
-
// This allows other stream implementations to just work (like rxjs)
|
|
888
|
-
return arg && arg.subscribe && typeof arg.subscribe === "function";
|
|
889
|
-
}
|
|
890
|
-
_createStreamInvocation(methodName, args, streamIds) {
|
|
891
|
-
const invocationId = this._invocationId;
|
|
892
|
-
this._invocationId++;
|
|
893
|
-
if (streamIds.length !== 0) {
|
|
894
|
-
return {
|
|
895
|
-
target: methodName,
|
|
896
|
-
arguments: args,
|
|
897
|
-
invocationId: invocationId.toString(),
|
|
898
|
-
streamIds,
|
|
899
|
-
type: MessageType.StreamInvocation,
|
|
900
|
-
};
|
|
901
|
-
}
|
|
902
|
-
else {
|
|
903
|
-
return {
|
|
904
|
-
target: methodName,
|
|
905
|
-
arguments: args,
|
|
906
|
-
invocationId: invocationId.toString(),
|
|
907
|
-
type: MessageType.StreamInvocation,
|
|
908
|
-
};
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
_createCancelInvocation(id) {
|
|
912
|
-
return {
|
|
913
|
-
invocationId: id,
|
|
914
|
-
type: MessageType.CancelInvocation,
|
|
915
|
-
};
|
|
916
|
-
}
|
|
917
|
-
_createStreamItemMessage(id, item) {
|
|
918
|
-
return {
|
|
919
|
-
invocationId: id,
|
|
920
|
-
item,
|
|
921
|
-
type: MessageType.StreamItem,
|
|
922
|
-
};
|
|
923
|
-
}
|
|
924
|
-
_createCompletionMessage(id, error, result) {
|
|
925
|
-
if (error) {
|
|
926
|
-
return {
|
|
927
|
-
error,
|
|
928
|
-
invocationId: id,
|
|
929
|
-
type: MessageType.Completion,
|
|
930
|
-
};
|
|
931
|
-
}
|
|
932
|
-
return {
|
|
933
|
-
invocationId: id,
|
|
934
|
-
result,
|
|
935
|
-
type: MessageType.Completion,
|
|
936
|
-
};
|
|
937
|
-
}
|
|
938
|
-
_createCloseMessage() {
|
|
939
|
-
return { type: MessageType.Close };
|
|
940
|
-
}
|
|
941
|
-
async _trySendPingMessage() {
|
|
942
|
-
try {
|
|
943
|
-
await this._sendMessage(this._cachedPingMessage);
|
|
944
|
-
}
|
|
945
|
-
catch {
|
|
946
|
-
// We don't care about the error. It should be seen elsewhere in the client.
|
|
947
|
-
// The connection is probably in a bad or closed state now, cleanup the timer so it stops triggering
|
|
948
|
-
this._cleanupPingTimer();
|
|
949
|
-
}
|
|
950
|
-
}
|
|
1
|
+
import { HandshakeProtocol } from "./HandshakeProtocol.js";
|
|
2
|
+
import { AbortError } from "./Errors.js";
|
|
3
|
+
import { MessageType } from "./IHubProtocol.js";
|
|
4
|
+
import { LogLevel } from "./ILogger.js";
|
|
5
|
+
import { Subject } from "./Subject.js";
|
|
6
|
+
import { Arg, Platform, getErrorString } from "./Utils.js";
|
|
7
|
+
import { MessageBuffer } from "./MessageBuffer.js";
|
|
8
|
+
const DEFAULT_TIMEOUT_IN_MS = 30 * 1e3;
|
|
9
|
+
const DEFAULT_PING_INTERVAL_IN_MS = 15 * 1e3;
|
|
10
|
+
const DEFAULT_STATEFUL_RECONNECT_BUFFER_SIZE = 1e5;
|
|
11
|
+
var HubConnectionState;
|
|
12
|
+
(function(HubConnectionState2) {
|
|
13
|
+
HubConnectionState2["Disconnected"] = "Disconnected";
|
|
14
|
+
HubConnectionState2["Connecting"] = "Connecting";
|
|
15
|
+
HubConnectionState2["Connected"] = "Connected";
|
|
16
|
+
HubConnectionState2["Disconnecting"] = "Disconnecting";
|
|
17
|
+
HubConnectionState2["Reconnecting"] = "Reconnecting";
|
|
18
|
+
})(HubConnectionState || (HubConnectionState = {}));
|
|
19
|
+
class HubConnection {
|
|
20
|
+
/** @internal */
|
|
21
|
+
// Using a public static factory method means we can have a private constructor and an _internal_
|
|
22
|
+
// create method that can be used by HubConnectionBuilder. An "internal" constructor would just
|
|
23
|
+
// be stripped away and the '.d.ts' file would have no constructor, which is interpreted as a
|
|
24
|
+
// public parameter-less constructor.
|
|
25
|
+
static create(connection, logger, protocol, reconnectPolicy, serverTimeoutInMilliseconds, keepAliveIntervalInMilliseconds, statefulReconnectBufferSize) {
|
|
26
|
+
return new HubConnection(connection, logger, protocol, reconnectPolicy, serverTimeoutInMilliseconds, keepAliveIntervalInMilliseconds, statefulReconnectBufferSize);
|
|
27
|
+
}
|
|
28
|
+
constructor(connection, logger, protocol, reconnectPolicy, serverTimeoutInMilliseconds, keepAliveIntervalInMilliseconds, statefulReconnectBufferSize) {
|
|
29
|
+
this._nextKeepAlive = 0;
|
|
30
|
+
this._freezeEventListener = () => {
|
|
31
|
+
this._logger.log(LogLevel.Warning, "The page is being frozen, this will likely lead to the connection being closed and messages being lost. For more information see the docs at https://learn.microsoft.com/aspnet/core/signalr/javascript-client#bsleep");
|
|
32
|
+
};
|
|
33
|
+
Arg.isRequired(connection, "connection");
|
|
34
|
+
Arg.isRequired(logger, "logger");
|
|
35
|
+
Arg.isRequired(protocol, "protocol");
|
|
36
|
+
this.serverTimeoutInMilliseconds = serverTimeoutInMilliseconds !== null && serverTimeoutInMilliseconds !== void 0 ? serverTimeoutInMilliseconds : DEFAULT_TIMEOUT_IN_MS;
|
|
37
|
+
this.keepAliveIntervalInMilliseconds = keepAliveIntervalInMilliseconds !== null && keepAliveIntervalInMilliseconds !== void 0 ? keepAliveIntervalInMilliseconds : DEFAULT_PING_INTERVAL_IN_MS;
|
|
38
|
+
this._statefulReconnectBufferSize = statefulReconnectBufferSize !== null && statefulReconnectBufferSize !== void 0 ? statefulReconnectBufferSize : DEFAULT_STATEFUL_RECONNECT_BUFFER_SIZE;
|
|
39
|
+
this._logger = logger;
|
|
40
|
+
this._protocol = protocol;
|
|
41
|
+
this.connection = connection;
|
|
42
|
+
this._reconnectPolicy = reconnectPolicy;
|
|
43
|
+
this._handshakeProtocol = new HandshakeProtocol();
|
|
44
|
+
this.connection.onreceive = (data) => this._processIncomingData(data);
|
|
45
|
+
this.connection.onclose = (error) => this._connectionClosed(error);
|
|
46
|
+
this._callbacks = {};
|
|
47
|
+
this._methods = {};
|
|
48
|
+
this._closedCallbacks = [];
|
|
49
|
+
this._reconnectingCallbacks = [];
|
|
50
|
+
this._reconnectedCallbacks = [];
|
|
51
|
+
this._invocationId = 0;
|
|
52
|
+
this._receivedHandshakeResponse = false;
|
|
53
|
+
this._connectionState = HubConnectionState.Disconnected;
|
|
54
|
+
this._connectionStarted = false;
|
|
55
|
+
this._cachedPingMessage = this._protocol.writeMessage({ type: MessageType.Ping });
|
|
56
|
+
}
|
|
57
|
+
/** Indicates the state of the {@link HubConnection} to the server. */
|
|
58
|
+
get state() {
|
|
59
|
+
return this._connectionState;
|
|
60
|
+
}
|
|
61
|
+
/** Represents the connection id of the {@link HubConnection} on the server. The connection id will be null when the connection is either
|
|
62
|
+
* in the disconnected state or if the negotiation step was skipped.
|
|
63
|
+
*/
|
|
64
|
+
get connectionId() {
|
|
65
|
+
return this.connection ? this.connection.connectionId || null : null;
|
|
66
|
+
}
|
|
67
|
+
/** Indicates the url of the {@link HubConnection} to the server. */
|
|
68
|
+
get baseUrl() {
|
|
69
|
+
return this.connection.baseUrl || "";
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Sets a new url for the HubConnection. Note that the url can only be changed when the connection is in either the Disconnected or
|
|
73
|
+
* Reconnecting states.
|
|
74
|
+
* @param {string} url The url to connect to.
|
|
75
|
+
*/
|
|
76
|
+
set baseUrl(url) {
|
|
77
|
+
if (this._connectionState !== HubConnectionState.Disconnected && this._connectionState !== HubConnectionState.Reconnecting) {
|
|
78
|
+
throw new Error("The HubConnection must be in the Disconnected or Reconnecting state to change the url.");
|
|
79
|
+
}
|
|
80
|
+
if (!url) {
|
|
81
|
+
throw new Error("The HubConnection url must be a valid url.");
|
|
82
|
+
}
|
|
83
|
+
this.connection.baseUrl = url;
|
|
84
|
+
}
|
|
85
|
+
/** Starts the connection.
|
|
86
|
+
*
|
|
87
|
+
* @returns {Promise<void>} A Promise that resolves when the connection has been successfully established, or rejects with an error.
|
|
88
|
+
*/
|
|
89
|
+
start() {
|
|
90
|
+
this._startPromise = this._startWithStateTransitions();
|
|
91
|
+
return this._startPromise;
|
|
92
|
+
}
|
|
93
|
+
async _startWithStateTransitions() {
|
|
94
|
+
if (this._connectionState !== HubConnectionState.Disconnected) {
|
|
95
|
+
return Promise.reject(new Error("Cannot start a HubConnection that is not in the 'Disconnected' state."));
|
|
96
|
+
}
|
|
97
|
+
this._connectionState = HubConnectionState.Connecting;
|
|
98
|
+
this._logger.log(LogLevel.Debug, "Starting HubConnection.");
|
|
99
|
+
try {
|
|
100
|
+
await this._startInternal();
|
|
101
|
+
if (Platform.isBrowser) {
|
|
102
|
+
window.document.addEventListener("freeze", this._freezeEventListener);
|
|
103
|
+
}
|
|
104
|
+
this._connectionState = HubConnectionState.Connected;
|
|
105
|
+
this._connectionStarted = true;
|
|
106
|
+
this._logger.log(LogLevel.Debug, "HubConnection connected successfully.");
|
|
107
|
+
} catch (e) {
|
|
108
|
+
this._connectionState = HubConnectionState.Disconnected;
|
|
109
|
+
this._logger.log(LogLevel.Debug, `HubConnection failed to start successfully because of error '${e}'.`);
|
|
110
|
+
return Promise.reject(e);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
async _startInternal() {
|
|
114
|
+
this._stopDuringStartError = void 0;
|
|
115
|
+
this._receivedHandshakeResponse = false;
|
|
116
|
+
const handshakePromise = new Promise((resolve, reject) => {
|
|
117
|
+
this._handshakeResolver = resolve;
|
|
118
|
+
this._handshakeRejecter = reject;
|
|
119
|
+
});
|
|
120
|
+
await this.connection.start(this._protocol.transferFormat);
|
|
121
|
+
try {
|
|
122
|
+
let version = this._protocol.version;
|
|
123
|
+
if (!this.connection.features.reconnect) {
|
|
124
|
+
version = 1;
|
|
125
|
+
}
|
|
126
|
+
const handshakeRequest = {
|
|
127
|
+
protocol: this._protocol.name,
|
|
128
|
+
version
|
|
129
|
+
};
|
|
130
|
+
this._logger.log(LogLevel.Debug, "Sending handshake request.");
|
|
131
|
+
await this._sendMessage(this._handshakeProtocol.writeHandshakeRequest(handshakeRequest));
|
|
132
|
+
this._logger.log(LogLevel.Information, `Using HubProtocol '${this._protocol.name}'.`);
|
|
133
|
+
this._cleanupTimeout();
|
|
134
|
+
this._resetTimeoutPeriod();
|
|
135
|
+
this._resetKeepAliveInterval();
|
|
136
|
+
await handshakePromise;
|
|
137
|
+
if (this._stopDuringStartError) {
|
|
138
|
+
throw this._stopDuringStartError;
|
|
139
|
+
}
|
|
140
|
+
const useStatefulReconnect = this.connection.features.reconnect || false;
|
|
141
|
+
if (useStatefulReconnect) {
|
|
142
|
+
this._messageBuffer = new MessageBuffer(this._protocol, this.connection, this._statefulReconnectBufferSize);
|
|
143
|
+
this.connection.features.disconnected = this._messageBuffer._disconnected.bind(this._messageBuffer);
|
|
144
|
+
this.connection.features.resend = () => {
|
|
145
|
+
if (this._messageBuffer) {
|
|
146
|
+
return this._messageBuffer._resend();
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
if (!this.connection.features.inherentKeepAlive) {
|
|
151
|
+
await this._sendMessage(this._cachedPingMessage);
|
|
152
|
+
}
|
|
153
|
+
} catch (e) {
|
|
154
|
+
this._logger.log(LogLevel.Debug, `Hub handshake failed with error '${e}' during start(). Stopping HubConnection.`);
|
|
155
|
+
this._cleanupTimeout();
|
|
156
|
+
this._cleanupPingTimer();
|
|
157
|
+
await this.connection.stop(e);
|
|
158
|
+
throw e;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/** Stops the connection.
|
|
162
|
+
*
|
|
163
|
+
* @returns {Promise<void>} A Promise that resolves when the connection has been successfully terminated, or rejects with an error.
|
|
164
|
+
*/
|
|
165
|
+
async stop() {
|
|
166
|
+
const startPromise = this._startPromise;
|
|
167
|
+
this.connection.features.reconnect = false;
|
|
168
|
+
this._stopPromise = this._stopInternal();
|
|
169
|
+
await this._stopPromise;
|
|
170
|
+
try {
|
|
171
|
+
await startPromise;
|
|
172
|
+
} catch (e) {
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
_stopInternal(error) {
|
|
176
|
+
if (this._connectionState === HubConnectionState.Disconnected) {
|
|
177
|
+
this._logger.log(LogLevel.Debug, `Call to HubConnection.stop(${error}) ignored because it is already in the disconnected state.`);
|
|
178
|
+
return Promise.resolve();
|
|
179
|
+
}
|
|
180
|
+
if (this._connectionState === HubConnectionState.Disconnecting) {
|
|
181
|
+
this._logger.log(LogLevel.Debug, `Call to HttpConnection.stop(${error}) ignored because the connection is already in the disconnecting state.`);
|
|
182
|
+
return this._stopPromise;
|
|
183
|
+
}
|
|
184
|
+
const state = this._connectionState;
|
|
185
|
+
this._connectionState = HubConnectionState.Disconnecting;
|
|
186
|
+
this._logger.log(LogLevel.Debug, "Stopping HubConnection.");
|
|
187
|
+
if (this._reconnectDelayHandle) {
|
|
188
|
+
this._logger.log(LogLevel.Debug, "Connection stopped during reconnect delay. Done reconnecting.");
|
|
189
|
+
clearTimeout(this._reconnectDelayHandle);
|
|
190
|
+
this._reconnectDelayHandle = void 0;
|
|
191
|
+
this._completeClose();
|
|
192
|
+
return Promise.resolve();
|
|
193
|
+
}
|
|
194
|
+
if (state === HubConnectionState.Connected) {
|
|
195
|
+
this._sendCloseMessage();
|
|
196
|
+
}
|
|
197
|
+
this._cleanupTimeout();
|
|
198
|
+
this._cleanupPingTimer();
|
|
199
|
+
this._stopDuringStartError = error || new AbortError("The connection was stopped before the hub handshake could complete.");
|
|
200
|
+
return this.connection.stop(error);
|
|
201
|
+
}
|
|
202
|
+
async _sendCloseMessage() {
|
|
203
|
+
try {
|
|
204
|
+
await this._sendWithProtocol(this._createCloseMessage());
|
|
205
|
+
} catch {
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/** Invokes a streaming hub method on the server using the specified name and arguments.
|
|
209
|
+
*
|
|
210
|
+
* @typeparam T The type of the items returned by the server.
|
|
211
|
+
* @param {string} methodName The name of the server method to invoke.
|
|
212
|
+
* @param {any[]} args The arguments used to invoke the server method.
|
|
213
|
+
* @returns {IStreamResult<T>} An object that yields results from the server as they are received.
|
|
214
|
+
*/
|
|
215
|
+
stream(methodName, ...args) {
|
|
216
|
+
const [streams, streamIds] = this._replaceStreamingParams(args);
|
|
217
|
+
const invocationDescriptor = this._createStreamInvocation(methodName, args, streamIds);
|
|
218
|
+
let promiseQueue;
|
|
219
|
+
const subject = new Subject();
|
|
220
|
+
subject.cancelCallback = () => {
|
|
221
|
+
const cancelInvocation = this._createCancelInvocation(invocationDescriptor.invocationId);
|
|
222
|
+
delete this._callbacks[invocationDescriptor.invocationId];
|
|
223
|
+
return promiseQueue.then(() => {
|
|
224
|
+
return this._sendWithProtocol(cancelInvocation);
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
this._callbacks[invocationDescriptor.invocationId] = (invocationEvent, error) => {
|
|
228
|
+
if (error) {
|
|
229
|
+
subject.error(error);
|
|
230
|
+
return;
|
|
231
|
+
} else if (invocationEvent) {
|
|
232
|
+
if (invocationEvent.type === MessageType.Completion) {
|
|
233
|
+
if (invocationEvent.error) {
|
|
234
|
+
subject.error(new Error(invocationEvent.error));
|
|
235
|
+
} else {
|
|
236
|
+
subject.complete();
|
|
237
|
+
}
|
|
238
|
+
} else {
|
|
239
|
+
subject.next(invocationEvent.item);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
promiseQueue = this._sendWithProtocol(invocationDescriptor).catch((e) => {
|
|
244
|
+
subject.error(e);
|
|
245
|
+
delete this._callbacks[invocationDescriptor.invocationId];
|
|
246
|
+
});
|
|
247
|
+
this._launchStreams(streams, promiseQueue);
|
|
248
|
+
return subject;
|
|
249
|
+
}
|
|
250
|
+
_sendMessage(message) {
|
|
251
|
+
this._resetKeepAliveInterval();
|
|
252
|
+
return this.connection.send(message);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Sends a js object to the server.
|
|
256
|
+
* @param message The js object to serialize and send.
|
|
257
|
+
*/
|
|
258
|
+
_sendWithProtocol(message) {
|
|
259
|
+
if (this._messageBuffer) {
|
|
260
|
+
return this._messageBuffer._send(message);
|
|
261
|
+
} else {
|
|
262
|
+
return this._sendMessage(this._protocol.writeMessage(message));
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/** Invokes a hub method on the server using the specified name and arguments. Does not wait for a response from the receiver.
|
|
266
|
+
*
|
|
267
|
+
* The Promise returned by this method resolves when the client has sent the invocation to the server. The server may still
|
|
268
|
+
* be processing the invocation.
|
|
269
|
+
*
|
|
270
|
+
* @param {string} methodName The name of the server method to invoke.
|
|
271
|
+
* @param {any[]} args The arguments used to invoke the server method.
|
|
272
|
+
* @returns {Promise<void>} A Promise that resolves when the invocation has been successfully sent, or rejects with an error.
|
|
273
|
+
*/
|
|
274
|
+
send(methodName, ...args) {
|
|
275
|
+
const [streams, streamIds] = this._replaceStreamingParams(args);
|
|
276
|
+
const sendPromise = this._sendWithProtocol(this._createInvocation(methodName, args, true, streamIds));
|
|
277
|
+
this._launchStreams(streams, sendPromise);
|
|
278
|
+
return sendPromise;
|
|
279
|
+
}
|
|
280
|
+
/** Invokes a hub method on the server using the specified name and arguments.
|
|
281
|
+
*
|
|
282
|
+
* The Promise returned by this method resolves when the server indicates it has finished invoking the method. When the promise
|
|
283
|
+
* resolves, the server has finished invoking the method. If the server method returns a result, it is produced as the result of
|
|
284
|
+
* resolving the Promise.
|
|
285
|
+
*
|
|
286
|
+
* @typeparam T The expected return type.
|
|
287
|
+
* @param {string} methodName The name of the server method to invoke.
|
|
288
|
+
* @param {any[]} args The arguments used to invoke the server method.
|
|
289
|
+
* @returns {Promise<T>} A Promise that resolves with the result of the server method (if any), or rejects with an error.
|
|
290
|
+
*/
|
|
291
|
+
invoke(methodName, ...args) {
|
|
292
|
+
const [streams, streamIds] = this._replaceStreamingParams(args);
|
|
293
|
+
const invocationDescriptor = this._createInvocation(methodName, args, false, streamIds);
|
|
294
|
+
const p = new Promise((resolve, reject) => {
|
|
295
|
+
this._callbacks[invocationDescriptor.invocationId] = (invocationEvent, error) => {
|
|
296
|
+
if (error) {
|
|
297
|
+
reject(error);
|
|
298
|
+
return;
|
|
299
|
+
} else if (invocationEvent) {
|
|
300
|
+
if (invocationEvent.type === MessageType.Completion) {
|
|
301
|
+
if (invocationEvent.error) {
|
|
302
|
+
reject(new Error(invocationEvent.error));
|
|
303
|
+
} else {
|
|
304
|
+
resolve(invocationEvent.result);
|
|
305
|
+
}
|
|
306
|
+
} else {
|
|
307
|
+
reject(new Error(`Unexpected message type: ${invocationEvent.type}`));
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
const promiseQueue = this._sendWithProtocol(invocationDescriptor).catch((e) => {
|
|
312
|
+
reject(e);
|
|
313
|
+
delete this._callbacks[invocationDescriptor.invocationId];
|
|
314
|
+
});
|
|
315
|
+
this._launchStreams(streams, promiseQueue);
|
|
316
|
+
});
|
|
317
|
+
return p;
|
|
318
|
+
}
|
|
319
|
+
on(methodName, newMethod) {
|
|
320
|
+
if (!methodName || !newMethod) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
methodName = methodName.toLowerCase();
|
|
324
|
+
if (!this._methods[methodName]) {
|
|
325
|
+
this._methods[methodName] = [];
|
|
326
|
+
}
|
|
327
|
+
if (this._methods[methodName].indexOf(newMethod) !== -1) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
this._methods[methodName].push(newMethod);
|
|
331
|
+
}
|
|
332
|
+
off(methodName, method) {
|
|
333
|
+
if (!methodName) {
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
methodName = methodName.toLowerCase();
|
|
337
|
+
const handlers = this._methods[methodName];
|
|
338
|
+
if (!handlers) {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
if (method) {
|
|
342
|
+
const removeIdx = handlers.indexOf(method);
|
|
343
|
+
if (removeIdx !== -1) {
|
|
344
|
+
handlers.splice(removeIdx, 1);
|
|
345
|
+
if (handlers.length === 0) {
|
|
346
|
+
delete this._methods[methodName];
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
} else {
|
|
350
|
+
delete this._methods[methodName];
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
/** Registers a handler that will be invoked when the connection is closed.
|
|
354
|
+
*
|
|
355
|
+
* @param {Function} callback The handler that will be invoked when the connection is closed. Optionally receives a single argument containing the error that caused the connection to close (if any).
|
|
356
|
+
*/
|
|
357
|
+
onclose(callback) {
|
|
358
|
+
if (callback) {
|
|
359
|
+
this._closedCallbacks.push(callback);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
/** Registers a handler that will be invoked when the connection starts reconnecting.
|
|
363
|
+
*
|
|
364
|
+
* @param {Function} callback The handler that will be invoked when the connection starts reconnecting. Optionally receives a single argument containing the error that caused the connection to start reconnecting (if any).
|
|
365
|
+
*/
|
|
366
|
+
onreconnecting(callback) {
|
|
367
|
+
if (callback) {
|
|
368
|
+
this._reconnectingCallbacks.push(callback);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
/** Registers a handler that will be invoked when the connection successfully reconnects.
|
|
372
|
+
*
|
|
373
|
+
* @param {Function} callback The handler that will be invoked when the connection successfully reconnects.
|
|
374
|
+
*/
|
|
375
|
+
onreconnected(callback) {
|
|
376
|
+
if (callback) {
|
|
377
|
+
this._reconnectedCallbacks.push(callback);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
_processIncomingData(data) {
|
|
381
|
+
this._cleanupTimeout();
|
|
382
|
+
if (!this._receivedHandshakeResponse) {
|
|
383
|
+
data = this._processHandshakeResponse(data);
|
|
384
|
+
this._receivedHandshakeResponse = true;
|
|
385
|
+
}
|
|
386
|
+
if (data) {
|
|
387
|
+
const messages = this._protocol.parseMessages(data, this._logger);
|
|
388
|
+
for (const message of messages) {
|
|
389
|
+
if (this._messageBuffer && !this._messageBuffer._shouldProcessMessage(message)) {
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
switch (message.type) {
|
|
393
|
+
case MessageType.Invocation:
|
|
394
|
+
this._invokeClientMethod(message).catch((e) => {
|
|
395
|
+
this._logger.log(LogLevel.Error, `Invoke client method threw error: ${getErrorString(e)}`);
|
|
396
|
+
});
|
|
397
|
+
break;
|
|
398
|
+
case MessageType.StreamItem:
|
|
399
|
+
case MessageType.Completion: {
|
|
400
|
+
const callback = this._callbacks[message.invocationId];
|
|
401
|
+
if (callback) {
|
|
402
|
+
if (message.type === MessageType.Completion) {
|
|
403
|
+
delete this._callbacks[message.invocationId];
|
|
404
|
+
}
|
|
405
|
+
try {
|
|
406
|
+
callback(message);
|
|
407
|
+
} catch (e) {
|
|
408
|
+
this._logger.log(LogLevel.Error, `Stream callback threw error: ${getErrorString(e)}`);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
break;
|
|
412
|
+
}
|
|
413
|
+
case MessageType.Ping:
|
|
414
|
+
break;
|
|
415
|
+
case MessageType.Close: {
|
|
416
|
+
this._logger.log(LogLevel.Information, "Close message received from server.");
|
|
417
|
+
const error = message.error ? new Error("Server returned an error on close: " + message.error) : void 0;
|
|
418
|
+
if (message.allowReconnect === true) {
|
|
419
|
+
this.connection.stop(error);
|
|
420
|
+
} else {
|
|
421
|
+
this._stopPromise = this._stopInternal(error);
|
|
422
|
+
}
|
|
423
|
+
break;
|
|
424
|
+
}
|
|
425
|
+
case MessageType.Ack:
|
|
426
|
+
if (this._messageBuffer) {
|
|
427
|
+
this._messageBuffer._ack(message);
|
|
428
|
+
}
|
|
429
|
+
break;
|
|
430
|
+
case MessageType.Sequence:
|
|
431
|
+
if (this._messageBuffer) {
|
|
432
|
+
this._messageBuffer._resetSequence(message);
|
|
433
|
+
}
|
|
434
|
+
break;
|
|
435
|
+
default:
|
|
436
|
+
this._logger.log(LogLevel.Warning, `Invalid message type: ${message.type}.`);
|
|
437
|
+
break;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
this._resetTimeoutPeriod();
|
|
442
|
+
}
|
|
443
|
+
_processHandshakeResponse(data) {
|
|
444
|
+
let responseMessage;
|
|
445
|
+
let remainingData;
|
|
446
|
+
try {
|
|
447
|
+
[remainingData, responseMessage] = this._handshakeProtocol.parseHandshakeResponse(data);
|
|
448
|
+
} catch (e) {
|
|
449
|
+
const message = "Error parsing handshake response: " + e;
|
|
450
|
+
this._logger.log(LogLevel.Error, message);
|
|
451
|
+
const error = new Error(message);
|
|
452
|
+
this._handshakeRejecter(error);
|
|
453
|
+
throw error;
|
|
454
|
+
}
|
|
455
|
+
if (responseMessage.error) {
|
|
456
|
+
const message = "Server returned handshake error: " + responseMessage.error;
|
|
457
|
+
this._logger.log(LogLevel.Error, message);
|
|
458
|
+
const error = new Error(message);
|
|
459
|
+
this._handshakeRejecter(error);
|
|
460
|
+
throw error;
|
|
461
|
+
} else {
|
|
462
|
+
this._logger.log(LogLevel.Debug, "Server handshake complete.");
|
|
463
|
+
}
|
|
464
|
+
this._handshakeResolver();
|
|
465
|
+
return remainingData;
|
|
466
|
+
}
|
|
467
|
+
_resetKeepAliveInterval() {
|
|
468
|
+
if (this.connection.features.inherentKeepAlive) {
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
this._nextKeepAlive = (/* @__PURE__ */ new Date()).getTime() + this.keepAliveIntervalInMilliseconds;
|
|
472
|
+
this._cleanupPingTimer();
|
|
473
|
+
}
|
|
474
|
+
_resetTimeoutPeriod() {
|
|
475
|
+
if (!this.connection.features || !this.connection.features.inherentKeepAlive) {
|
|
476
|
+
this._timeoutHandle = setTimeout(() => this.serverTimeout(), this.serverTimeoutInMilliseconds);
|
|
477
|
+
let nextPing = this._nextKeepAlive - (/* @__PURE__ */ new Date()).getTime();
|
|
478
|
+
if (nextPing < 0) {
|
|
479
|
+
if (this._connectionState === HubConnectionState.Connected) {
|
|
480
|
+
this._trySendPingMessage();
|
|
481
|
+
}
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
if (this._pingServerHandle === void 0) {
|
|
485
|
+
if (nextPing < 0) {
|
|
486
|
+
nextPing = 0;
|
|
487
|
+
}
|
|
488
|
+
this._pingServerHandle = setTimeout(async () => {
|
|
489
|
+
if (this._connectionState === HubConnectionState.Connected) {
|
|
490
|
+
await this._trySendPingMessage();
|
|
491
|
+
}
|
|
492
|
+
}, nextPing);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
497
|
+
serverTimeout() {
|
|
498
|
+
this.connection.stop(new Error("Server timeout elapsed without receiving a message from the server."));
|
|
499
|
+
}
|
|
500
|
+
async _invokeClientMethod(invocationMessage) {
|
|
501
|
+
const methodName = invocationMessage.target.toLowerCase();
|
|
502
|
+
const methods = this._methods[methodName];
|
|
503
|
+
if (!methods) {
|
|
504
|
+
this._logger.log(LogLevel.Warning, `No client method with the name '${methodName}' found.`);
|
|
505
|
+
if (invocationMessage.invocationId) {
|
|
506
|
+
this._logger.log(LogLevel.Warning, `No result given for '${methodName}' method and invocation ID '${invocationMessage.invocationId}'.`);
|
|
507
|
+
await this._sendWithProtocol(this._createCompletionMessage(invocationMessage.invocationId, "Client didn't provide a result.", null));
|
|
508
|
+
}
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
const methodsCopy = methods.slice();
|
|
512
|
+
const expectsResponse = invocationMessage.invocationId ? true : false;
|
|
513
|
+
let res;
|
|
514
|
+
let exception;
|
|
515
|
+
let completionMessage;
|
|
516
|
+
for (const m of methodsCopy) {
|
|
517
|
+
try {
|
|
518
|
+
const prevRes = res;
|
|
519
|
+
res = await m.apply(this, invocationMessage.arguments);
|
|
520
|
+
if (expectsResponse && res && prevRes) {
|
|
521
|
+
this._logger.log(LogLevel.Error, `Multiple results provided for '${methodName}'. Sending error to server.`);
|
|
522
|
+
completionMessage = this._createCompletionMessage(invocationMessage.invocationId, `Client provided multiple results.`, null);
|
|
523
|
+
}
|
|
524
|
+
exception = void 0;
|
|
525
|
+
} catch (e) {
|
|
526
|
+
exception = e;
|
|
527
|
+
this._logger.log(LogLevel.Error, `A callback for the method '${methodName}' threw error '${e}'.`);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
if (completionMessage) {
|
|
531
|
+
await this._sendWithProtocol(completionMessage);
|
|
532
|
+
} else if (expectsResponse) {
|
|
533
|
+
if (exception) {
|
|
534
|
+
completionMessage = this._createCompletionMessage(invocationMessage.invocationId, `${exception}`, null);
|
|
535
|
+
} else if (res !== void 0) {
|
|
536
|
+
completionMessage = this._createCompletionMessage(invocationMessage.invocationId, null, res);
|
|
537
|
+
} else {
|
|
538
|
+
this._logger.log(LogLevel.Warning, `No result given for '${methodName}' method and invocation ID '${invocationMessage.invocationId}'.`);
|
|
539
|
+
completionMessage = this._createCompletionMessage(invocationMessage.invocationId, "Client didn't provide a result.", null);
|
|
540
|
+
}
|
|
541
|
+
await this._sendWithProtocol(completionMessage);
|
|
542
|
+
} else {
|
|
543
|
+
if (res) {
|
|
544
|
+
this._logger.log(LogLevel.Error, `Result given for '${methodName}' method but server is not expecting a result.`);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
_connectionClosed(error) {
|
|
549
|
+
this._logger.log(LogLevel.Debug, `HubConnection.connectionClosed(${error}) called while in state ${this._connectionState}.`);
|
|
550
|
+
this._stopDuringStartError = this._stopDuringStartError || error || new AbortError("The underlying connection was closed before the hub handshake could complete.");
|
|
551
|
+
if (this._handshakeResolver) {
|
|
552
|
+
this._handshakeResolver();
|
|
553
|
+
}
|
|
554
|
+
this._cancelCallbacksWithError(error || new Error("Invocation canceled due to the underlying connection being closed."));
|
|
555
|
+
this._cleanupTimeout();
|
|
556
|
+
this._cleanupPingTimer();
|
|
557
|
+
if (this._connectionState === HubConnectionState.Disconnecting) {
|
|
558
|
+
this._completeClose(error);
|
|
559
|
+
} else if (this._connectionState === HubConnectionState.Connected && this._reconnectPolicy) {
|
|
560
|
+
this._reconnect(error);
|
|
561
|
+
} else if (this._connectionState === HubConnectionState.Connected) {
|
|
562
|
+
this._completeClose(error);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
_completeClose(error) {
|
|
566
|
+
if (this._connectionStarted) {
|
|
567
|
+
this._connectionState = HubConnectionState.Disconnected;
|
|
568
|
+
this._connectionStarted = false;
|
|
569
|
+
if (this._messageBuffer) {
|
|
570
|
+
this._messageBuffer._dispose(error !== null && error !== void 0 ? error : new Error("Connection closed."));
|
|
571
|
+
this._messageBuffer = void 0;
|
|
572
|
+
}
|
|
573
|
+
if (Platform.isBrowser) {
|
|
574
|
+
window.document.removeEventListener("freeze", this._freezeEventListener);
|
|
575
|
+
}
|
|
576
|
+
try {
|
|
577
|
+
this._closedCallbacks.forEach((c) => c.apply(this, [error]));
|
|
578
|
+
} catch (e) {
|
|
579
|
+
this._logger.log(LogLevel.Error, `An onclose callback called with error '${error}' threw error '${e}'.`);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
async _reconnect(error) {
|
|
584
|
+
const reconnectStartTime = Date.now();
|
|
585
|
+
let previousReconnectAttempts = 0;
|
|
586
|
+
let retryError = error !== void 0 ? error : new Error("Attempting to reconnect due to a unknown error.");
|
|
587
|
+
let nextRetryDelay = this._getNextRetryDelay(previousReconnectAttempts, 0, retryError);
|
|
588
|
+
if (nextRetryDelay === null) {
|
|
589
|
+
this._logger.log(LogLevel.Debug, "Connection not reconnecting because the IRetryPolicy returned null on the first reconnect attempt.");
|
|
590
|
+
this._completeClose(error);
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
this._connectionState = HubConnectionState.Reconnecting;
|
|
594
|
+
if (error) {
|
|
595
|
+
this._logger.log(LogLevel.Information, `Connection reconnecting because of error '${error}'.`);
|
|
596
|
+
} else {
|
|
597
|
+
this._logger.log(LogLevel.Information, "Connection reconnecting.");
|
|
598
|
+
}
|
|
599
|
+
if (this._reconnectingCallbacks.length !== 0) {
|
|
600
|
+
try {
|
|
601
|
+
this._reconnectingCallbacks.forEach((c) => c.apply(this, [error]));
|
|
602
|
+
} catch (e) {
|
|
603
|
+
this._logger.log(LogLevel.Error, `An onreconnecting callback called with error '${error}' threw error '${e}'.`);
|
|
604
|
+
}
|
|
605
|
+
if (this._connectionState !== HubConnectionState.Reconnecting) {
|
|
606
|
+
this._logger.log(LogLevel.Debug, "Connection left the reconnecting state in onreconnecting callback. Done reconnecting.");
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
while (nextRetryDelay !== null) {
|
|
611
|
+
this._logger.log(LogLevel.Information, `Reconnect attempt number ${previousReconnectAttempts + 1} will start in ${nextRetryDelay} ms.`);
|
|
612
|
+
await new Promise((resolve) => {
|
|
613
|
+
this._reconnectDelayHandle = setTimeout(resolve, nextRetryDelay);
|
|
614
|
+
});
|
|
615
|
+
this._reconnectDelayHandle = void 0;
|
|
616
|
+
if (this._connectionState !== HubConnectionState.Reconnecting) {
|
|
617
|
+
this._logger.log(LogLevel.Debug, "Connection left the reconnecting state during reconnect delay. Done reconnecting.");
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
try {
|
|
621
|
+
await this._startInternal();
|
|
622
|
+
this._connectionState = HubConnectionState.Connected;
|
|
623
|
+
this._logger.log(LogLevel.Information, "HubConnection reconnected successfully.");
|
|
624
|
+
if (this._reconnectedCallbacks.length !== 0) {
|
|
625
|
+
try {
|
|
626
|
+
this._reconnectedCallbacks.forEach((c) => c.apply(this, [this.connection.connectionId]));
|
|
627
|
+
} catch (e) {
|
|
628
|
+
this._logger.log(LogLevel.Error, `An onreconnected callback called with connectionId '${this.connection.connectionId}; threw error '${e}'.`);
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
return;
|
|
632
|
+
} catch (e) {
|
|
633
|
+
this._logger.log(LogLevel.Information, `Reconnect attempt failed because of error '${e}'.`);
|
|
634
|
+
if (this._connectionState !== HubConnectionState.Reconnecting) {
|
|
635
|
+
this._logger.log(LogLevel.Debug, `Connection moved to the '${this._connectionState}' from the reconnecting state during reconnect attempt. Done reconnecting.`);
|
|
636
|
+
if (this._connectionState === HubConnectionState.Disconnecting) {
|
|
637
|
+
this._completeClose();
|
|
638
|
+
}
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
previousReconnectAttempts++;
|
|
642
|
+
retryError = e instanceof Error ? e : new Error(e.toString());
|
|
643
|
+
nextRetryDelay = this._getNextRetryDelay(previousReconnectAttempts, Date.now() - reconnectStartTime, retryError);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
this._logger.log(LogLevel.Information, `Reconnect retries have been exhausted after ${Date.now() - reconnectStartTime} ms and ${previousReconnectAttempts} failed attempts. Connection disconnecting.`);
|
|
647
|
+
this._completeClose();
|
|
648
|
+
}
|
|
649
|
+
_getNextRetryDelay(previousRetryCount, elapsedMilliseconds, retryReason) {
|
|
650
|
+
try {
|
|
651
|
+
return this._reconnectPolicy.nextRetryDelayInMilliseconds({
|
|
652
|
+
elapsedMilliseconds,
|
|
653
|
+
previousRetryCount,
|
|
654
|
+
retryReason
|
|
655
|
+
});
|
|
656
|
+
} catch (e) {
|
|
657
|
+
this._logger.log(LogLevel.Error, `IRetryPolicy.nextRetryDelayInMilliseconds(${previousRetryCount}, ${elapsedMilliseconds}) threw error '${e}'.`);
|
|
658
|
+
return null;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
_cancelCallbacksWithError(error) {
|
|
662
|
+
const callbacks = this._callbacks;
|
|
663
|
+
this._callbacks = {};
|
|
664
|
+
Object.keys(callbacks).forEach((key) => {
|
|
665
|
+
const callback = callbacks[key];
|
|
666
|
+
try {
|
|
667
|
+
callback(null, error);
|
|
668
|
+
} catch (e) {
|
|
669
|
+
this._logger.log(LogLevel.Error, `Stream 'error' callback called with '${error}' threw error: ${getErrorString(e)}`);
|
|
670
|
+
}
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
_cleanupPingTimer() {
|
|
674
|
+
if (this._pingServerHandle) {
|
|
675
|
+
clearTimeout(this._pingServerHandle);
|
|
676
|
+
this._pingServerHandle = void 0;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
_cleanupTimeout() {
|
|
680
|
+
if (this._timeoutHandle) {
|
|
681
|
+
clearTimeout(this._timeoutHandle);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
_createInvocation(methodName, args, nonblocking, streamIds) {
|
|
685
|
+
if (nonblocking) {
|
|
686
|
+
if (streamIds.length !== 0) {
|
|
687
|
+
return {
|
|
688
|
+
target: methodName,
|
|
689
|
+
arguments: args,
|
|
690
|
+
streamIds,
|
|
691
|
+
type: MessageType.Invocation
|
|
692
|
+
};
|
|
693
|
+
} else {
|
|
694
|
+
return {
|
|
695
|
+
target: methodName,
|
|
696
|
+
arguments: args,
|
|
697
|
+
type: MessageType.Invocation
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
} else {
|
|
701
|
+
const invocationId = this._invocationId;
|
|
702
|
+
this._invocationId++;
|
|
703
|
+
if (streamIds.length !== 0) {
|
|
704
|
+
return {
|
|
705
|
+
target: methodName,
|
|
706
|
+
arguments: args,
|
|
707
|
+
invocationId: invocationId.toString(),
|
|
708
|
+
streamIds,
|
|
709
|
+
type: MessageType.Invocation
|
|
710
|
+
};
|
|
711
|
+
} else {
|
|
712
|
+
return {
|
|
713
|
+
target: methodName,
|
|
714
|
+
arguments: args,
|
|
715
|
+
invocationId: invocationId.toString(),
|
|
716
|
+
type: MessageType.Invocation
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
_launchStreams(streams, promiseQueue) {
|
|
722
|
+
if (streams.length === 0) {
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
if (!promiseQueue) {
|
|
726
|
+
promiseQueue = Promise.resolve();
|
|
727
|
+
}
|
|
728
|
+
for (const streamId in streams) {
|
|
729
|
+
streams[streamId].subscribe({
|
|
730
|
+
complete: () => {
|
|
731
|
+
promiseQueue = promiseQueue.then(() => this._sendWithProtocol(this._createCompletionMessage(streamId)));
|
|
732
|
+
},
|
|
733
|
+
error: (err) => {
|
|
734
|
+
let message;
|
|
735
|
+
if (err instanceof Error) {
|
|
736
|
+
message = err.message;
|
|
737
|
+
} else if (err && err.toString) {
|
|
738
|
+
message = err.toString();
|
|
739
|
+
} else {
|
|
740
|
+
message = "Unknown error";
|
|
741
|
+
}
|
|
742
|
+
promiseQueue = promiseQueue.then(() => this._sendWithProtocol(this._createCompletionMessage(streamId, message)));
|
|
743
|
+
},
|
|
744
|
+
next: (item) => {
|
|
745
|
+
promiseQueue = promiseQueue.then(() => this._sendWithProtocol(this._createStreamItemMessage(streamId, item)));
|
|
746
|
+
}
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
_replaceStreamingParams(args) {
|
|
751
|
+
const streams = [];
|
|
752
|
+
const streamIds = [];
|
|
753
|
+
for (let i = 0; i < args.length; i++) {
|
|
754
|
+
const argument = args[i];
|
|
755
|
+
if (this._isObservable(argument)) {
|
|
756
|
+
const streamId = this._invocationId;
|
|
757
|
+
this._invocationId++;
|
|
758
|
+
streams[streamId] = argument;
|
|
759
|
+
streamIds.push(streamId.toString());
|
|
760
|
+
args.splice(i, 1);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
return [streams, streamIds];
|
|
764
|
+
}
|
|
765
|
+
_isObservable(arg) {
|
|
766
|
+
return arg && arg.subscribe && typeof arg.subscribe === "function";
|
|
767
|
+
}
|
|
768
|
+
_createStreamInvocation(methodName, args, streamIds) {
|
|
769
|
+
const invocationId = this._invocationId;
|
|
770
|
+
this._invocationId++;
|
|
771
|
+
if (streamIds.length !== 0) {
|
|
772
|
+
return {
|
|
773
|
+
target: methodName,
|
|
774
|
+
arguments: args,
|
|
775
|
+
invocationId: invocationId.toString(),
|
|
776
|
+
streamIds,
|
|
777
|
+
type: MessageType.StreamInvocation
|
|
778
|
+
};
|
|
779
|
+
} else {
|
|
780
|
+
return {
|
|
781
|
+
target: methodName,
|
|
782
|
+
arguments: args,
|
|
783
|
+
invocationId: invocationId.toString(),
|
|
784
|
+
type: MessageType.StreamInvocation
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
_createCancelInvocation(id) {
|
|
789
|
+
return {
|
|
790
|
+
invocationId: id,
|
|
791
|
+
type: MessageType.CancelInvocation
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
_createStreamItemMessage(id, item) {
|
|
795
|
+
return {
|
|
796
|
+
invocationId: id,
|
|
797
|
+
item,
|
|
798
|
+
type: MessageType.StreamItem
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
_createCompletionMessage(id, error, result) {
|
|
802
|
+
if (error) {
|
|
803
|
+
return {
|
|
804
|
+
error,
|
|
805
|
+
invocationId: id,
|
|
806
|
+
type: MessageType.Completion
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
return {
|
|
810
|
+
invocationId: id,
|
|
811
|
+
result,
|
|
812
|
+
type: MessageType.Completion
|
|
813
|
+
};
|
|
814
|
+
}
|
|
815
|
+
_createCloseMessage() {
|
|
816
|
+
return { type: MessageType.Close };
|
|
817
|
+
}
|
|
818
|
+
async _trySendPingMessage() {
|
|
819
|
+
try {
|
|
820
|
+
await this._sendMessage(this._cachedPingMessage);
|
|
821
|
+
} catch {
|
|
822
|
+
this._cleanupPingTimer();
|
|
823
|
+
}
|
|
824
|
+
}
|
|
951
825
|
}
|
|
952
|
-
|
|
953
|
-
|
|
826
|
+
export {
|
|
827
|
+
HubConnection,
|
|
828
|
+
HubConnectionState
|
|
829
|
+
};
|