@gbraver-burst-network/local-webrtc-browser-sdk 1.21.0 → 1.22.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.
package/Readme.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  ## コマンド例のカレントディレクトリについて
8
8
 
9
- 特に断りがない限り、本書のコマンド例のカレントディレクトリは`<本リポジトリをcloneした場所>/packages/local-webrtc-browser-sdk`であるとします。
9
+ とくに断りがない限り、本書のコマンド例のカレントディレクトリは`<本リポジトリをcloneした場所>/packages/local-webrtc-browser-sdk`であるとします。
10
10
 
11
11
  ## 前提条件
12
12
 
@@ -32,6 +32,6 @@ npm audit --omit=dev
32
32
  fixpack
33
33
  ```
34
34
 
35
- # License
35
+ ## License
36
36
 
37
37
  MIT
@@ -0,0 +1,13 @@
1
+ /**
2
+ * RTCPeerConnectionを作成する
3
+ * @param options オプション
4
+ * @param options.webRTCHelperApiURL WebRTCヘルパーAPIのURL
5
+ * @param options.coturnDomainName coturnサーバーのドメイン名
6
+ * @returns 作成したRTCPeerConnection
7
+ */
8
+ export declare const createRTCPeerConnection: (options: {
9
+ /** WebRTCヘルパーAPIのURL */
10
+ webRTCHelperApiURL: string;
11
+ /** coturnサーバーのドメイン名 */
12
+ coturnDomainName: string;
13
+ }) => Promise<RTCPeerConnection>;
@@ -0,0 +1,41 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.createRTCPeerConnection = void 0;
13
+ const issue_coturn_credential_1 = require("../webrtc-helper/issue-coturn-credential");
14
+ /**
15
+ * RTCPeerConnectionを作成する
16
+ * @param options オプション
17
+ * @param options.webRTCHelperApiURL WebRTCヘルパーAPIのURL
18
+ * @param options.coturnDomainName coturnサーバーのドメイン名
19
+ * @returns 作成したRTCPeerConnection
20
+ */
21
+ const createRTCPeerConnection = (options) => __awaiter(void 0, void 0, void 0, function* () {
22
+ const { webRTCHelperApiURL, coturnDomainName } = options;
23
+ const { username, password: credential } = yield (0, issue_coturn_credential_1.issueCoturnCredential)(webRTCHelperApiURL);
24
+ return new RTCPeerConnection({
25
+ iceServers: [
26
+ {
27
+ urls: [`stun:${coturnDomainName}:3478`],
28
+ },
29
+ {
30
+ urls: [
31
+ `turn:${coturnDomainName}:3478?transport=udp`,
32
+ `turn:${coturnDomainName}:3478?transport=tcp`,
33
+ `turns:${coturnDomainName}:5349?transport=tcp`,
34
+ ],
35
+ username,
36
+ credential,
37
+ },
38
+ ],
39
+ });
40
+ });
41
+ exports.createRTCPeerConnection = createRTCPeerConnection;
@@ -48,7 +48,7 @@ class GuestBattleSDK {
48
48
  /** @override */
49
49
  progress(command) {
50
50
  return __awaiter(this, void 0, void 0, function* () {
51
- const dataChannel = yield __classPrivateFieldGet(this, _GuestBattleSDK_webRTCConnection, "f").getOrCreateConnection().dataChannel;
51
+ const dataChannel = yield __classPrivateFieldGet(this, _GuestBattleSDK_webRTCConnection, "f").getOrCreateConnection().dataChannelPromise;
52
52
  const battleProgressedPromise = (0, receive_battle_progressed_1.receiveBattleProgressed)(dataChannel);
53
53
  (0, guest_message_1.sendGuestMessage)(dataChannel, {
54
54
  type: "send-command",
@@ -1,6 +1,17 @@
1
+ /** GuestWebRTCConnectionManagerコンストラクタのオプション */
2
+ export type GuestWebRTCConnectionManagerOptions = {
3
+ /** WebRTCヘルパーAPIのURL */
4
+ webRTCHelperApiURL: string;
5
+ /** coturnサーバーのドメイン名 */
6
+ coturnDomainName: string;
7
+ };
1
8
  /** ゲストのWebRTCコネクション管理 */
2
9
  export declare class GuestWebRTCConnectionManager {
3
10
  #private;
11
+ /** コンストラクタ
12
+ * @param options オプション
13
+ */
14
+ constructor(options: GuestWebRTCConnectionManagerOptions);
4
15
  /**
5
16
  * コネクションを取得する。
6
17
  * コネクションが存在しない場合は新たに作成する。
@@ -8,9 +19,9 @@ export declare class GuestWebRTCConnectionManager {
8
19
  */
9
20
  getOrCreateConnection(): {
10
21
  /** コネクション */
11
- connection: RTCPeerConnection;
22
+ connectionPromise: Promise<RTCPeerConnection>;
12
23
  /** データチャンネル */
13
- dataChannel: Promise<RTCDataChannel>;
24
+ dataChannelPromise: Promise<RTCDataChannel>;
14
25
  };
15
26
  /**
16
27
  * コネクションを切断する
@@ -1,24 +1,34 @@
1
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
2
  var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8
3
  if (kind === "m") throw new TypeError("Private method is not writable");
9
4
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
10
5
  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
6
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
7
  };
13
- var _GuestWebRTCConnectionManager_connectionState;
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ 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");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _GuestWebRTCConnectionManager_connectionState, _GuestWebRTCConnectionManager_webRTCHelperApiURL, _GuestWebRTCConnectionManager_coturnDomainName;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.GuestWebRTCConnectionManager = void 0;
16
16
  const wait_until_data_channel_1 = require("../webrtc/guest/wait-until-data-channel");
17
+ const create_rtc_peer_connection_1 = require("./create-rtc-peer-connection");
17
18
  /** ゲストのWebRTCコネクション管理 */
18
19
  class GuestWebRTCConnectionManager {
19
- constructor() {
20
+ /** コンストラクタ
21
+ * @param options オプション
22
+ */
23
+ constructor(options) {
20
24
  /** コネクションの状態 */
21
25
  _GuestWebRTCConnectionManager_connectionState.set(this, { type: "disconnected" });
26
+ /** WebRTCヘルパーAPIのURL */
27
+ _GuestWebRTCConnectionManager_webRTCHelperApiURL.set(this, void 0);
28
+ /** coturnサーバーのドメイン名 */
29
+ _GuestWebRTCConnectionManager_coturnDomainName.set(this, void 0);
30
+ __classPrivateFieldSet(this, _GuestWebRTCConnectionManager_webRTCHelperApiURL, options.webRTCHelperApiURL, "f");
31
+ __classPrivateFieldSet(this, _GuestWebRTCConnectionManager_coturnDomainName, options.coturnDomainName, "f");
22
32
  }
23
33
  /**
24
34
  * コネクションを取得する。
@@ -27,12 +37,15 @@ class GuestWebRTCConnectionManager {
27
37
  */
28
38
  getOrCreateConnection() {
29
39
  if (__classPrivateFieldGet(this, _GuestWebRTCConnectionManager_connectionState, "f").type === "disconnected") {
30
- const connection = new RTCPeerConnection();
31
- const dataChannel = (0, wait_until_data_channel_1.waitUntilDataChannel)(connection);
40
+ const connectionPromise = (0, create_rtc_peer_connection_1.createRTCPeerConnection)({
41
+ webRTCHelperApiURL: __classPrivateFieldGet(this, _GuestWebRTCConnectionManager_webRTCHelperApiURL, "f"),
42
+ coturnDomainName: __classPrivateFieldGet(this, _GuestWebRTCConnectionManager_coturnDomainName, "f"),
43
+ });
44
+ const dataChannelPromise = connectionPromise.then((connection) => (0, wait_until_data_channel_1.waitUntilDataChannel)(connection));
32
45
  __classPrivateFieldSet(this, _GuestWebRTCConnectionManager_connectionState, {
33
46
  type: "connected",
34
- connection,
35
- dataChannel,
47
+ connectionPromise,
48
+ dataChannelPromise,
36
49
  }, "f");
37
50
  }
38
51
  return __classPrivateFieldGet(this, _GuestWebRTCConnectionManager_connectionState, "f");
@@ -42,11 +55,11 @@ class GuestWebRTCConnectionManager {
42
55
  */
43
56
  disconnect() {
44
57
  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());
58
+ __classPrivateFieldGet(this, _GuestWebRTCConnectionManager_connectionState, "f").connectionPromise.then((connection) => connection.close());
59
+ __classPrivateFieldGet(this, _GuestWebRTCConnectionManager_connectionState, "f").dataChannelPromise.then((channel) => channel.close());
47
60
  }
48
61
  __classPrivateFieldSet(this, _GuestWebRTCConnectionManager_connectionState, { type: "disconnected" }, "f");
49
62
  }
50
63
  }
51
64
  exports.GuestWebRTCConnectionManager = GuestWebRTCConnectionManager;
52
- _GuestWebRTCConnectionManager_connectionState = new WeakMap();
65
+ _GuestWebRTCConnectionManager_connectionState = new WeakMap(), _GuestWebRTCConnectionManager_webRTCHelperApiURL = new WeakMap(), _GuestWebRTCConnectionManager_coturnDomainName = new WeakMap();
@@ -62,7 +62,9 @@ class HostBattleSDK {
62
62
  this.initialState = __classPrivateFieldGet(this, _HostBattleSDK_core, "f").stateHistory();
63
63
  this.flowID = (0, nanoid_1.nanoid)();
64
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");
65
+ __classPrivateFieldSet(this, _HostBattleSDK_sendCommandPromise, __classPrivateFieldGet(this, _HostBattleSDK_webRTCConnection, "f")
66
+ .getOrCreateConnection()
67
+ .dataChannelPromise.then((dataChannel) => (0, receive_send_command_1.receiveSendCommand)(dataChannel, this.flowID)), "f");
66
68
  }
67
69
  /** @override */
68
70
  progress(command) {
@@ -75,8 +77,9 @@ class HostBattleSDK {
75
77
  };
76
78
  const update = __classPrivateFieldGet(this, _HostBattleSDK_core, "f").progress([hostCommand, guestCommand]);
77
79
  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
+ const dataChannel = yield __classPrivateFieldGet(this, _HostBattleSDK_webRTCConnection, "f").getOrCreateConnection().dataChannelPromise;
81
+ __classPrivateFieldSet(this, _HostBattleSDK_sendCommandPromise, (0, receive_send_command_1.receiveSendCommand)(dataChannel, this.flowID), "f");
82
+ (0, host_message_1.sendHostMessage)(dataChannel, {
80
83
  type: "battle-progressed",
81
84
  flowID: this.flowID,
82
85
  update,
@@ -1,16 +1,28 @@
1
+ /** HostWebRTCConnectionManagerコンストラクタのオプション */
2
+ export type HostWebRTCConnectionManagerOptions = {
3
+ /** WebRTCヘルパーAPIのURL */
4
+ webRTCHelperApiURL: string;
5
+ /** coturnサーバーのドメイン名 */
6
+ coturnDomainName: string;
7
+ };
1
8
  /** ホストのWebRTCコネクション管理 */
2
9
  export declare class HostWebRTCConnectionManager {
3
10
  #private;
11
+ /**
12
+ * コンストラクタ
13
+ * @param options オプション
14
+ */
15
+ constructor(options: HostWebRTCConnectionManagerOptions);
4
16
  /**
5
17
  * コネクションを取得する。
6
18
  * コネクションが存在しない場合は新たに作成する。
7
- * @returns 取得したコネクションとデータチャンネル
19
+ * @returns 生成したコネクション
8
20
  */
9
21
  getOrCreateConnection(): {
10
- /** コネクション */
11
- connection: RTCPeerConnection;
12
- /** データチャンネル */
13
- dataChannel: RTCDataChannel;
22
+ /** コネクションのPromise */
23
+ connectionPromise: Promise<RTCPeerConnection>;
24
+ /** データチャンネルのPromise */
25
+ dataChannelPromise: Promise<RTCDataChannel>;
14
26
  };
15
27
  /**
16
28
  * コネクションを切断する
@@ -1,37 +1,51 @@
1
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
2
  var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8
3
  if (kind === "m") throw new TypeError("Private method is not writable");
9
4
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
10
5
  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
6
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
7
  };
13
- var _HostWebRTCConnectionManager_connectionState;
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ 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");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _HostWebRTCConnectionManager_connectionState, _HostWebRTCConnectionManager_webRTCHelperApiURL, _HostWebRTCConnectionManager_coturnDomainName;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.HostWebRTCConnectionManager = void 0;
16
+ const create_rtc_peer_connection_1 = require("./create-rtc-peer-connection");
16
17
  /** ホストのWebRTCコネクション管理 */
17
18
  class HostWebRTCConnectionManager {
18
- constructor() {
19
+ /**
20
+ * コンストラクタ
21
+ * @param options オプション
22
+ */
23
+ constructor(options) {
19
24
  /** コネクションの状態 */
20
25
  _HostWebRTCConnectionManager_connectionState.set(this, { type: "disconnected" });
26
+ /** WebRTCヘルパーAPIのURL */
27
+ _HostWebRTCConnectionManager_webRTCHelperApiURL.set(this, void 0);
28
+ /** coturnサーバーのドメイン名 */
29
+ _HostWebRTCConnectionManager_coturnDomainName.set(this, void 0);
30
+ __classPrivateFieldSet(this, _HostWebRTCConnectionManager_webRTCHelperApiURL, options.webRTCHelperApiURL, "f");
31
+ __classPrivateFieldSet(this, _HostWebRTCConnectionManager_coturnDomainName, options.coturnDomainName, "f");
21
32
  }
22
33
  /**
23
34
  * コネクションを取得する。
24
35
  * コネクションが存在しない場合は新たに作成する。
25
- * @returns 取得したコネクションとデータチャンネル
36
+ * @returns 生成したコネクション
26
37
  */
27
38
  getOrCreateConnection() {
28
39
  if (__classPrivateFieldGet(this, _HostWebRTCConnectionManager_connectionState, "f").type === "disconnected") {
29
- const connection = new RTCPeerConnection();
30
- const dataChannel = connection.createDataChannel("sendDataChannel");
40
+ const connectionPromise = (0, create_rtc_peer_connection_1.createRTCPeerConnection)({
41
+ webRTCHelperApiURL: __classPrivateFieldGet(this, _HostWebRTCConnectionManager_webRTCHelperApiURL, "f"),
42
+ coturnDomainName: __classPrivateFieldGet(this, _HostWebRTCConnectionManager_coturnDomainName, "f"),
43
+ });
44
+ const dataChannelPromise = connectionPromise.then((connection) => connection.createDataChannel("sendDataChannel"));
31
45
  __classPrivateFieldSet(this, _HostWebRTCConnectionManager_connectionState, {
32
46
  type: "connected",
33
- connection,
34
- dataChannel,
47
+ connectionPromise,
48
+ dataChannelPromise,
35
49
  }, "f");
36
50
  }
37
51
  return __classPrivateFieldGet(this, _HostWebRTCConnectionManager_connectionState, "f");
@@ -41,11 +55,15 @@ class HostWebRTCConnectionManager {
41
55
  */
42
56
  disconnect() {
43
57
  if (__classPrivateFieldGet(this, _HostWebRTCConnectionManager_connectionState, "f").type === "connected") {
44
- __classPrivateFieldGet(this, _HostWebRTCConnectionManager_connectionState, "f").connection.close();
45
- __classPrivateFieldGet(this, _HostWebRTCConnectionManager_connectionState, "f").dataChannel.close();
58
+ __classPrivateFieldGet(this, _HostWebRTCConnectionManager_connectionState, "f").connectionPromise.then((connection) => {
59
+ connection.close();
60
+ });
61
+ __classPrivateFieldGet(this, _HostWebRTCConnectionManager_connectionState, "f").dataChannelPromise.then((dataChannel) => {
62
+ dataChannel.close();
63
+ });
46
64
  }
47
65
  __classPrivateFieldSet(this, _HostWebRTCConnectionManager_connectionState, { type: "disconnected" }, "f");
48
66
  }
49
67
  }
50
68
  exports.HostWebRTCConnectionManager = HostWebRTCConnectionManager;
51
- _HostWebRTCConnectionManager_connectionState = new WeakMap();
69
+ _HostWebRTCConnectionManager_connectionState = new WeakMap(), _HostWebRTCConnectionManager_webRTCHelperApiURL = new WeakMap(), _HostWebRTCConnectionManager_coturnDomainName = new WeakMap();
@@ -1,6 +1,7 @@
1
1
  import { ArmdozerId, PilotId } from "gbraver-burst-core";
2
2
  import { Observable } from "rxjs";
3
3
  import { BattleSDK } from "./battle-sdk";
4
+ import { GuestWebRTCConnectionManagerOptions } from "./guest-webrtc-connection-manager";
4
5
  /** ローカルWebRTCゲスト用SDK */
5
6
  export type LocalWebRTCGuestSDK = {
6
7
  /**
@@ -33,9 +34,17 @@ export type LocalWebRTCGuestSDK = {
33
34
  */
34
35
  disconnectWebRTC(): void;
35
36
  };
37
+ /** LocalWebRTCGuestSDKImplコンストラクタのオプション */
38
+ type LocalWebRTCGuestSDKImplOptions = GuestWebRTCConnectionManagerOptions & {
39
+ /** WebSocketシグナルサーバーのURL */
40
+ wsSignalUrl: string;
41
+ };
42
+ /** LocalWebRTCGuestSDKを生成するオプション */
43
+ type CreateLocalWebRTCGuestSDKOptions = LocalWebRTCGuestSDKImplOptions;
36
44
  /**
37
45
  * ローカルWebRTCゲスト用SDKを生成する
38
- * @param wsSignalUrl WebSocketシグナルサーバーのURL
46
+ * @param options オプション
39
47
  * @returns ローカルWebRTCゲスト用SDKのインスタンス
40
48
  */
41
- export declare function createLocalWebRTCGuestSDK(wsSignalUrl: string): LocalWebRTCGuestSDK;
49
+ export declare function createLocalWebRTCGuestSDK(options: CreateLocalWebRTCGuestSDKOptions): LocalWebRTCGuestSDK;
50
+ export {};
@@ -36,15 +36,16 @@ const websocket_connection_manager_1 = require("./websocket-connection-manager")
36
36
  class LocalWebRTCGuestSDKImpl {
37
37
  /**
38
38
  * コンストラクタ
39
- * @param wsSignalUrl WebSocketシグナルサーバーのURL
39
+ * @param options コンストラクタのオプション
40
40
  */
41
- constructor(wsSignalUrl) {
41
+ constructor(options) {
42
42
  _LocalWebRTCGuestSDKImpl_instances.add(this);
43
43
  /** WebRTCコネクションマネージャー */
44
44
  _LocalWebRTCGuestSDKImpl_webRTCConnection.set(this, void 0);
45
45
  /** WebSocketコネクションマネージャー */
46
46
  _LocalWebRTCGuestSDKImpl_websocketConnection.set(this, void 0);
47
- __classPrivateFieldSet(this, _LocalWebRTCGuestSDKImpl_webRTCConnection, new guest_webrtc_connection_manager_1.GuestWebRTCConnectionManager(), "f");
47
+ const { wsSignalUrl } = options;
48
+ __classPrivateFieldSet(this, _LocalWebRTCGuestSDKImpl_webRTCConnection, new guest_webrtc_connection_manager_1.GuestWebRTCConnectionManager(options), "f");
48
49
  __classPrivateFieldSet(this, _LocalWebRTCGuestSDKImpl_websocketConnection, new websocket_connection_manager_1.WebSocketConnectionManager(wsSignalUrl), "f");
49
50
  }
50
51
  /** @override */
@@ -52,11 +53,11 @@ class LocalWebRTCGuestSDKImpl {
52
53
  return __awaiter(this, void 0, void 0, function* () {
53
54
  const { roomID, armdozerId, pilotId } = options;
54
55
  const requestSelectedPlayerPromise = (() => __awaiter(this, void 0, void 0, function* () {
55
- const dataChannel = yield __classPrivateFieldGet(this, _LocalWebRTCGuestSDKImpl_webRTCConnection, "f").getOrCreateConnection().dataChannel;
56
+ const dataChannel = yield __classPrivateFieldGet(this, _LocalWebRTCGuestSDKImpl_webRTCConnection, "f").getOrCreateConnection().dataChannelPromise;
56
57
  return yield (0, receive_request_selected_player_1.receiveRequestSelectedPlayer)(dataChannel);
57
58
  }))();
58
59
  const battleStartPromise = (() => __awaiter(this, void 0, void 0, function* () {
59
- const dataChannel = yield __classPrivateFieldGet(this, _LocalWebRTCGuestSDKImpl_webRTCConnection, "f").getOrCreateConnection().dataChannel;
60
+ const dataChannel = yield __classPrivateFieldGet(this, _LocalWebRTCGuestSDKImpl_webRTCConnection, "f").getOrCreateConnection().dataChannelPromise;
60
61
  return yield (0, receive_battle_start_1.receiveBattleStart)(dataChannel);
61
62
  }))();
62
63
  const isSignalingSuccessful = yield __classPrivateFieldGet(this, _LocalWebRTCGuestSDKImpl_instances, "m", _LocalWebRTCGuestSDKImpl_signaling).call(this, roomID);
@@ -64,7 +65,7 @@ class LocalWebRTCGuestSDKImpl {
64
65
  return null;
65
66
  }
66
67
  const { flowID } = yield requestSelectedPlayerPromise;
67
- const dataChannel = yield __classPrivateFieldGet(this, _LocalWebRTCGuestSDKImpl_webRTCConnection, "f").getOrCreateConnection().dataChannel;
68
+ const dataChannel = yield __classPrivateFieldGet(this, _LocalWebRTCGuestSDKImpl_webRTCConnection, "f").getOrCreateConnection().dataChannelPromise;
68
69
  (0, guest_message_1.sendGuestMessage)(dataChannel, {
69
70
  type: "send-player",
70
71
  flowID,
@@ -103,7 +104,7 @@ _LocalWebRTCGuestSDKImpl_webRTCConnection = new WeakMap(), _LocalWebRTCGuestSDKI
103
104
  return false;
104
105
  }
105
106
  const { sdp: hostSDP, iceCandidates: hostIceCandidates } = joinRoomAccepted;
106
- const { connection } = __classPrivateFieldGet(this, _LocalWebRTCGuestSDKImpl_webRTCConnection, "f").getOrCreateConnection();
107
+ const connection = yield __classPrivateFieldGet(this, _LocalWebRTCGuestSDKImpl_webRTCConnection, "f").getOrCreateConnection().connectionPromise;
107
108
  yield connection.setRemoteDescription(hostSDP);
108
109
  yield Promise.all(hostIceCandidates.map((c) => connection.addIceCandidate(c)));
109
110
  const guestSDP = yield connection.createAnswer();
@@ -132,9 +133,9 @@ _LocalWebRTCGuestSDKImpl_webRTCConnection = new WeakMap(), _LocalWebRTCGuestSDKI
132
133
  };
133
134
  /**
134
135
  * ローカルWebRTCゲスト用SDKを生成する
135
- * @param wsSignalUrl WebSocketシグナルサーバーのURL
136
+ * @param options オプション
136
137
  * @returns ローカルWebRTCゲスト用SDKのインスタンス
137
138
  */
138
- function createLocalWebRTCGuestSDK(wsSignalUrl) {
139
- return new LocalWebRTCGuestSDKImpl(wsSignalUrl);
139
+ function createLocalWebRTCGuestSDK(options) {
140
+ return new LocalWebRTCGuestSDKImpl(options);
140
141
  }
@@ -1,5 +1,6 @@
1
1
  import { ArmdozerId, PilotId } from "gbraver-burst-core";
2
2
  import { Observable } from "rxjs";
3
+ import { HostWebRTCConnectionManagerOptions } from "./host-webrtc-connection-manager";
3
4
  import { LocalWebRTCRoom } from "./local-webrtc-room";
4
5
  /** ローカルWebRTCホスト用SDK */
5
6
  export type LocalWebRTCHostSDK = {
@@ -31,9 +32,17 @@ export type LocalWebRTCHostSDK = {
31
32
  */
32
33
  disconnectWebRTC(): void;
33
34
  };
35
+ /** LocalWebRTCHostSDKImplコンストラクタのオプション */
36
+ type LocalWebRTCHostSDKImplOptions = HostWebRTCConnectionManagerOptions & {
37
+ /** WebSocketシグナルサーバーのURL */
38
+ wsSignalUrl: string;
39
+ };
40
+ /** LocalWebRTCHostSDKを生成するオプション */
41
+ type CreateLocalWebRTCHostSDKOptions = LocalWebRTCHostSDKImplOptions;
34
42
  /**
35
43
  * ローカルWebRTCホスト用SDKを生成する
36
- * @param wsSignalUrl WebSocketシグナルサーバーのURL
44
+ * @param options SDK生成のオプション
37
45
  * @returns ローカルWebRTCホスト用SDKのインスタンス
38
46
  */
39
- export declare function createLocalWebRTCHostSDK(wsSignalUrl: string): LocalWebRTCHostSDK;
47
+ export declare function createLocalWebRTCHostSDK(options: CreateLocalWebRTCHostSDKOptions): LocalWebRTCHostSDK;
48
+ export {};
@@ -31,21 +31,22 @@ const websocket_connection_manager_1 = require("./websocket-connection-manager")
31
31
  class LocalWebRTCHostSDKImpl {
32
32
  /**
33
33
  * コンストラクタ
34
- * @param wsSignalUrl WebSocketシグナルサーバーのURL
34
+ * @param options コンストラクタのオプション
35
35
  */
36
- constructor(wsSignalUrl) {
36
+ constructor(options) {
37
37
  /** WebRTCコネクションマネージャー */
38
38
  _LocalWebRTCHostSDKImpl_webRTCConnection.set(this, void 0);
39
39
  /** WebSocketコネクションマネージャー */
40
40
  _LocalWebRTCHostSDKImpl_websocketConnection.set(this, void 0);
41
+ const { wsSignalUrl } = options;
41
42
  __classPrivateFieldSet(this, _LocalWebRTCHostSDKImpl_websocketConnection, new websocket_connection_manager_1.WebSocketConnectionManager(wsSignalUrl), "f");
42
- __classPrivateFieldSet(this, _LocalWebRTCHostSDKImpl_webRTCConnection, new host_webrtc_connection_manager_1.HostWebRTCConnectionManager(), "f");
43
+ __classPrivateFieldSet(this, _LocalWebRTCHostSDKImpl_webRTCConnection, new host_webrtc_connection_manager_1.HostWebRTCConnectionManager(options), "f");
43
44
  }
44
45
  /** @override */
45
46
  createRoom(options) {
46
47
  return __awaiter(this, void 0, void 0, function* () {
47
48
  try {
48
- const { connection } = __classPrivateFieldGet(this, _LocalWebRTCHostSDKImpl_webRTCConnection, "f").getOrCreateConnection();
49
+ const connection = yield __classPrivateFieldGet(this, _LocalWebRTCHostSDKImpl_webRTCConnection, "f").getOrCreateConnection().connectionPromise;
49
50
  const sdp = yield connection.createOffer();
50
51
  const [iceCandidates] = yield Promise.all([
51
52
  // icecandidateイベントはsetLocalDescriptionの後に発生するため、先に待機しておく
@@ -89,9 +90,9 @@ class LocalWebRTCHostSDKImpl {
89
90
  _LocalWebRTCHostSDKImpl_webRTCConnection = new WeakMap(), _LocalWebRTCHostSDKImpl_websocketConnection = new WeakMap();
90
91
  /**
91
92
  * ローカルWebRTCホスト用SDKを生成する
92
- * @param wsSignalUrl WebSocketシグナルサーバーのURL
93
+ * @param options SDK生成のオプション
93
94
  * @returns ローカルWebRTCホスト用SDKのインスタンス
94
95
  */
95
- function createLocalWebRTCHostSDK(wsSignalUrl) {
96
- return new LocalWebRTCHostSDKImpl(wsSignalUrl);
96
+ function createLocalWebRTCHostSDK(options) {
97
+ return new LocalWebRTCHostSDKImpl(options);
97
98
  }
@@ -61,7 +61,7 @@ class LocalWebRTCRoomImpl {
61
61
  */
62
62
  waitUntilMatching() {
63
63
  return __awaiter(this, void 0, void 0, function* () {
64
- const { dataChannel } = __classPrivateFieldGet(this, _LocalWebRTCRoomImpl_webRTCConnection, "f").getOrCreateConnection();
64
+ const dataChannel = yield __classPrivateFieldGet(this, _LocalWebRTCRoomImpl_webRTCConnection, "f").getOrCreateConnection().dataChannelPromise;
65
65
  yield Promise.all([
66
66
  __classPrivateFieldGet(this, _LocalWebRTCRoomImpl_instances, "m", _LocalWebRTCRoomImpl_signaling).call(this),
67
67
  (0, wait_until_data_channel_ready_1.waitUntilDataChannelOpen)(dataChannel),
@@ -92,7 +92,7 @@ _LocalWebRTCRoomImpl_webRTCConnection = new WeakMap(), _LocalWebRTCRoomImpl_webs
92
92
  try {
93
93
  const websocket = yield __classPrivateFieldGet(this, _LocalWebRTCRoomImpl_websocketConnection, "f").getOrCreate();
94
94
  const signal = yield (0, wait_until_matching_1.waitUntilMatching)(websocket);
95
- const { connection } = __classPrivateFieldGet(this, _LocalWebRTCRoomImpl_webRTCConnection, "f").getOrCreateConnection();
95
+ const connection = yield __classPrivateFieldGet(this, _LocalWebRTCRoomImpl_webRTCConnection, "f").getOrCreateConnection().connectionPromise;
96
96
  yield connection.setRemoteDescription(signal.sdp);
97
97
  yield Promise.all([
98
98
  ...signal.iceCandidates.map((c) => connection.addIceCandidate(c)),
@@ -0,0 +1,7 @@
1
+ import { IssueCoturnCredentialResponse } from "./response/issue-coturn-credential";
2
+ /**
3
+ * coturnクレデンシャルを発行する
4
+ * @param apiURL WebRTCヘルパーREST APIのURL
5
+ * @returns 発行したクレデンシャル
6
+ */
7
+ export declare const issueCoturnCredential: (apiURL: string) => Promise<IssueCoturnCredentialResponse>;
@@ -0,0 +1,29 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.issueCoturnCredential = void 0;
13
+ const issue_coturn_credential_1 = require("./response/issue-coturn-credential");
14
+ /**
15
+ * coturnクレデンシャルを発行する
16
+ * @param apiURL WebRTCヘルパーREST APIのURL
17
+ * @returns 発行したクレデンシャル
18
+ */
19
+ const issueCoturnCredential = (apiURL) => __awaiter(void 0, void 0, void 0, function* () {
20
+ const response = yield fetch(`${apiURL}/coturn/credentials`, {
21
+ method: "POST",
22
+ });
23
+ if (response.status !== 201) {
24
+ throw new Error(`Failed to issue coturn credential: ${response.status}`);
25
+ }
26
+ const body = yield response.json();
27
+ return issue_coturn_credential_1.IssueCoturnCredentialResponseSchema.parse(body);
28
+ });
29
+ exports.issueCoturnCredential = issueCoturnCredential;
@@ -0,0 +1,13 @@
1
+ import { z } from "zod";
2
+ /** coturn用クレデンシャル発行結果 */
3
+ export type IssueCoturnCredentialResponse = {
4
+ /** ユーザー名 */
5
+ username: string;
6
+ /** パスワード */
7
+ password: string;
8
+ };
9
+ /** IssueCoturnCredentialResponse zod スキーマ */
10
+ export declare const IssueCoturnCredentialResponseSchema: z.ZodObject<{
11
+ username: z.ZodString;
12
+ password: z.ZodString;
13
+ }, z.core.$strip>;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IssueCoturnCredentialResponseSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ /** IssueCoturnCredentialResponse zod スキーマ */
6
+ exports.IssueCoturnCredentialResponseSchema = zod_1.z.object({
7
+ username: zod_1.z.string(),
8
+ password: zod_1.z.string(),
9
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gbraver-burst-network/local-webrtc-browser-sdk",
3
3
  "description": "gbraver burst local webrtc browser sdk",
4
- "version": "1.21.0",
4
+ "version": "1.22.0",
5
5
  "author": "Y.Takeuchi",
6
6
  "bugs": {
7
7
  "url": "https://github.com/kaidouji85/gbraver-burst-network/issues",
@@ -14,13 +14,13 @@
14
14
  "devDependencies": {
15
15
  "@eslint/js": "^10.0.1",
16
16
  "dependency-cruiser": "^17.3.10",
17
- "eslint": "^10.1.0",
18
- "eslint-plugin-simple-import-sort": "^12.1.1",
17
+ "eslint": "^10.2.0",
18
+ "eslint-plugin-simple-import-sort": "^13.0.0",
19
19
  "gbraver-burst-core": "^1.44.0",
20
20
  "npm-run-all": "^4.1.5",
21
- "prettier": "^3.8.1",
21
+ "prettier": "^3.8.2",
22
22
  "rimraf": "^6.1.3",
23
- "typescript-eslint": "^8.58.0",
23
+ "typescript-eslint": "^8.58.2",
24
24
  "zod": "^4.3.6"
25
25
  },
26
26
  "files": [