@gbraver-burst-network/local-webrtc-browser-sdk 1.20.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/LICENSE.txt +7 -0
  2. package/Readme.md +37 -0
  3. package/lib/index.d.ts +4 -0
  4. package/lib/index.js +7 -0
  5. package/lib/json/parse.d.ts +7 -0
  6. package/lib/json/parse.js +20 -0
  7. package/lib/sdk/battle-sdk.d.ts +25 -0
  8. package/lib/sdk/battle-sdk.js +2 -0
  9. package/lib/sdk/guest-battle-sdk.d.ts +39 -0
  10. package/lib/sdk/guest-battle-sdk.js +73 -0
  11. package/lib/sdk/guest-webrtc-connection-manager.d.ts +19 -0
  12. package/lib/sdk/guest-webrtc-connection-manager.js +52 -0
  13. package/lib/sdk/host-battle-sdk.d.ts +39 -0
  14. package/lib/sdk/host-battle-sdk.js +97 -0
  15. package/lib/sdk/host-webrtc-connection-manager.d.ts +19 -0
  16. package/lib/sdk/host-webrtc-connection-manager.js +51 -0
  17. package/lib/sdk/local-webrtc-guest-sdk.d.ts +34 -0
  18. package/lib/sdk/local-webrtc-guest-sdk.js +136 -0
  19. package/lib/sdk/local-webrtc-host-sdk.d.ts +32 -0
  20. package/lib/sdk/local-webrtc-host-sdk.js +93 -0
  21. package/lib/sdk/local-webrtc-room.d.ts +39 -0
  22. package/lib/sdk/local-webrtc-room.js +106 -0
  23. package/lib/sdk/websocket-connection-manager.d.ts +27 -0
  24. package/lib/sdk/websocket-connection-manager.js +84 -0
  25. package/lib/webrtc/guest/guest-message.d.ts +48 -0
  26. package/lib/webrtc/guest/guest-message.js +27 -0
  27. package/lib/webrtc/guest/receive-battle-progressed.d.ts +7 -0
  28. package/lib/webrtc/guest/receive-battle-progressed.js +29 -0
  29. package/lib/webrtc/guest/receive-battle-start.d.ts +7 -0
  30. package/lib/webrtc/guest/receive-battle-start.js +29 -0
  31. package/lib/webrtc/guest/receive-request-selected-player.d.ts +7 -0
  32. package/lib/webrtc/guest/receive-request-selected-player.js +29 -0
  33. package/lib/webrtc/guest/wait-until-data-channel.d.ts +6 -0
  34. package/lib/webrtc/guest/wait-until-data-channel.js +14 -0
  35. package/lib/webrtc/host/host-message.d.ts +1001 -0
  36. package/lib/webrtc/host/host-message.js +33 -0
  37. package/lib/webrtc/host/receive-send-command.d.ts +8 -0
  38. package/lib/webrtc/host/receive-send-command.js +31 -0
  39. package/lib/webrtc/host/request-selected-player.d.ts +16 -0
  40. package/lib/webrtc/host/request-selected-player.js +35 -0
  41. package/lib/webrtc/rtc-ice-candidate-init-schema.d.ts +8 -0
  42. package/lib/webrtc/rtc-ice-candidate-init-schema.js +11 -0
  43. package/lib/webrtc/rtc-session-description-init-schema.d.ts +11 -0
  44. package/lib/webrtc/rtc-session-description-init-schema.js +9 -0
  45. package/lib/webrtc/signal.d.ts +5 -0
  46. package/lib/webrtc/signal.js +2 -0
  47. package/lib/webrtc/wait-until-connected.d.ts +6 -0
  48. package/lib/webrtc/wait-until-connected.js +28 -0
  49. package/lib/webrtc/wait-until-data-channel-ready.d.ts +6 -0
  50. package/lib/webrtc/wait-until-data-channel-ready.js +28 -0
  51. package/lib/webrtc/wait-untilIce-candidate.d.ts +6 -0
  52. package/lib/webrtc/wait-untilIce-candidate.js +28 -0
  53. package/lib/ws-signal/connect-ws-signal.d.ts +6 -0
  54. package/lib/ws-signal/connect-ws-signal.js +28 -0
  55. package/lib/ws-signal/create-room.d.ts +13 -0
  56. package/lib/ws-signal/create-room.js +41 -0
  57. package/lib/ws-signal/join-room.d.ts +12 -0
  58. package/lib/ws-signal/join-room.js +40 -0
  59. package/lib/ws-signal/request/create-room.d.ts +8 -0
  60. package/lib/ws-signal/request/create-room.js +2 -0
  61. package/lib/ws-signal/request/index.d.ts +5 -0
  62. package/lib/ws-signal/request/index.js +2 -0
  63. package/lib/ws-signal/request/join-room.d.ts +6 -0
  64. package/lib/ws-signal/request/join-room.js +2 -0
  65. package/lib/ws-signal/request/send-guest-signal.d.ts +12 -0
  66. package/lib/ws-signal/request/send-guest-signal.js +2 -0
  67. package/lib/ws-signal/response/join-room-accepted.d.ts +31 -0
  68. package/lib/ws-signal/response/join-room-accepted.js +13 -0
  69. package/lib/ws-signal/response/join-room-rejected.d.ts +9 -0
  70. package/lib/ws-signal/response/join-room-rejected.js +8 -0
  71. package/lib/ws-signal/response/matching.d.ts +28 -0
  72. package/lib/ws-signal/response/matching.js +12 -0
  73. package/lib/ws-signal/response/room-creation-result.d.ts +37 -0
  74. package/lib/ws-signal/response/room-creation-result.js +20 -0
  75. package/lib/ws-signal/response/send-guest-signal-accepted.d.ts +9 -0
  76. package/lib/ws-signal/response/send-guest-signal-accepted.js +8 -0
  77. package/lib/ws-signal/response/send-guest-signal-rejected.d.ts +9 -0
  78. package/lib/ws-signal/response/send-guest-signal-rejected.js +8 -0
  79. package/lib/ws-signal/send-guest-signal.d.ts +17 -0
  80. package/lib/ws-signal/send-guest-signal.js +49 -0
  81. package/lib/ws-signal/send-to-ws-signal.d.ts +7 -0
  82. package/lib/ws-signal/send-to-ws-signal.js +11 -0
  83. package/lib/ws-signal/wait-until-matching.d.ts +7 -0
  84. package/lib/ws-signal/wait-until-matching.js +30 -0
  85. package/package.json +52 -0
package/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2026 Y.Takeuchi
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/Readme.md ADDED
@@ -0,0 +1,37 @@
1
+ # Gブレイバーバースト ローカルWebRTCブラウザSDK
2
+
3
+ ## はじめに
4
+
5
+ 本リポジトリは、GブレイバーバーストのローカルWebRTCブラウザSDKです。
6
+
7
+ ## コマンド例のカレントディレクトリについて
8
+
9
+ 特に断りがない限り、本書のコマンド例のカレントディレクトリは`<本リポジトリをcloneした場所>/packages/local-webrtc-browser-sdk`であるとします。
10
+
11
+ ## 前提条件
12
+
13
+ プロジェクトルートに記載されている[事前作業](../../Readme.md#事前作業)を完了させてください。
14
+
15
+ ## ビルド
16
+
17
+ ```shell
18
+ npm run build
19
+ ```
20
+
21
+ ## 脆弱性チェック
22
+
23
+ ```shell
24
+ npm audit --omit=dev
25
+ ```
26
+
27
+ ## package.jsonフォーマット
28
+
29
+ ```shell
30
+ # 本コマンドの実行にはfixpackが必要
31
+ # https://www.npmjs.com/package/fixpack
32
+ fixpack
33
+ ```
34
+
35
+ # License
36
+
37
+ MIT
package/lib/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { BattleSDK } from "./sdk/battle-sdk";
2
+ export { createLocalWebRTCGuestSDK, LocalWebRTCGuestSDK, } from "./sdk/local-webrtc-guest-sdk";
3
+ export { createLocalWebRTCHostSDK, LocalWebRTCHostSDK, } from "./sdk/local-webrtc-host-sdk";
4
+ export { LocalWebRTCRoom } from "./sdk/local-webrtc-room";
package/lib/index.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createLocalWebRTCHostSDK = exports.createLocalWebRTCGuestSDK = void 0;
4
+ var local_webrtc_guest_sdk_1 = require("./sdk/local-webrtc-guest-sdk");
5
+ Object.defineProperty(exports, "createLocalWebRTCGuestSDK", { enumerable: true, get: function () { return local_webrtc_guest_sdk_1.createLocalWebRTCGuestSDK; } });
6
+ var local_webrtc_host_sdk_1 = require("./sdk/local-webrtc-host-sdk");
7
+ Object.defineProperty(exports, "createLocalWebRTCHostSDK", { enumerable: true, get: function () { return local_webrtc_host_sdk_1.createLocalWebRTCHostSDK; } });
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 例外を発生させずにJSONをパースする
3
+ * パース結果はzodなどでバリデーションすることを想定している
4
+ * @param origin パース元
5
+ * @returns パース結果
6
+ */
7
+ export declare function parseJSON(origin: unknown): unknown;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseJSON = parseJSON;
4
+ /**
5
+ * 例外を発生させずにJSONをパースする
6
+ * パース結果はzodなどでバリデーションすることを想定している
7
+ * @param origin パース元
8
+ * @returns パース結果
9
+ */
10
+ function parseJSON(origin) {
11
+ if (typeof origin !== "string") {
12
+ return null;
13
+ }
14
+ try {
15
+ return JSON.parse(origin);
16
+ }
17
+ catch (_a) {
18
+ return null;
19
+ }
20
+ }
@@ -0,0 +1,25 @@
1
+ import { Command, GameState, Player } from "gbraver-burst-core";
2
+ import { Observable } from "rxjs";
3
+ /**
4
+ * バトルSDK
5
+ * 本操作はログイン後に実行することを想定している
6
+ */
7
+ export interface BattleSDK {
8
+ /** プレイヤーの情報 */
9
+ player: Player;
10
+ /** 対戦相手の情報 */
11
+ enemy: Player;
12
+ /** ゲームの初期状態 */
13
+ initialState: GameState[];
14
+ /**
15
+ * バトルを進行させる
16
+ * @param command プレイヤーが入力するコマンド
17
+ * @returns ゲーム結果
18
+ */
19
+ progress(command: Command): Promise<GameState[]>;
20
+ /**
21
+ * バトル強制終了の通知ストリーム
22
+ * @returns 通知ストリーム
23
+ */
24
+ suddenlyBattleEndNotifier(): Observable<unknown>;
25
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,39 @@
1
+ import { Command, GameState, Player } from "gbraver-burst-core";
2
+ import { Observable } from "rxjs";
3
+ import { BattleSDK } from "./battle-sdk";
4
+ import { GuestWebRTCConnectionManager } from "./guest-webrtc-connection-manager";
5
+ /** ゲスト側バトルSDK */
6
+ export declare class GuestBattleSDK implements BattleSDK {
7
+ #private;
8
+ /** プレイヤーの情報 */
9
+ player: Player;
10
+ /** 対戦相手の情報 */
11
+ enemy: Player;
12
+ /** ゲームの初期状態 */
13
+ initialState: GameState[];
14
+ /** 最新のフローID */
15
+ flowID: string;
16
+ /**
17
+ * コンストラクタ
18
+ * @param options オプション
19
+ * @param options.hostPlayer ホスト側のプレイヤー情報
20
+ * @param options.guestPlayer ゲスト側のプレイヤー情報
21
+ * @param options.initialState ゲームの初期状態
22
+ * @param options.initialFlowID 初期のフローID
23
+ * @param options.webRTCConnection ホストのWebRTCコネクションマネージャー
24
+ */
25
+ constructor(options: {
26
+ hostPlayer: Player;
27
+ guestPlayer: Player;
28
+ initialState: GameState[];
29
+ initialFlowID: string;
30
+ webRTCConnection: GuestWebRTCConnectionManager;
31
+ });
32
+ /** @override */
33
+ progress(command: Command): Promise<GameState[]>;
34
+ /**
35
+ * バトル強制終了の通知ストリーム
36
+ * @returns 通知ストリーム
37
+ */
38
+ suddenlyBattleEndNotifier(): Observable<unknown>;
39
+ }
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
+ if (kind === "m") throw new TypeError("Private method is not writable");
13
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
15
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
+ };
17
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
19
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
20
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
+ };
22
+ var _GuestBattleSDK_webRTCConnection;
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.GuestBattleSDK = void 0;
25
+ const rxjs_1 = require("rxjs");
26
+ const guest_message_1 = require("../webrtc/guest/guest-message");
27
+ const receive_battle_progressed_1 = require("../webrtc/guest/receive-battle-progressed");
28
+ /** ゲスト側バトルSDK */
29
+ class GuestBattleSDK {
30
+ /**
31
+ * コンストラクタ
32
+ * @param options オプション
33
+ * @param options.hostPlayer ホスト側のプレイヤー情報
34
+ * @param options.guestPlayer ゲスト側のプレイヤー情報
35
+ * @param options.initialState ゲームの初期状態
36
+ * @param options.initialFlowID 初期のフローID
37
+ * @param options.webRTCConnection ホストのWebRTCコネクションマネージャー
38
+ */
39
+ constructor(options) {
40
+ /** ホストのWebRTCコネクションマネージャー */
41
+ _GuestBattleSDK_webRTCConnection.set(this, void 0);
42
+ this.player = options.guestPlayer;
43
+ this.enemy = options.hostPlayer;
44
+ this.initialState = options.initialState;
45
+ this.flowID = options.initialFlowID;
46
+ __classPrivateFieldSet(this, _GuestBattleSDK_webRTCConnection, options.webRTCConnection, "f");
47
+ }
48
+ /** @override */
49
+ progress(command) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ const dataChannel = yield __classPrivateFieldGet(this, _GuestBattleSDK_webRTCConnection, "f").getOrCreateConnection().dataChannel;
52
+ const battleProgressedPromise = (0, receive_battle_progressed_1.receiveBattleProgressed)(dataChannel);
53
+ (0, guest_message_1.sendGuestMessage)(dataChannel, {
54
+ type: "send-command",
55
+ flowID: this.flowID,
56
+ command,
57
+ });
58
+ const battleProgressed = yield battleProgressedPromise;
59
+ this.flowID = battleProgressed.flowID;
60
+ return battleProgressed.update;
61
+ });
62
+ }
63
+ /**
64
+ * バトル強制終了の通知ストリーム
65
+ * @returns 通知ストリーム
66
+ */
67
+ suddenlyBattleEndNotifier() {
68
+ // TODO 中身を実装する
69
+ return rxjs_1.EMPTY;
70
+ }
71
+ }
72
+ exports.GuestBattleSDK = GuestBattleSDK;
73
+ _GuestBattleSDK_webRTCConnection = new WeakMap();
@@ -0,0 +1,19 @@
1
+ /** ゲストのWebRTCコネクション管理 */
2
+ export declare class GuestWebRTCConnectionManager {
3
+ #private;
4
+ /**
5
+ * コネクションを取得する。
6
+ * コネクションが存在しない場合は新たに作成する。
7
+ * @returns 取得したコネクションとデータチャンネル
8
+ */
9
+ getOrCreateConnection(): {
10
+ /** コネクション */
11
+ connection: RTCPeerConnection;
12
+ /** データチャンネル */
13
+ dataChannel: Promise<RTCDataChannel>;
14
+ };
15
+ /**
16
+ * コネクションを切断する
17
+ */
18
+ disconnect(): void;
19
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8
+ if (kind === "m") throw new TypeError("Private method is not writable");
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
+ };
13
+ var _GuestWebRTCConnectionManager_connectionState;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.GuestWebRTCConnectionManager = void 0;
16
+ const wait_until_data_channel_1 = require("../webrtc/guest/wait-until-data-channel");
17
+ /** ゲストのWebRTCコネクション管理 */
18
+ class GuestWebRTCConnectionManager {
19
+ constructor() {
20
+ /** コネクションの状態 */
21
+ _GuestWebRTCConnectionManager_connectionState.set(this, { type: "disconnected" });
22
+ }
23
+ /**
24
+ * コネクションを取得する。
25
+ * コネクションが存在しない場合は新たに作成する。
26
+ * @returns 取得したコネクションとデータチャンネル
27
+ */
28
+ getOrCreateConnection() {
29
+ if (__classPrivateFieldGet(this, _GuestWebRTCConnectionManager_connectionState, "f").type === "disconnected") {
30
+ const connection = new RTCPeerConnection();
31
+ const dataChannel = (0, wait_until_data_channel_1.waitUntilDataChannel)(connection);
32
+ __classPrivateFieldSet(this, _GuestWebRTCConnectionManager_connectionState, {
33
+ type: "connected",
34
+ connection,
35
+ dataChannel,
36
+ }, "f");
37
+ }
38
+ return __classPrivateFieldGet(this, _GuestWebRTCConnectionManager_connectionState, "f");
39
+ }
40
+ /**
41
+ * コネクションを切断する
42
+ */
43
+ disconnect() {
44
+ if (__classPrivateFieldGet(this, _GuestWebRTCConnectionManager_connectionState, "f").type === "connected") {
45
+ __classPrivateFieldGet(this, _GuestWebRTCConnectionManager_connectionState, "f").connection.close();
46
+ __classPrivateFieldGet(this, _GuestWebRTCConnectionManager_connectionState, "f").dataChannel.then((channel) => channel.close());
47
+ }
48
+ __classPrivateFieldSet(this, _GuestWebRTCConnectionManager_connectionState, { type: "disconnected" }, "f");
49
+ }
50
+ }
51
+ exports.GuestWebRTCConnectionManager = GuestWebRTCConnectionManager;
52
+ _GuestWebRTCConnectionManager_connectionState = new WeakMap();
@@ -0,0 +1,39 @@
1
+ import { ArmdozerId, Command, GameState, PilotId, Player } from "gbraver-burst-core";
2
+ import { Observable } from "rxjs";
3
+ import { BattleSDK } from "./battle-sdk";
4
+ import { HostWebRTCConnectionManager } from "./host-webrtc-connection-manager";
5
+ /** ホスト側バトルSDK */
6
+ export declare class HostBattleSDK implements BattleSDK {
7
+ #private;
8
+ /** プレイヤーの情報 */
9
+ player: Player;
10
+ /** 対戦相手の情報 */
11
+ enemy: Player;
12
+ /** ゲームの初期状態 */
13
+ initialState: GameState[];
14
+ /** 最新のフローID */
15
+ flowID: string;
16
+ /**
17
+ * コンストラクタ
18
+ * @param options オプション
19
+ * @param options.hostArmdozerId ホスト側のアームドーザID
20
+ * @param options.hostPilotId ホスト側のパイロットID
21
+ * @param options.guestArmdozerId ゲスト側のアームドーザID
22
+ * @param options.guestPilotId ゲスト側のパイロットID
23
+ * @param options.webRTCConnection ホスト側のWebRTC接続マネージャー
24
+ */
25
+ constructor(options: {
26
+ hostArmdozerId: ArmdozerId;
27
+ hostPilotId: PilotId;
28
+ guestArmdozerId: ArmdozerId;
29
+ guestPilotId: PilotId;
30
+ webRTCConnection: HostWebRTCConnectionManager;
31
+ });
32
+ /** @override */
33
+ progress(command: Command): Promise<GameState[]>;
34
+ /**
35
+ * バトル強制終了の通知ストリーム
36
+ * @returns 通知ストリーム
37
+ */
38
+ suddenlyBattleEndNotifier(): Observable<unknown>;
39
+ }
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
+ if (kind === "m") throw new TypeError("Private method is not writable");
13
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
15
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
+ };
17
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
19
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
20
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
+ };
22
+ var _HostBattleSDK_core, _HostBattleSDK_webRTCConnection, _HostBattleSDK_sendCommandPromise;
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.HostBattleSDK = void 0;
25
+ const gbraver_burst_core_1 = require("gbraver-burst-core");
26
+ const nanoid_1 = require("nanoid");
27
+ const rxjs_1 = require("rxjs");
28
+ const host_message_1 = require("../webrtc/host/host-message");
29
+ const receive_send_command_1 = require("../webrtc/host/receive-send-command");
30
+ /** ホスト側バトルSDK */
31
+ class HostBattleSDK {
32
+ /**
33
+ * コンストラクタ
34
+ * @param options オプション
35
+ * @param options.hostArmdozerId ホスト側のアームドーザID
36
+ * @param options.hostPilotId ホスト側のパイロットID
37
+ * @param options.guestArmdozerId ゲスト側のアームドーザID
38
+ * @param options.guestPilotId ゲスト側のパイロットID
39
+ * @param options.webRTCConnection ホスト側のWebRTC接続マネージャー
40
+ */
41
+ constructor(options) {
42
+ var _a, _b, _c, _d;
43
+ /** Gブレイバーバーストコア */
44
+ _HostBattleSDK_core.set(this, void 0);
45
+ /** ホスト側のWebRTCコネクションマネージャー */
46
+ _HostBattleSDK_webRTCConnection.set(this, void 0);
47
+ /** ゲストからのコマンド受信プロミス */
48
+ _HostBattleSDK_sendCommandPromise.set(this, void 0);
49
+ const hostPlayerId = (0, nanoid_1.nanoid)();
50
+ this.player = {
51
+ playerId: hostPlayerId,
52
+ armdozer: (_a = gbraver_burst_core_1.Armdozers.find((a) => a.id === options.hostArmdozerId)) !== null && _a !== void 0 ? _a : gbraver_burst_core_1.Armdozers[0],
53
+ pilot: (_b = gbraver_burst_core_1.Pilots.find((p) => p.id === options.hostPilotId)) !== null && _b !== void 0 ? _b : gbraver_burst_core_1.Pilots[0],
54
+ };
55
+ const guestPlayerId = (0, nanoid_1.nanoid)();
56
+ this.enemy = {
57
+ playerId: guestPlayerId,
58
+ armdozer: (_c = gbraver_burst_core_1.Armdozers.find((a) => a.id === options.guestArmdozerId)) !== null && _c !== void 0 ? _c : gbraver_burst_core_1.Armdozers[0],
59
+ pilot: (_d = gbraver_burst_core_1.Pilots.find((p) => p.id === options.guestPilotId)) !== null && _d !== void 0 ? _d : gbraver_burst_core_1.Pilots[0],
60
+ };
61
+ __classPrivateFieldSet(this, _HostBattleSDK_core, (0, gbraver_burst_core_1.startGBraverBurst)([this.player, this.enemy]), "f");
62
+ this.initialState = __classPrivateFieldGet(this, _HostBattleSDK_core, "f").stateHistory();
63
+ this.flowID = (0, nanoid_1.nanoid)();
64
+ __classPrivateFieldSet(this, _HostBattleSDK_webRTCConnection, options.webRTCConnection, "f");
65
+ __classPrivateFieldSet(this, _HostBattleSDK_sendCommandPromise, (0, receive_send_command_1.receiveSendCommand)(__classPrivateFieldGet(this, _HostBattleSDK_webRTCConnection, "f").getOrCreateConnection().dataChannel, this.flowID), "f");
66
+ }
67
+ /** @override */
68
+ progress(command) {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ const sendCommand = yield __classPrivateFieldGet(this, _HostBattleSDK_sendCommandPromise, "f");
71
+ const hostCommand = { playerId: this.player.playerId, command };
72
+ const guestCommand = {
73
+ playerId: this.enemy.playerId,
74
+ command: sendCommand.command,
75
+ };
76
+ const update = __classPrivateFieldGet(this, _HostBattleSDK_core, "f").progress([hostCommand, guestCommand]);
77
+ this.flowID = (0, nanoid_1.nanoid)();
78
+ __classPrivateFieldSet(this, _HostBattleSDK_sendCommandPromise, (0, receive_send_command_1.receiveSendCommand)(__classPrivateFieldGet(this, _HostBattleSDK_webRTCConnection, "f").getOrCreateConnection().dataChannel, this.flowID), "f");
79
+ (0, host_message_1.sendHostMessage)(__classPrivateFieldGet(this, _HostBattleSDK_webRTCConnection, "f").getOrCreateConnection().dataChannel, {
80
+ type: "battle-progressed",
81
+ flowID: this.flowID,
82
+ update,
83
+ });
84
+ return update;
85
+ });
86
+ }
87
+ /**
88
+ * バトル強制終了の通知ストリーム
89
+ * @returns 通知ストリーム
90
+ */
91
+ suddenlyBattleEndNotifier() {
92
+ // TODO 中身を実装する
93
+ return rxjs_1.EMPTY;
94
+ }
95
+ }
96
+ exports.HostBattleSDK = HostBattleSDK;
97
+ _HostBattleSDK_core = new WeakMap(), _HostBattleSDK_webRTCConnection = new WeakMap(), _HostBattleSDK_sendCommandPromise = new WeakMap();
@@ -0,0 +1,19 @@
1
+ /** ホストのWebRTCコネクション管理 */
2
+ export declare class HostWebRTCConnectionManager {
3
+ #private;
4
+ /**
5
+ * コネクションを取得する。
6
+ * コネクションが存在しない場合は新たに作成する。
7
+ * @returns 取得したコネクションとデータチャンネル
8
+ */
9
+ getOrCreateConnection(): {
10
+ /** コネクション */
11
+ connection: RTCPeerConnection;
12
+ /** データチャンネル */
13
+ dataChannel: RTCDataChannel;
14
+ };
15
+ /**
16
+ * コネクションを切断する
17
+ */
18
+ disconnect(): void;
19
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8
+ if (kind === "m") throw new TypeError("Private method is not writable");
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
+ };
13
+ var _HostWebRTCConnectionManager_connectionState;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.HostWebRTCConnectionManager = void 0;
16
+ /** ホストのWebRTCコネクション管理 */
17
+ class HostWebRTCConnectionManager {
18
+ constructor() {
19
+ /** コネクションの状態 */
20
+ _HostWebRTCConnectionManager_connectionState.set(this, { type: "disconnected" });
21
+ }
22
+ /**
23
+ * コネクションを取得する。
24
+ * コネクションが存在しない場合は新たに作成する。
25
+ * @returns 取得したコネクションとデータチャンネル
26
+ */
27
+ getOrCreateConnection() {
28
+ if (__classPrivateFieldGet(this, _HostWebRTCConnectionManager_connectionState, "f").type === "disconnected") {
29
+ const connection = new RTCPeerConnection();
30
+ const dataChannel = connection.createDataChannel("sendDataChannel");
31
+ __classPrivateFieldSet(this, _HostWebRTCConnectionManager_connectionState, {
32
+ type: "connected",
33
+ connection,
34
+ dataChannel,
35
+ }, "f");
36
+ }
37
+ return __classPrivateFieldGet(this, _HostWebRTCConnectionManager_connectionState, "f");
38
+ }
39
+ /**
40
+ * コネクションを切断する
41
+ */
42
+ disconnect() {
43
+ if (__classPrivateFieldGet(this, _HostWebRTCConnectionManager_connectionState, "f").type === "connected") {
44
+ __classPrivateFieldGet(this, _HostWebRTCConnectionManager_connectionState, "f").connection.close();
45
+ __classPrivateFieldGet(this, _HostWebRTCConnectionManager_connectionState, "f").dataChannel.close();
46
+ }
47
+ __classPrivateFieldSet(this, _HostWebRTCConnectionManager_connectionState, { type: "disconnected" }, "f");
48
+ }
49
+ }
50
+ exports.HostWebRTCConnectionManager = HostWebRTCConnectionManager;
51
+ _HostWebRTCConnectionManager_connectionState = new WeakMap();
@@ -0,0 +1,34 @@
1
+ import { ArmdozerId, PilotId } from "gbraver-burst-core";
2
+ import { Observable } from "rxjs";
3
+ import { BattleSDK } from "./battle-sdk";
4
+ /** ローカルWebRTCゲスト用SDK */
5
+ export type LocalWebRTCGuestSDK = {
6
+ /**
7
+ * ルームに参加する
8
+ * @param options ルーム参加のオプション
9
+ * @param options.roomID ルームID
10
+ * @param options.armdozerId ゲストが選択したアームドーザのID
11
+ * @param options.pilotId ゲストが選択したパイロットのID
12
+ * @returns ルームへの参加に成功したらBattleSDK、失敗したらnull
13
+ */
14
+ joinRoom: (options: {
15
+ roomID: string;
16
+ armdozerId: ArmdozerId;
17
+ pilotId: PilotId;
18
+ }) => Promise<BattleSDK | null>;
19
+ /**
20
+ * WebSocketのエラーを通知する
21
+ * @returns 通知ストリーム
22
+ */
23
+ websocketErrorNotifier(): Observable<unknown>;
24
+ /**
25
+ * WebRTCコネクションを切断する
26
+ */
27
+ disconnectWebRTC(): void;
28
+ };
29
+ /**
30
+ * ローカルWebRTCゲスト用SDKを生成する
31
+ * @param wsSignalUrl WebSocketシグナルサーバーのURL
32
+ * @returns ローカルWebRTCゲスト用SDKのインスタンス
33
+ */
34
+ export declare function createLocalWebRTCGuestSDK(wsSignalUrl: string): LocalWebRTCGuestSDK;