@gbraver-burst-network/anonymous-browser-sdk 1.30.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.
- package/LICENSE.txt +7 -0
- package/Readme.md +37 -0
- package/lib/http-api/frontend-log.d.ts +14 -0
- package/lib/http-api/frontend-log.js +33 -0
- package/lib/http-api/issue-auth-token.d.ts +7 -0
- package/lib/http-api/issue-auth-token.js +29 -0
- package/lib/http-api/issue-coturn-credential.d.ts +12 -0
- package/lib/http-api/issue-coturn-credential.js +36 -0
- package/lib/http-api/request/frontend-log.d.ts +30 -0
- package/lib/http-api/request/frontend-log.js +2 -0
- package/lib/http-api/response/issue-auth-token.d.ts +13 -0
- package/lib/http-api/response/issue-auth-token.js +9 -0
- package/lib/http-api/response/issue-coturn-credential.d.ts +13 -0
- package/lib/http-api/response/issue-coturn-credential.js +9 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +9 -0
- package/lib/json/parse.d.ts +7 -0
- package/lib/json/parse.js +20 -0
- package/lib/sdk/auth-token-manager.d.ts +23 -0
- package/lib/sdk/auth-token-manager.js +72 -0
- package/lib/sdk/battle-sdk.d.ts +25 -0
- package/lib/sdk/battle-sdk.js +2 -0
- package/lib/sdk/create-rtc-peer-connection.d.ts +13 -0
- package/lib/sdk/create-rtc-peer-connection.js +45 -0
- package/lib/sdk/frontend-log-manager.d.ts +23 -0
- package/lib/sdk/frontend-log-manager.js +65 -0
- package/lib/sdk/guest-battle-sdk.d.ts +36 -0
- package/lib/sdk/guest-battle-sdk.js +78 -0
- package/lib/sdk/guest-local-webrtc-sdk.d.ts +54 -0
- package/lib/sdk/guest-local-webrtc-sdk.js +194 -0
- package/lib/sdk/guest-webrtc-connection-manager.d.ts +33 -0
- package/lib/sdk/guest-webrtc-connection-manager.js +71 -0
- package/lib/sdk/host-battle-sdk.d.ts +39 -0
- package/lib/sdk/host-battle-sdk.js +108 -0
- package/lib/sdk/host-local-webrtc-sdk.d.ts +50 -0
- package/lib/sdk/host-local-webrtc-sdk.js +99 -0
- package/lib/sdk/host-webrtc-connection-manager.d.ts +37 -0
- package/lib/sdk/host-webrtc-connection-manager.js +84 -0
- package/lib/sdk/local-webrtc-room.d.ts +44 -0
- package/lib/sdk/local-webrtc-room.js +178 -0
- package/lib/sdk/websocket-connection-manager.d.ts +34 -0
- package/lib/sdk/websocket-connection-manager.js +92 -0
- package/lib/webrtc/gather-all-ice-candidate.d.ts +20 -0
- package/lib/webrtc/gather-all-ice-candidate.js +45 -0
- package/lib/webrtc/get-selected-ice-candidate-summary.d.ts +6 -0
- package/lib/webrtc/get-selected-ice-candidate-summary.js +36 -0
- package/lib/webrtc/guest/guest-message.d.ts +48 -0
- package/lib/webrtc/guest/guest-message.js +27 -0
- package/lib/webrtc/guest/receive-battle-progressed.d.ts +7 -0
- package/lib/webrtc/guest/receive-battle-progressed.js +29 -0
- package/lib/webrtc/guest/receive-battle-start.d.ts +7 -0
- package/lib/webrtc/guest/receive-battle-start.js +29 -0
- package/lib/webrtc/guest/receive-request-selected-player.d.ts +7 -0
- package/lib/webrtc/guest/receive-request-selected-player.js +29 -0
- package/lib/webrtc/guest/wait-until-data-channel.d.ts +6 -0
- package/lib/webrtc/guest/wait-until-data-channel.js +14 -0
- package/lib/webrtc/host/host-message.d.ts +1001 -0
- package/lib/webrtc/host/host-message.js +33 -0
- package/lib/webrtc/host/receive-send-command.d.ts +8 -0
- package/lib/webrtc/host/receive-send-command.js +31 -0
- package/lib/webrtc/host/request-selected-player.d.ts +16 -0
- package/lib/webrtc/host/request-selected-player.js +35 -0
- package/lib/webrtc/notify-connection-failed.d.ts +7 -0
- package/lib/webrtc/notify-connection-failed.js +11 -0
- package/lib/webrtc/rtc-ice-candidate-init-schema.d.ts +8 -0
- package/lib/webrtc/rtc-ice-candidate-init-schema.js +11 -0
- package/lib/webrtc/rtc-session-description-init-schema.d.ts +11 -0
- package/lib/webrtc/rtc-session-description-init-schema.js +9 -0
- package/lib/webrtc/wait-until-connected.d.ts +6 -0
- package/lib/webrtc/wait-until-connected.js +28 -0
- package/lib/webrtc/wait-until-data-channel-ready.d.ts +6 -0
- package/lib/webrtc/wait-until-data-channel-ready.js +28 -0
- package/lib/websocket-api/connect-ws-signal.d.ts +7 -0
- package/lib/websocket-api/connect-ws-signal.js +29 -0
- package/lib/websocket-api/create-room.d.ts +6 -0
- package/lib/websocket-api/create-room.js +37 -0
- package/lib/websocket-api/delete-signaling-channel.d.ts +11 -0
- package/lib/websocket-api/delete-signaling-channel.js +43 -0
- package/lib/websocket-api/join-room.d.ts +12 -0
- package/lib/websocket-api/join-room.js +40 -0
- package/lib/websocket-api/notify-ice-candidate-recieved.d.ts +7 -0
- package/lib/websocket-api/notify-ice-candidate-recieved.js +13 -0
- package/lib/websocket-api/request/create-room.d.ts +4 -0
- package/lib/websocket-api/request/create-room.js +2 -0
- package/lib/websocket-api/request/delete-signaling-channel.d.ts +6 -0
- package/lib/websocket-api/request/delete-signaling-channel.js +2 -0
- package/lib/websocket-api/request/index.d.ts +7 -0
- package/lib/websocket-api/request/index.js +2 -0
- package/lib/websocket-api/request/join-room.d.ts +6 -0
- package/lib/websocket-api/request/join-room.js +2 -0
- package/lib/websocket-api/request/send-ice-candidate.d.ts +8 -0
- package/lib/websocket-api/request/send-ice-candidate.js +2 -0
- package/lib/websocket-api/request/send-sdp.d.ts +8 -0
- package/lib/websocket-api/request/send-sdp.js +2 -0
- package/lib/websocket-api/response/delete-signaling-channel-accepted.d.ts +9 -0
- package/lib/websocket-api/response/delete-signaling-channel-accepted.js +8 -0
- package/lib/websocket-api/response/delete-signaling-channel-rejected.d.ts +9 -0
- package/lib/websocket-api/response/delete-signaling-channel-rejected.js +8 -0
- package/lib/websocket-api/response/join-room-accepted.d.ts +12 -0
- package/lib/websocket-api/response/join-room-accepted.js +9 -0
- package/lib/websocket-api/response/join-room-rejected.d.ts +9 -0
- package/lib/websocket-api/response/join-room-rejected.js +8 -0
- package/lib/websocket-api/response/matching.d.ts +12 -0
- package/lib/websocket-api/response/matching.js +9 -0
- package/lib/websocket-api/response/receive-ice-candidate.d.ts +20 -0
- package/lib/websocket-api/response/receive-ice-candidate.js +11 -0
- package/lib/websocket-api/response/receive-remote-sdp.d.ts +23 -0
- package/lib/websocket-api/response/receive-remote-sdp.js +11 -0
- package/lib/websocket-api/response/room-creation-result.d.ts +37 -0
- package/lib/websocket-api/response/room-creation-result.js +20 -0
- package/lib/websocket-api/response/send-sdp-rejected.d.ts +9 -0
- package/lib/websocket-api/response/send-sdp-rejected.js +8 -0
- package/lib/websocket-api/send-to-ws-signal.d.ts +7 -0
- package/lib/websocket-api/send-to-ws-signal.js +11 -0
- package/lib/websocket-api/wait-until-matching.d.ts +6 -0
- package/lib/websocket-api/wait-until-matching.js +29 -0
- package/lib/websocket-api/wait-until-sdp-recieve.d.ts +6 -0
- package/lib/websocket-api/wait-until-sdp-recieve.js +33 -0
- 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
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FrontendLog } from "./request/frontend-log";
|
|
2
|
+
/**
|
|
3
|
+
* フロントエンドのログを記録する
|
|
4
|
+
* @param options 記録するログのオプション
|
|
5
|
+
* @param options.authToken 認証トークン
|
|
6
|
+
* @param options.body 記録するログの内容
|
|
7
|
+
* @param options.apiURL WebRTCヘルパーREST APIのURL
|
|
8
|
+
* @returns ログ記録結果、trueで成功
|
|
9
|
+
*/
|
|
10
|
+
export declare const frontendLog: (options: {
|
|
11
|
+
apiURL: string;
|
|
12
|
+
authToken: string;
|
|
13
|
+
body: FrontendLog;
|
|
14
|
+
}) => Promise<boolean>;
|
|
@@ -0,0 +1,33 @@
|
|
|
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.frontendLog = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* フロントエンドのログを記録する
|
|
15
|
+
* @param options 記録するログのオプション
|
|
16
|
+
* @param options.authToken 認証トークン
|
|
17
|
+
* @param options.body 記録するログの内容
|
|
18
|
+
* @param options.apiURL WebRTCヘルパーREST APIのURL
|
|
19
|
+
* @returns ログ記録結果、trueで成功
|
|
20
|
+
*/
|
|
21
|
+
const frontendLog = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
const { apiURL, authToken, body } = options;
|
|
23
|
+
const response = yield fetch(`${apiURL}/frontend-log`, {
|
|
24
|
+
method: "POST",
|
|
25
|
+
headers: {
|
|
26
|
+
"Content-Type": "application/json",
|
|
27
|
+
Authorization: `Bearer ${authToken}`,
|
|
28
|
+
},
|
|
29
|
+
body: JSON.stringify(body),
|
|
30
|
+
});
|
|
31
|
+
return response.status === 201;
|
|
32
|
+
});
|
|
33
|
+
exports.frontendLog = frontendLog;
|
|
@@ -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.issueAuthToken = void 0;
|
|
13
|
+
const issue_auth_token_1 = require("./response/issue-auth-token");
|
|
14
|
+
/**
|
|
15
|
+
* 認証トークンを発行する
|
|
16
|
+
* @param apiURL WebRTCヘルパーREST APIのURL
|
|
17
|
+
* @returns 発行した認証トークン
|
|
18
|
+
*/
|
|
19
|
+
const issueAuthToken = (apiURL) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
const response = yield fetch(`${apiURL}/auth-token`, {
|
|
21
|
+
method: "POST",
|
|
22
|
+
});
|
|
23
|
+
if (response.status !== 201) {
|
|
24
|
+
throw new Error(`Failed to issue auth token: ${response.status}`);
|
|
25
|
+
}
|
|
26
|
+
const body = yield response.json();
|
|
27
|
+
return issue_auth_token_1.IssueAuthTokenResponseSchema.parse(body);
|
|
28
|
+
});
|
|
29
|
+
exports.issueAuthToken = issueAuthToken;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IssueCoturnCredentialResponse } from "./response/issue-coturn-credential";
|
|
2
|
+
/**
|
|
3
|
+
* coturnクレデンシャルを発行する
|
|
4
|
+
* @param options オプション
|
|
5
|
+
* @param options.apiURL WebRTCヘルパーREST APIのURL
|
|
6
|
+
* @param options.authToken 認証トークン
|
|
7
|
+
* @returns 発行したクレデンシャル
|
|
8
|
+
*/
|
|
9
|
+
export declare const issueCoturnCredential: (options: {
|
|
10
|
+
apiURL: string;
|
|
11
|
+
authToken: string;
|
|
12
|
+
}) => Promise<IssueCoturnCredentialResponse>;
|
|
@@ -0,0 +1,36 @@
|
|
|
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 options オプション
|
|
17
|
+
* @param options.apiURL WebRTCヘルパーREST APIのURL
|
|
18
|
+
* @param options.authToken 認証トークン
|
|
19
|
+
* @returns 発行したクレデンシャル
|
|
20
|
+
*/
|
|
21
|
+
const issueCoturnCredential = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
const { apiURL, authToken } = options;
|
|
23
|
+
const response = yield fetch(`${apiURL}/coturn/credentials`, {
|
|
24
|
+
method: "POST",
|
|
25
|
+
headers: {
|
|
26
|
+
"Content-Type": "application/json",
|
|
27
|
+
Authorization: `Bearer ${authToken}`,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
if (response.status !== 201) {
|
|
31
|
+
throw new Error(`Failed to issue coturn credential: ${response.status}`);
|
|
32
|
+
}
|
|
33
|
+
const body = yield response.json();
|
|
34
|
+
return issue_coturn_credential_1.IssueCoturnCredentialResponseSchema.parse(body);
|
|
35
|
+
});
|
|
36
|
+
exports.issueCoturnCredential = issueCoturnCredential;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** 選択されたICE Candidateの概要 */
|
|
2
|
+
export type SelectedIceCandidateSummary = {
|
|
3
|
+
type: "SELECTED_ICE_CANDIDATE_SUMMARY";
|
|
4
|
+
/** スパンID */
|
|
5
|
+
spanId: string;
|
|
6
|
+
/** ICE Candidate概要 */
|
|
7
|
+
summary: string;
|
|
8
|
+
};
|
|
9
|
+
/** ログ:ICE候補収集エラー */
|
|
10
|
+
export type ICECandidateError = {
|
|
11
|
+
type: "ICE_CANDIDATE_ERROR";
|
|
12
|
+
/** スパンID */
|
|
13
|
+
spanId: string;
|
|
14
|
+
/** エラーメッセージ */
|
|
15
|
+
error: string;
|
|
16
|
+
};
|
|
17
|
+
/** ログ:シグナリング開始 */
|
|
18
|
+
export type SignalingStart = {
|
|
19
|
+
type: "SIGNALING_START";
|
|
20
|
+
/** スパンID */
|
|
21
|
+
spanId: string;
|
|
22
|
+
};
|
|
23
|
+
/** ログ:シグナリング終了 */
|
|
24
|
+
export type SignalingEnd = {
|
|
25
|
+
type: "SIGNALING_END";
|
|
26
|
+
/** スパンID */
|
|
27
|
+
spanId: string;
|
|
28
|
+
};
|
|
29
|
+
/** フロントエンドログ */
|
|
30
|
+
export type FrontendLog = SelectedIceCandidateSummary | ICECandidateError | SignalingStart | SignalingEnd;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** 認証トークン発行レスポンス */
|
|
3
|
+
export type IssueAuthTokenResponse = {
|
|
4
|
+
/** トークン文字列 */
|
|
5
|
+
token: string;
|
|
6
|
+
/** トークンの有効期限(Unix時間) */
|
|
7
|
+
expiresAt: number;
|
|
8
|
+
};
|
|
9
|
+
/** IssueAuthTokenResponse zodスキーマ */
|
|
10
|
+
export declare const IssueAuthTokenResponseSchema: z.ZodObject<{
|
|
11
|
+
token: z.ZodString;
|
|
12
|
+
expiresAt: z.ZodNumber;
|
|
13
|
+
}, z.core.$strip>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IssueAuthTokenResponseSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/** IssueAuthTokenResponse zodスキーマ */
|
|
6
|
+
exports.IssueAuthTokenResponseSchema = zod_1.z.object({
|
|
7
|
+
token: zod_1.z.string(),
|
|
8
|
+
expiresAt: zod_1.z.number(),
|
|
9
|
+
});
|
|
@@ -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/lib/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { AuthTokenManager, createAuthTokenManager, } from "./sdk/auth-token-manager";
|
|
2
|
+
export { BattleSDK } from "./sdk/battle-sdk";
|
|
3
|
+
export { createGuestLocalWebRTCSDK, GuestLocalWebRTCSDK, } from "./sdk/guest-local-webrtc-sdk";
|
|
4
|
+
export { createHostLocalWebRTCSDK, HostLocalWebRTCSDK, } from "./sdk/host-local-webrtc-sdk";
|
|
5
|
+
export { LocalWebRTCRoom } from "./sdk/local-webrtc-room";
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createHostLocalWebRTCSDK = exports.createGuestLocalWebRTCSDK = exports.createAuthTokenManager = void 0;
|
|
4
|
+
var auth_token_manager_1 = require("./sdk/auth-token-manager");
|
|
5
|
+
Object.defineProperty(exports, "createAuthTokenManager", { enumerable: true, get: function () { return auth_token_manager_1.createAuthTokenManager; } });
|
|
6
|
+
var guest_local_webrtc_sdk_1 = require("./sdk/guest-local-webrtc-sdk");
|
|
7
|
+
Object.defineProperty(exports, "createGuestLocalWebRTCSDK", { enumerable: true, get: function () { return guest_local_webrtc_sdk_1.createGuestLocalWebRTCSDK; } });
|
|
8
|
+
var host_local_webrtc_sdk_1 = require("./sdk/host-local-webrtc-sdk");
|
|
9
|
+
Object.defineProperty(exports, "createHostLocalWebRTCSDK", { enumerable: true, get: function () { return host_local_webrtc_sdk_1.createHostLocalWebRTCSDK; } });
|
|
@@ -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,23 @@
|
|
|
1
|
+
/** 認証トークン */
|
|
2
|
+
export type AuthToken = {
|
|
3
|
+
/** トークン文字列 */
|
|
4
|
+
token: string;
|
|
5
|
+
/** トークンの有効期限(Unix時間) */
|
|
6
|
+
expiresAt: number;
|
|
7
|
+
};
|
|
8
|
+
/** 認証トークンマネージャー */
|
|
9
|
+
export interface AuthTokenManager {
|
|
10
|
+
/**
|
|
11
|
+
* 認証トークンを取得する(必要なら再発行する)
|
|
12
|
+
* キャッシュ済みトークンが再利用可能ならそれを返し、
|
|
13
|
+
* そうでなければ新しいトークンを発行して返す
|
|
14
|
+
* @returns 認証トークン
|
|
15
|
+
*/
|
|
16
|
+
getOrIssueAuthToken(): Promise<AuthToken>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 認証トークンマネージャーを生成する
|
|
20
|
+
* @param webRTCHelperApiURL WebRTCヘルパーAPIのURL
|
|
21
|
+
* @returns 生成した認証トークンマネージャー
|
|
22
|
+
*/
|
|
23
|
+
export declare const createAuthTokenManager: (webRTCHelperApiURL: string) => AuthTokenManager;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
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");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
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 _AuthTokenManagerImpl_instances, _AuthTokenManagerImpl_webRTCHelperApiURL, _AuthTokenManagerImpl_authTokenPromise, _AuthTokenManagerImpl_issueAuthTokenWithReset;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.createAuthTokenManager = void 0;
|
|
16
|
+
const issue_auth_token_1 = require("../http-api/issue-auth-token");
|
|
17
|
+
/**
|
|
18
|
+
* トークン再利用のしきい値(秒)
|
|
19
|
+
* 残り有効時間がこの値以下になったら、再利用せず再発行する
|
|
20
|
+
*/
|
|
21
|
+
const TOKEN_REUSE_CUTOFF_SECONDS = 60 * 5;
|
|
22
|
+
/**
|
|
23
|
+
* トークンを再利用できるか判定する
|
|
24
|
+
* 残り有効時間がしきい値より長い場合のみ、再利用可能とする
|
|
25
|
+
* @param authToken 認証トークン
|
|
26
|
+
* @returns 判定結果、再利用可能ならtrue、トークンの再発行が必要ならfalse
|
|
27
|
+
*/
|
|
28
|
+
const canReuseToken = (authToken) => {
|
|
29
|
+
const now = Date.now() / 1000;
|
|
30
|
+
return now < authToken.expiresAt - TOKEN_REUSE_CUTOFF_SECONDS;
|
|
31
|
+
};
|
|
32
|
+
/** 認証トークンマネージャーの実装 */
|
|
33
|
+
class AuthTokenManagerImpl {
|
|
34
|
+
/**
|
|
35
|
+
* コンストラクタ
|
|
36
|
+
* @param webRTCHelperApiURL WebRTCヘルパーAPIのURL
|
|
37
|
+
*/
|
|
38
|
+
constructor(webRTCHelperApiURL) {
|
|
39
|
+
_AuthTokenManagerImpl_instances.add(this);
|
|
40
|
+
/** WebRTCヘルパーAPIのURL */
|
|
41
|
+
_AuthTokenManagerImpl_webRTCHelperApiURL.set(this, void 0);
|
|
42
|
+
/** 認証トークンPromise、未発行時はnull */
|
|
43
|
+
_AuthTokenManagerImpl_authTokenPromise.set(this, null);
|
|
44
|
+
__classPrivateFieldSet(this, _AuthTokenManagerImpl_webRTCHelperApiURL, webRTCHelperApiURL, "f");
|
|
45
|
+
}
|
|
46
|
+
/** @override */
|
|
47
|
+
getOrIssueAuthToken() {
|
|
48
|
+
if (__classPrivateFieldGet(this, _AuthTokenManagerImpl_authTokenPromise, "f") === null) {
|
|
49
|
+
__classPrivateFieldSet(this, _AuthTokenManagerImpl_authTokenPromise, __classPrivateFieldGet(this, _AuthTokenManagerImpl_instances, "m", _AuthTokenManagerImpl_issueAuthTokenWithReset).call(this), "f");
|
|
50
|
+
return __classPrivateFieldGet(this, _AuthTokenManagerImpl_authTokenPromise, "f");
|
|
51
|
+
}
|
|
52
|
+
__classPrivateFieldSet(this, _AuthTokenManagerImpl_authTokenPromise, __classPrivateFieldGet(this, _AuthTokenManagerImpl_authTokenPromise, "f").then((token) => {
|
|
53
|
+
return canReuseToken(token) ? token : __classPrivateFieldGet(this, _AuthTokenManagerImpl_instances, "m", _AuthTokenManagerImpl_issueAuthTokenWithReset).call(this);
|
|
54
|
+
}), "f");
|
|
55
|
+
return __classPrivateFieldGet(this, _AuthTokenManagerImpl_authTokenPromise, "f");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
_AuthTokenManagerImpl_webRTCHelperApiURL = new WeakMap(), _AuthTokenManagerImpl_authTokenPromise = new WeakMap(), _AuthTokenManagerImpl_instances = new WeakSet(), _AuthTokenManagerImpl_issueAuthTokenWithReset = function _AuthTokenManagerImpl_issueAuthTokenWithReset() {
|
|
59
|
+
return (0, issue_auth_token_1.issueAuthToken)(__classPrivateFieldGet(this, _AuthTokenManagerImpl_webRTCHelperApiURL, "f")).catch((error) => {
|
|
60
|
+
__classPrivateFieldSet(this, _AuthTokenManagerImpl_authTokenPromise, null, "f");
|
|
61
|
+
throw error;
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* 認証トークンマネージャーを生成する
|
|
66
|
+
* @param webRTCHelperApiURL WebRTCヘルパーAPIのURL
|
|
67
|
+
* @returns 生成した認証トークンマネージャー
|
|
68
|
+
*/
|
|
69
|
+
const createAuthTokenManager = (webRTCHelperApiURL) => {
|
|
70
|
+
return new AuthTokenManagerImpl(webRTCHelperApiURL);
|
|
71
|
+
};
|
|
72
|
+
exports.createAuthTokenManager = createAuthTokenManager;
|
|
@@ -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,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RTCPeerConnectionを作成する
|
|
3
|
+
* @param options オプション
|
|
4
|
+
* @param options.webRTCHelperApiURL WebRTCヘルパーAPIのURL
|
|
5
|
+
* @param options.coturnDomainName coturnサーバーのドメイン名
|
|
6
|
+
* @param options.authToken 認証トークン
|
|
7
|
+
* @returns 作成したRTCPeerConnection
|
|
8
|
+
*/
|
|
9
|
+
export declare const createRTCPeerConnection: (options: {
|
|
10
|
+
webRTCHelperApiURL: string;
|
|
11
|
+
coturnDomainName: string;
|
|
12
|
+
authToken: string;
|
|
13
|
+
}) => Promise<RTCPeerConnection>;
|
|
@@ -0,0 +1,45 @@
|
|
|
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("../http-api/issue-coturn-credential");
|
|
14
|
+
/**
|
|
15
|
+
* RTCPeerConnectionを作成する
|
|
16
|
+
* @param options オプション
|
|
17
|
+
* @param options.webRTCHelperApiURL WebRTCヘルパーAPIのURL
|
|
18
|
+
* @param options.coturnDomainName coturnサーバーのドメイン名
|
|
19
|
+
* @param options.authToken 認証トークン
|
|
20
|
+
* @returns 作成したRTCPeerConnection
|
|
21
|
+
*/
|
|
22
|
+
const createRTCPeerConnection = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
const { webRTCHelperApiURL, coturnDomainName, authToken } = options;
|
|
24
|
+
const { username, password: credential } = yield (0, issue_coturn_credential_1.issueCoturnCredential)({
|
|
25
|
+
apiURL: webRTCHelperApiURL,
|
|
26
|
+
authToken,
|
|
27
|
+
});
|
|
28
|
+
return new RTCPeerConnection({
|
|
29
|
+
iceServers: [
|
|
30
|
+
{
|
|
31
|
+
urls: [`stun:${coturnDomainName}:3478`],
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
urls: [
|
|
35
|
+
`turn:${coturnDomainName}:3478?transport=udp`,
|
|
36
|
+
`turn:${coturnDomainName}:3478?transport=tcp`,
|
|
37
|
+
`turns:${coturnDomainName}:5349?transport=tcp`,
|
|
38
|
+
],
|
|
39
|
+
username,
|
|
40
|
+
credential,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
exports.createRTCPeerConnection = createRTCPeerConnection;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { FrontendLog } from "../http-api/request/frontend-log";
|
|
2
|
+
import { AuthTokenManager } from "./auth-token-manager";
|
|
3
|
+
/** フロントエンドログマネージャー */
|
|
4
|
+
export declare class FrontendLogManager {
|
|
5
|
+
#private;
|
|
6
|
+
/**
|
|
7
|
+
* コンストラクタ
|
|
8
|
+
* @param options コンストラクタのオプション
|
|
9
|
+
* @param options.webRTCHelperApiURL WebRTCヘルパーAPIのURL
|
|
10
|
+
* @param options.authTokenManager 認証トークンマネージャー
|
|
11
|
+
*/
|
|
12
|
+
constructor(options: {
|
|
13
|
+
webRTCHelperApiURL: string;
|
|
14
|
+
authToken: AuthTokenManager;
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* フロントエンドログを送信する
|
|
18
|
+
* ログの失敗で以降の処理を止めるべきではないため、例外は握りつぶしてfalseを返す
|
|
19
|
+
* @param body ログ内容
|
|
20
|
+
* @returns ログ送信結果、成功ならtrue
|
|
21
|
+
*/
|
|
22
|
+
log(body: FrontendLog): Promise<boolean>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 _FrontendLogManager_authToken, _FrontendLogManager_webRTCHelperApiURL;
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.FrontendLogManager = void 0;
|
|
25
|
+
const frontend_log_1 = require("../http-api/frontend-log");
|
|
26
|
+
/** フロントエンドログマネージャー */
|
|
27
|
+
class FrontendLogManager {
|
|
28
|
+
/**
|
|
29
|
+
* コンストラクタ
|
|
30
|
+
* @param options コンストラクタのオプション
|
|
31
|
+
* @param options.webRTCHelperApiURL WebRTCヘルパーAPIのURL
|
|
32
|
+
* @param options.authTokenManager 認証トークンマネージャー
|
|
33
|
+
*/
|
|
34
|
+
constructor(options) {
|
|
35
|
+
/** 認証トークンマネージャー */
|
|
36
|
+
_FrontendLogManager_authToken.set(this, void 0);
|
|
37
|
+
/** WebRTCヘルパーAPIのURL */
|
|
38
|
+
_FrontendLogManager_webRTCHelperApiURL.set(this, void 0);
|
|
39
|
+
__classPrivateFieldSet(this, _FrontendLogManager_authToken, options.authToken, "f");
|
|
40
|
+
__classPrivateFieldSet(this, _FrontendLogManager_webRTCHelperApiURL, options.webRTCHelperApiURL, "f");
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* フロントエンドログを送信する
|
|
44
|
+
* ログの失敗で以降の処理を止めるべきではないため、例外は握りつぶしてfalseを返す
|
|
45
|
+
* @param body ログ内容
|
|
46
|
+
* @returns ログ送信結果、成功ならtrue
|
|
47
|
+
*/
|
|
48
|
+
log(body) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
try {
|
|
51
|
+
const authToken = yield __classPrivateFieldGet(this, _FrontendLogManager_authToken, "f").getOrIssueAuthToken();
|
|
52
|
+
return yield (0, frontend_log_1.frontendLog)({
|
|
53
|
+
apiURL: __classPrivateFieldGet(this, _FrontendLogManager_webRTCHelperApiURL, "f"),
|
|
54
|
+
authToken: authToken.token,
|
|
55
|
+
body,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
catch (_a) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.FrontendLogManager = FrontendLogManager;
|
|
65
|
+
_FrontendLogManager_authToken = new WeakMap(), _FrontendLogManager_webRTCHelperApiURL = new WeakMap();
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
/** @override */
|
|
35
|
+
suddenlyBattleEndNotifier(): Observable<unknown>;
|
|
36
|
+
}
|