@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
|
@@ -0,0 +1,99 @@
|
|
|
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 _HostLocalWebRTCSDKImpl_webRTCConnection, _HostLocalWebRTCSDKImpl_websocketConnection, _HostLocalWebRTCSDKImpl_frontendLog;
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.createHostLocalWebRTCSDK = createHostLocalWebRTCSDK;
|
|
25
|
+
const nanoid_1 = require("nanoid");
|
|
26
|
+
const create_room_1 = require("../websocket-api/create-room");
|
|
27
|
+
const frontend_log_manager_1 = require("./frontend-log-manager");
|
|
28
|
+
const host_webrtc_connection_manager_1 = require("./host-webrtc-connection-manager");
|
|
29
|
+
const local_webrtc_room_1 = require("./local-webrtc-room");
|
|
30
|
+
const websocket_connection_manager_1 = require("./websocket-connection-manager");
|
|
31
|
+
/** ローカルWebRTCホスト用SDKの実装 */
|
|
32
|
+
class HostLocalWebRTCSDKImpl {
|
|
33
|
+
/**
|
|
34
|
+
* コンストラクタ
|
|
35
|
+
* @param options コンストラクタのオプション
|
|
36
|
+
*/
|
|
37
|
+
constructor(options) {
|
|
38
|
+
/** WebRTCコネクションマネージャー */
|
|
39
|
+
_HostLocalWebRTCSDKImpl_webRTCConnection.set(this, void 0);
|
|
40
|
+
/** WebSocketコネクションマネージャー */
|
|
41
|
+
_HostLocalWebRTCSDKImpl_websocketConnection.set(this, void 0);
|
|
42
|
+
/** フロントエンドログマネージャー */
|
|
43
|
+
_HostLocalWebRTCSDKImpl_frontendLog.set(this, void 0);
|
|
44
|
+
__classPrivateFieldSet(this, _HostLocalWebRTCSDKImpl_websocketConnection, new websocket_connection_manager_1.WebSocketConnectionManager(options), "f");
|
|
45
|
+
__classPrivateFieldSet(this, _HostLocalWebRTCSDKImpl_webRTCConnection, new host_webrtc_connection_manager_1.HostWebRTCConnectionManager(options), "f");
|
|
46
|
+
__classPrivateFieldSet(this, _HostLocalWebRTCSDKImpl_frontendLog, new frontend_log_manager_1.FrontendLogManager(options), "f");
|
|
47
|
+
}
|
|
48
|
+
/** @override */
|
|
49
|
+
createRoom(options) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
const spanId = (0, nanoid_1.nanoid)();
|
|
52
|
+
try {
|
|
53
|
+
__classPrivateFieldGet(this, _HostLocalWebRTCSDKImpl_websocketConnection, "f").gracefulDisconnect();
|
|
54
|
+
__classPrivateFieldGet(this, _HostLocalWebRTCSDKImpl_webRTCConnection, "f").disconnect();
|
|
55
|
+
const websocket = yield __classPrivateFieldGet(this, _HostLocalWebRTCSDKImpl_websocketConnection, "f").getOrCreate();
|
|
56
|
+
const roomID = yield (0, create_room_1.createRoom)(websocket);
|
|
57
|
+
if (roomID === null) {
|
|
58
|
+
__classPrivateFieldGet(this, _HostLocalWebRTCSDKImpl_websocketConnection, "f").gracefulDisconnect();
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
const { armdozerId: hostArmdozerId, pilotId: hostPilotId } = options;
|
|
62
|
+
return new local_webrtc_room_1.LocalWebRTCRoomImpl({
|
|
63
|
+
roomID,
|
|
64
|
+
spanId,
|
|
65
|
+
webRTCConnection: __classPrivateFieldGet(this, _HostLocalWebRTCSDKImpl_webRTCConnection, "f"),
|
|
66
|
+
websocketConnection: __classPrivateFieldGet(this, _HostLocalWebRTCSDKImpl_websocketConnection, "f"),
|
|
67
|
+
frontendLog: __classPrivateFieldGet(this, _HostLocalWebRTCSDKImpl_frontendLog, "f"),
|
|
68
|
+
hostArmdozerId,
|
|
69
|
+
hostPilotId,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
__classPrivateFieldGet(this, _HostLocalWebRTCSDKImpl_websocketConnection, "f").gracefulDisconnect();
|
|
74
|
+
throw e;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/** @override */
|
|
79
|
+
websocketErrorNotifier() {
|
|
80
|
+
return __classPrivateFieldGet(this, _HostLocalWebRTCSDKImpl_websocketConnection, "f").errorNotifier();
|
|
81
|
+
}
|
|
82
|
+
/** @override */
|
|
83
|
+
disconnectWebSocket() {
|
|
84
|
+
__classPrivateFieldGet(this, _HostLocalWebRTCSDKImpl_websocketConnection, "f").gracefulDisconnect();
|
|
85
|
+
}
|
|
86
|
+
/** @override */
|
|
87
|
+
disconnectWebRTC() {
|
|
88
|
+
__classPrivateFieldGet(this, _HostLocalWebRTCSDKImpl_webRTCConnection, "f").disconnect();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
_HostLocalWebRTCSDKImpl_webRTCConnection = new WeakMap(), _HostLocalWebRTCSDKImpl_websocketConnection = new WeakMap(), _HostLocalWebRTCSDKImpl_frontendLog = new WeakMap();
|
|
92
|
+
/**
|
|
93
|
+
* ローカルWebRTCホスト用SDKを生成する
|
|
94
|
+
* @param options SDK生成のオプション
|
|
95
|
+
* @returns ローカルWebRTCホスト用SDKのインスタンス
|
|
96
|
+
*/
|
|
97
|
+
function createHostLocalWebRTCSDK(options) {
|
|
98
|
+
return new HostLocalWebRTCSDKImpl(options);
|
|
99
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { AuthTokenManager } from "./auth-token-manager";
|
|
2
|
+
/** コネクション情報 */
|
|
3
|
+
type Connection = {
|
|
4
|
+
/** WebRTCコネクション */
|
|
5
|
+
connection: RTCPeerConnection;
|
|
6
|
+
/** データチャンネル */
|
|
7
|
+
dataChannel: RTCDataChannel;
|
|
8
|
+
};
|
|
9
|
+
/** HostWebRTCConnectionManagerコンストラクタのオプション */
|
|
10
|
+
export type HostWebRTCConnectionManagerOptions = {
|
|
11
|
+
/** 認証トークンマネージャー */
|
|
12
|
+
authToken: AuthTokenManager;
|
|
13
|
+
/** WebRTCヘルパーAPIのURL */
|
|
14
|
+
webRTCHelperApiURL: string;
|
|
15
|
+
/** coturnサーバーのドメイン名 */
|
|
16
|
+
coturnDomainName: string;
|
|
17
|
+
};
|
|
18
|
+
/** ホストのWebRTCコネクション管理 */
|
|
19
|
+
export declare class HostWebRTCConnectionManager {
|
|
20
|
+
#private;
|
|
21
|
+
/**
|
|
22
|
+
* コンストラクタ
|
|
23
|
+
* @param options オプション
|
|
24
|
+
*/
|
|
25
|
+
constructor(options: HostWebRTCConnectionManagerOptions);
|
|
26
|
+
/**
|
|
27
|
+
* コネクションを取得する。
|
|
28
|
+
* コネクションが存在しない場合は新たに作成する。
|
|
29
|
+
* @returns 生成したコネクション
|
|
30
|
+
*/
|
|
31
|
+
getOrCreateConnection(): Promise<Connection>;
|
|
32
|
+
/**
|
|
33
|
+
* コネクションを切断する
|
|
34
|
+
*/
|
|
35
|
+
disconnect(): void;
|
|
36
|
+
}
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
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 _HostWebRTCConnectionManager_authToken, _HostWebRTCConnectionManager_connection, _HostWebRTCConnectionManager_webRTCHelperApiURL, _HostWebRTCConnectionManager_coturnDomainName;
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.HostWebRTCConnectionManager = void 0;
|
|
25
|
+
const create_rtc_peer_connection_1 = require("./create-rtc-peer-connection");
|
|
26
|
+
/** ホストのWebRTCコネクション管理 */
|
|
27
|
+
class HostWebRTCConnectionManager {
|
|
28
|
+
/**
|
|
29
|
+
* コンストラクタ
|
|
30
|
+
* @param options オプション
|
|
31
|
+
*/
|
|
32
|
+
constructor(options) {
|
|
33
|
+
/** 認証トークンマネージャー */
|
|
34
|
+
_HostWebRTCConnectionManager_authToken.set(this, void 0);
|
|
35
|
+
/** コネクション情報、nullで未接続 */
|
|
36
|
+
_HostWebRTCConnectionManager_connection.set(this, null);
|
|
37
|
+
/** WebRTCヘルパーAPIのURL */
|
|
38
|
+
_HostWebRTCConnectionManager_webRTCHelperApiURL.set(this, void 0);
|
|
39
|
+
/** coturnサーバーのドメイン名 */
|
|
40
|
+
_HostWebRTCConnectionManager_coturnDomainName.set(this, void 0);
|
|
41
|
+
__classPrivateFieldSet(this, _HostWebRTCConnectionManager_authToken, options.authToken, "f");
|
|
42
|
+
__classPrivateFieldSet(this, _HostWebRTCConnectionManager_webRTCHelperApiURL, options.webRTCHelperApiURL, "f");
|
|
43
|
+
__classPrivateFieldSet(this, _HostWebRTCConnectionManager_coturnDomainName, options.coturnDomainName, "f");
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* コネクションを取得する。
|
|
47
|
+
* コネクションが存在しない場合は新たに作成する。
|
|
48
|
+
* @returns 生成したコネクション
|
|
49
|
+
*/
|
|
50
|
+
getOrCreateConnection() {
|
|
51
|
+
if (__classPrivateFieldGet(this, _HostWebRTCConnectionManager_connection, "f")) {
|
|
52
|
+
return __classPrivateFieldGet(this, _HostWebRTCConnectionManager_connection, "f");
|
|
53
|
+
}
|
|
54
|
+
__classPrivateFieldSet(this, _HostWebRTCConnectionManager_connection, (() => __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
const authToken = yield __classPrivateFieldGet(this, _HostWebRTCConnectionManager_authToken, "f").getOrIssueAuthToken();
|
|
56
|
+
const connection = yield (0, create_rtc_peer_connection_1.createRTCPeerConnection)({
|
|
57
|
+
webRTCHelperApiURL: __classPrivateFieldGet(this, _HostWebRTCConnectionManager_webRTCHelperApiURL, "f"),
|
|
58
|
+
coturnDomainName: __classPrivateFieldGet(this, _HostWebRTCConnectionManager_coturnDomainName, "f"),
|
|
59
|
+
authToken: authToken.token,
|
|
60
|
+
});
|
|
61
|
+
const dataChannel = connection.createDataChannel("sendDataChannel");
|
|
62
|
+
return { connection, dataChannel };
|
|
63
|
+
}))().catch((err) => {
|
|
64
|
+
__classPrivateFieldSet(this, _HostWebRTCConnectionManager_connection, null, "f");
|
|
65
|
+
throw err;
|
|
66
|
+
}), "f");
|
|
67
|
+
return __classPrivateFieldGet(this, _HostWebRTCConnectionManager_connection, "f");
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* コネクションを切断する
|
|
71
|
+
*/
|
|
72
|
+
disconnect() {
|
|
73
|
+
if (!__classPrivateFieldGet(this, _HostWebRTCConnectionManager_connection, "f")) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
__classPrivateFieldGet(this, _HostWebRTCConnectionManager_connection, "f").then(({ connection, dataChannel }) => {
|
|
77
|
+
connection.close();
|
|
78
|
+
dataChannel.close();
|
|
79
|
+
});
|
|
80
|
+
__classPrivateFieldSet(this, _HostWebRTCConnectionManager_connection, null, "f");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.HostWebRTCConnectionManager = HostWebRTCConnectionManager;
|
|
84
|
+
_HostWebRTCConnectionManager_authToken = new WeakMap(), _HostWebRTCConnectionManager_connection = new WeakMap(), _HostWebRTCConnectionManager_webRTCHelperApiURL = new WeakMap(), _HostWebRTCConnectionManager_coturnDomainName = new WeakMap();
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ArmdozerId, PilotId } from "gbraver-burst-core";
|
|
2
|
+
import { BattleSDK } from "./battle-sdk";
|
|
3
|
+
import { FrontendLogManager } from "./frontend-log-manager";
|
|
4
|
+
import { HostWebRTCConnectionManager } from "./host-webrtc-connection-manager";
|
|
5
|
+
import { WebSocketConnectionManager } from "./websocket-connection-manager";
|
|
6
|
+
/** ローカルWebRTC ルーム */
|
|
7
|
+
export type LocalWebRTCRoom = {
|
|
8
|
+
/** ルームID */
|
|
9
|
+
readonly roomID: string;
|
|
10
|
+
/**
|
|
11
|
+
* マッチングするまで待機する
|
|
12
|
+
* @returns マッチングした相手とのバトルSDK
|
|
13
|
+
*/
|
|
14
|
+
waitUntilMatching: () => Promise<BattleSDK>;
|
|
15
|
+
};
|
|
16
|
+
/** ローカルWebRTCルームの実装 */
|
|
17
|
+
export declare class LocalWebRTCRoomImpl implements LocalWebRTCRoom {
|
|
18
|
+
#private;
|
|
19
|
+
/** ルームID */
|
|
20
|
+
roomID: string;
|
|
21
|
+
/**
|
|
22
|
+
* コンストラクタ
|
|
23
|
+
* @param options ルームの生成に必要なオプション
|
|
24
|
+
* @param options.spanId ログ用の識別子
|
|
25
|
+
* @param options.roomID ルームID
|
|
26
|
+
* @param options.webRTCConnection WebRTCコネクションマネジャー
|
|
27
|
+
* @param options.websocketConnection WebSocketコネクションマネジャー
|
|
28
|
+
* @param options.frontendLog フロントエンドログマネジャー
|
|
29
|
+
*/
|
|
30
|
+
constructor(options: {
|
|
31
|
+
roomID: string;
|
|
32
|
+
spanId: string;
|
|
33
|
+
webRTCConnection: HostWebRTCConnectionManager;
|
|
34
|
+
websocketConnection: WebSocketConnectionManager;
|
|
35
|
+
frontendLog: FrontendLogManager;
|
|
36
|
+
hostArmdozerId: ArmdozerId;
|
|
37
|
+
hostPilotId: PilotId;
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* マッチングするまで待機する
|
|
41
|
+
* @returns マッチングしたら発火するPromise
|
|
42
|
+
*/
|
|
43
|
+
waitUntilMatching(): Promise<BattleSDK>;
|
|
44
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
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 _LocalWebRTCRoomImpl_instances, _LocalWebRTCRoomImpl_spanId, _LocalWebRTCRoomImpl_webRTCConnection, _LocalWebRTCRoomImpl_websocketConnection, _LocalWebRTCRoomImpl_frontendLog, _LocalWebRTCRoomImpl_hostArmdozerId, _LocalWebRTCRoomImpl_hostPilotId, _LocalWebRTCRoomImpl_signaling;
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.LocalWebRTCRoomImpl = void 0;
|
|
25
|
+
const nanoid_1 = require("nanoid");
|
|
26
|
+
const rxjs_1 = require("rxjs");
|
|
27
|
+
const gather_all_ice_candidate_1 = require("../webrtc/gather-all-ice-candidate");
|
|
28
|
+
const get_selected_ice_candidate_summary_1 = require("../webrtc/get-selected-ice-candidate-summary");
|
|
29
|
+
const host_message_1 = require("../webrtc/host/host-message");
|
|
30
|
+
const request_selected_player_1 = require("../webrtc/host/request-selected-player");
|
|
31
|
+
const wait_until_connected_1 = require("../webrtc/wait-until-connected");
|
|
32
|
+
const wait_until_data_channel_ready_1 = require("../webrtc/wait-until-data-channel-ready");
|
|
33
|
+
const delete_signaling_channel_1 = require("../websocket-api/delete-signaling-channel");
|
|
34
|
+
const notify_ice_candidate_recieved_1 = require("../websocket-api/notify-ice-candidate-recieved");
|
|
35
|
+
const send_to_ws_signal_1 = require("../websocket-api/send-to-ws-signal");
|
|
36
|
+
const wait_until_matching_1 = require("../websocket-api/wait-until-matching");
|
|
37
|
+
const wait_until_sdp_recieve_1 = require("../websocket-api/wait-until-sdp-recieve");
|
|
38
|
+
const host_battle_sdk_1 = require("./host-battle-sdk");
|
|
39
|
+
/** ローカルWebRTCルームの実装 */
|
|
40
|
+
class LocalWebRTCRoomImpl {
|
|
41
|
+
/**
|
|
42
|
+
* コンストラクタ
|
|
43
|
+
* @param options ルームの生成に必要なオプション
|
|
44
|
+
* @param options.spanId ログ用の識別子
|
|
45
|
+
* @param options.roomID ルームID
|
|
46
|
+
* @param options.webRTCConnection WebRTCコネクションマネジャー
|
|
47
|
+
* @param options.websocketConnection WebSocketコネクションマネジャー
|
|
48
|
+
* @param options.frontendLog フロントエンドログマネジャー
|
|
49
|
+
*/
|
|
50
|
+
constructor(options) {
|
|
51
|
+
_LocalWebRTCRoomImpl_instances.add(this);
|
|
52
|
+
/** ログ用の識別子 */
|
|
53
|
+
_LocalWebRTCRoomImpl_spanId.set(this, void 0);
|
|
54
|
+
/** WebRTCコネクションマネージャー */
|
|
55
|
+
_LocalWebRTCRoomImpl_webRTCConnection.set(this, void 0);
|
|
56
|
+
/** WebSocketコネクションマネージャー */
|
|
57
|
+
_LocalWebRTCRoomImpl_websocketConnection.set(this, void 0);
|
|
58
|
+
/** フロントエンドログマネージャー */
|
|
59
|
+
_LocalWebRTCRoomImpl_frontendLog.set(this, void 0);
|
|
60
|
+
/** ホストが選択したアームドーザID */
|
|
61
|
+
_LocalWebRTCRoomImpl_hostArmdozerId.set(this, void 0);
|
|
62
|
+
/** ホストが選択したパイロットID */
|
|
63
|
+
_LocalWebRTCRoomImpl_hostPilotId.set(this, void 0);
|
|
64
|
+
const { roomID, spanId, webRTCConnection, websocketConnection, hostArmdozerId, hostPilotId, frontendLog, } = options;
|
|
65
|
+
this.roomID = roomID;
|
|
66
|
+
__classPrivateFieldSet(this, _LocalWebRTCRoomImpl_spanId, spanId, "f");
|
|
67
|
+
__classPrivateFieldSet(this, _LocalWebRTCRoomImpl_webRTCConnection, webRTCConnection, "f");
|
|
68
|
+
__classPrivateFieldSet(this, _LocalWebRTCRoomImpl_websocketConnection, websocketConnection, "f");
|
|
69
|
+
__classPrivateFieldSet(this, _LocalWebRTCRoomImpl_hostArmdozerId, hostArmdozerId, "f");
|
|
70
|
+
__classPrivateFieldSet(this, _LocalWebRTCRoomImpl_hostPilotId, hostPilotId, "f");
|
|
71
|
+
__classPrivateFieldSet(this, _LocalWebRTCRoomImpl_frontendLog, frontendLog, "f");
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* マッチングするまで待機する
|
|
75
|
+
* @returns マッチングしたら発火するPromise
|
|
76
|
+
*/
|
|
77
|
+
waitUntilMatching() {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
yield __classPrivateFieldGet(this, _LocalWebRTCRoomImpl_instances, "m", _LocalWebRTCRoomImpl_signaling).call(this);
|
|
80
|
+
const { dataChannel } = yield __classPrivateFieldGet(this, _LocalWebRTCRoomImpl_webRTCConnection, "f").getOrCreateConnection();
|
|
81
|
+
const flowID = (0, nanoid_1.nanoid)();
|
|
82
|
+
const { armdozerId: guestArmdozerId, pilotId: guestPilotId } = yield (0, request_selected_player_1.requestSelectedPlayer)(dataChannel, flowID);
|
|
83
|
+
const battleSDK = new host_battle_sdk_1.HostBattleSDK({
|
|
84
|
+
hostArmdozerId: __classPrivateFieldGet(this, _LocalWebRTCRoomImpl_hostArmdozerId, "f"),
|
|
85
|
+
hostPilotId: __classPrivateFieldGet(this, _LocalWebRTCRoomImpl_hostPilotId, "f"),
|
|
86
|
+
guestArmdozerId,
|
|
87
|
+
guestPilotId,
|
|
88
|
+
webRTCConnection: __classPrivateFieldGet(this, _LocalWebRTCRoomImpl_webRTCConnection, "f"),
|
|
89
|
+
});
|
|
90
|
+
(0, host_message_1.sendHostMessage)(dataChannel, {
|
|
91
|
+
type: "battle-start",
|
|
92
|
+
flowID: battleSDK.flowID,
|
|
93
|
+
hostPlayer: battleSDK.player,
|
|
94
|
+
guestPlayer: battleSDK.enemy,
|
|
95
|
+
update: battleSDK.initialState,
|
|
96
|
+
});
|
|
97
|
+
return battleSDK;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.LocalWebRTCRoomImpl = LocalWebRTCRoomImpl;
|
|
102
|
+
_LocalWebRTCRoomImpl_spanId = new WeakMap(), _LocalWebRTCRoomImpl_webRTCConnection = new WeakMap(), _LocalWebRTCRoomImpl_websocketConnection = new WeakMap(), _LocalWebRTCRoomImpl_frontendLog = new WeakMap(), _LocalWebRTCRoomImpl_hostArmdozerId = new WeakMap(), _LocalWebRTCRoomImpl_hostPilotId = new WeakMap(), _LocalWebRTCRoomImpl_instances = new WeakSet(), _LocalWebRTCRoomImpl_signaling = function _LocalWebRTCRoomImpl_signaling() {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
let unSubscribers = [];
|
|
105
|
+
try {
|
|
106
|
+
yield __classPrivateFieldGet(this, _LocalWebRTCRoomImpl_frontendLog, "f").log({
|
|
107
|
+
type: "SIGNALING_START",
|
|
108
|
+
spanId: __classPrivateFieldGet(this, _LocalWebRTCRoomImpl_spanId, "f"),
|
|
109
|
+
});
|
|
110
|
+
const websocket = yield __classPrivateFieldGet(this, _LocalWebRTCRoomImpl_websocketConnection, "f").getOrCreate();
|
|
111
|
+
const signalingID = yield (0, wait_until_matching_1.waitUntilMatching)(websocket);
|
|
112
|
+
const { connection, dataChannel } = yield __classPrivateFieldGet(this, _LocalWebRTCRoomImpl_webRTCConnection, "f").getOrCreateConnection();
|
|
113
|
+
let isRemoteDescriptionSet = false;
|
|
114
|
+
const pendingIceCandidates = [];
|
|
115
|
+
// イベントを取り逃がさないように、あらかじめハンドラをセットしておく
|
|
116
|
+
unSubscribers = [
|
|
117
|
+
(0, notify_ice_candidate_recieved_1.notifyIceCandidateReceived)(websocket).subscribe((iceCandidate) => {
|
|
118
|
+
if (isRemoteDescriptionSet) {
|
|
119
|
+
connection.addIceCandidate(iceCandidate);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
pendingIceCandidates.push(iceCandidate);
|
|
123
|
+
}
|
|
124
|
+
}),
|
|
125
|
+
(0, rxjs_1.fromEvent)(connection, "icecandidate").subscribe((event) => {
|
|
126
|
+
if (event.candidate) {
|
|
127
|
+
(0, send_to_ws_signal_1.sendToWSSignal)(websocket, {
|
|
128
|
+
action: "send-ice-candidate",
|
|
129
|
+
signalingID,
|
|
130
|
+
iceCandidate: event.candidate,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}),
|
|
134
|
+
(0, rxjs_1.fromEvent)(connection, "icecandidateerror").subscribe((event) => {
|
|
135
|
+
__classPrivateFieldGet(this, _LocalWebRTCRoomImpl_frontendLog, "f").log({
|
|
136
|
+
type: "ICE_CANDIDATE_ERROR",
|
|
137
|
+
spanId: __classPrivateFieldGet(this, _LocalWebRTCRoomImpl_spanId, "f"),
|
|
138
|
+
error: (0, gather_all_ice_candidate_1.createICECandidateErrorMessage)(event),
|
|
139
|
+
});
|
|
140
|
+
}),
|
|
141
|
+
];
|
|
142
|
+
const sdp = yield connection.createOffer();
|
|
143
|
+
yield connection.setLocalDescription(sdp);
|
|
144
|
+
(0, send_to_ws_signal_1.sendToWSSignal)(websocket, {
|
|
145
|
+
action: "send-sdp",
|
|
146
|
+
signalingID,
|
|
147
|
+
sdp,
|
|
148
|
+
});
|
|
149
|
+
const remoteSDP = yield (0, wait_until_sdp_recieve_1.waitUntilSDPReceive)(websocket);
|
|
150
|
+
yield connection.setRemoteDescription(remoteSDP);
|
|
151
|
+
isRemoteDescriptionSet = true;
|
|
152
|
+
pendingIceCandidates.forEach((iceCandidate) => {
|
|
153
|
+
connection.addIceCandidate(iceCandidate);
|
|
154
|
+
});
|
|
155
|
+
yield Promise.all([
|
|
156
|
+
(0, wait_until_connected_1.waitUntilConnected)(connection),
|
|
157
|
+
(0, wait_until_data_channel_ready_1.waitUntilDataChannelOpen)(dataChannel),
|
|
158
|
+
]);
|
|
159
|
+
yield (0, delete_signaling_channel_1.deleteSignalingChannel)({ websocket, signalingID });
|
|
160
|
+
yield __classPrivateFieldGet(this, _LocalWebRTCRoomImpl_frontendLog, "f").log({
|
|
161
|
+
type: "SIGNALING_END",
|
|
162
|
+
spanId: __classPrivateFieldGet(this, _LocalWebRTCRoomImpl_spanId, "f"),
|
|
163
|
+
});
|
|
164
|
+
const selectedLocalIceCandidateSummary = yield (0, get_selected_ice_candidate_summary_1.getSelectedIceCandidateSummary)(connection);
|
|
165
|
+
if (selectedLocalIceCandidateSummary !== null) {
|
|
166
|
+
yield __classPrivateFieldGet(this, _LocalWebRTCRoomImpl_frontendLog, "f").log({
|
|
167
|
+
type: "SELECTED_ICE_CANDIDATE_SUMMARY",
|
|
168
|
+
spanId: __classPrivateFieldGet(this, _LocalWebRTCRoomImpl_spanId, "f"),
|
|
169
|
+
summary: selectedLocalIceCandidateSummary,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
finally {
|
|
174
|
+
unSubscribers.forEach((u) => u.unsubscribe());
|
|
175
|
+
__classPrivateFieldGet(this, _LocalWebRTCRoomImpl_websocketConnection, "f").gracefulDisconnect();
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Observable } from "rxjs";
|
|
2
|
+
import { AuthTokenManager } from "./auth-token-manager";
|
|
3
|
+
/** WebSocketコネクション管理 */
|
|
4
|
+
export declare class WebSocketConnectionManager {
|
|
5
|
+
#private;
|
|
6
|
+
/** WebSocketシグナルサーバーのURL */
|
|
7
|
+
readonly wsSignalUrl: string;
|
|
8
|
+
/**
|
|
9
|
+
* コンストラクタ
|
|
10
|
+
* @param options オプション
|
|
11
|
+
* @param options.wsSignalUrl WebSocketシグナルサーバーのURL
|
|
12
|
+
* @param options.authToken 認証トークンマネージャー
|
|
13
|
+
*/
|
|
14
|
+
constructor(options: {
|
|
15
|
+
wsSignalUrl: string;
|
|
16
|
+
authToken: AuthTokenManager;
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* WebSocketクライアントの取得を行う
|
|
20
|
+
* WebSocketクライアントが存在しない場合は、本メソッド内で生成してから返す
|
|
21
|
+
* @returns 取得、生成結果
|
|
22
|
+
*/
|
|
23
|
+
getOrCreate(): Promise<WebSocket>;
|
|
24
|
+
/**
|
|
25
|
+
* Websocketコネクションを切断する
|
|
26
|
+
* 本メソッドを呼び出すことで、WebSocketコネクションに関連するイベントストリームの購読も解除する
|
|
27
|
+
*/
|
|
28
|
+
gracefulDisconnect(): void;
|
|
29
|
+
/**
|
|
30
|
+
* WebSocketのエラーを通知する
|
|
31
|
+
* @returns 通知ストリーム
|
|
32
|
+
*/
|
|
33
|
+
errorNotifier(): Observable<unknown>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
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 _WebSocketConnectionManager_authToken, _WebSocketConnectionManager_websocketError, _WebSocketConnectionManager_connection;
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.WebSocketConnectionManager = void 0;
|
|
25
|
+
const rxjs_1 = require("rxjs");
|
|
26
|
+
const connect_ws_signal_1 = require("../websocket-api/connect-ws-signal");
|
|
27
|
+
/** WebSocketコネクション管理 */
|
|
28
|
+
class WebSocketConnectionManager {
|
|
29
|
+
/**
|
|
30
|
+
* コンストラクタ
|
|
31
|
+
* @param options オプション
|
|
32
|
+
* @param options.wsSignalUrl WebSocketシグナルサーバーのURL
|
|
33
|
+
* @param options.authToken 認証トークンマネージャー
|
|
34
|
+
*/
|
|
35
|
+
constructor(options) {
|
|
36
|
+
/** 認証トークンマネージャー */
|
|
37
|
+
_WebSocketConnectionManager_authToken.set(this, void 0);
|
|
38
|
+
/** Web Socket エラー通知 */
|
|
39
|
+
_WebSocketConnectionManager_websocketError.set(this, void 0);
|
|
40
|
+
/** コネクション情報、nullで未接続 */
|
|
41
|
+
_WebSocketConnectionManager_connection.set(this, null);
|
|
42
|
+
this.wsSignalUrl = options.wsSignalUrl;
|
|
43
|
+
__classPrivateFieldSet(this, _WebSocketConnectionManager_authToken, options.authToken, "f");
|
|
44
|
+
__classPrivateFieldSet(this, _WebSocketConnectionManager_websocketError, new rxjs_1.Subject(), "f");
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* WebSocketクライアントの取得を行う
|
|
48
|
+
* WebSocketクライアントが存在しない場合は、本メソッド内で生成してから返す
|
|
49
|
+
* @returns 取得、生成結果
|
|
50
|
+
*/
|
|
51
|
+
getOrCreate() {
|
|
52
|
+
if (__classPrivateFieldGet(this, _WebSocketConnectionManager_connection, "f")) {
|
|
53
|
+
return __classPrivateFieldGet(this, _WebSocketConnectionManager_connection, "f").then((v) => v.websocket);
|
|
54
|
+
}
|
|
55
|
+
__classPrivateFieldSet(this, _WebSocketConnectionManager_connection, (() => __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
const authToken = yield __classPrivateFieldGet(this, _WebSocketConnectionManager_authToken, "f").getOrIssueAuthToken();
|
|
57
|
+
const websocket = yield (0, connect_ws_signal_1.connectWSSignal)(this.wsSignalUrl, authToken.token);
|
|
58
|
+
const websocketSubscriptions = [
|
|
59
|
+
(0, rxjs_1.fromEvent)(websocket, "error").subscribe(__classPrivateFieldGet(this, _WebSocketConnectionManager_websocketError, "f")),
|
|
60
|
+
(0, rxjs_1.fromEvent)(websocket, "close").subscribe(__classPrivateFieldGet(this, _WebSocketConnectionManager_websocketError, "f")),
|
|
61
|
+
];
|
|
62
|
+
return { websocket, websocketSubscriptions };
|
|
63
|
+
}))().catch((err) => {
|
|
64
|
+
__classPrivateFieldSet(this, _WebSocketConnectionManager_connection, null, "f");
|
|
65
|
+
throw err;
|
|
66
|
+
}), "f");
|
|
67
|
+
return __classPrivateFieldGet(this, _WebSocketConnectionManager_connection, "f").then((v) => v.websocket);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Websocketコネクションを切断する
|
|
71
|
+
* 本メソッドを呼び出すことで、WebSocketコネクションに関連するイベントストリームの購読も解除する
|
|
72
|
+
*/
|
|
73
|
+
gracefulDisconnect() {
|
|
74
|
+
if (!__classPrivateFieldGet(this, _WebSocketConnectionManager_connection, "f")) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
__classPrivateFieldGet(this, _WebSocketConnectionManager_connection, "f").then((v) => {
|
|
78
|
+
v.websocket.close();
|
|
79
|
+
v.websocketSubscriptions.forEach((s) => s.unsubscribe());
|
|
80
|
+
});
|
|
81
|
+
__classPrivateFieldSet(this, _WebSocketConnectionManager_connection, null, "f");
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* WebSocketのエラーを通知する
|
|
85
|
+
* @returns 通知ストリーム
|
|
86
|
+
*/
|
|
87
|
+
errorNotifier() {
|
|
88
|
+
return __classPrivateFieldGet(this, _WebSocketConnectionManager_websocketError, "f");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.WebSocketConnectionManager = WebSocketConnectionManager;
|
|
92
|
+
_WebSocketConnectionManager_authToken = new WeakMap(), _WebSocketConnectionManager_websocketError = new WeakMap(), _WebSocketConnectionManager_connection = new WeakMap();
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ICE Candidateの収集中に発生したエラーのメッセージを作成する
|
|
3
|
+
* @param error ICE Candidateの収集中に発生したエラー
|
|
4
|
+
* @returns エラーメッセージ
|
|
5
|
+
*/
|
|
6
|
+
export declare const createICECandidateErrorMessage: (error: RTCPeerConnectionIceErrorEvent) => string;
|
|
7
|
+
/** ICE Candidateの収集結果 */
|
|
8
|
+
type Result = {
|
|
9
|
+
/** 収集したICE Candidate */
|
|
10
|
+
iceCandidates: RTCIceCandidate[];
|
|
11
|
+
/** 発生したICE Candidateのエラー */
|
|
12
|
+
iceCandidateErrors: string[];
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* すべてのICE Candidateが収集する
|
|
16
|
+
* @param connection 待機するコネクション
|
|
17
|
+
* @returns 収集結果
|
|
18
|
+
*/
|
|
19
|
+
export declare const gatherAllIceCandidates: (connection: RTCPeerConnection) => Promise<Result>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.gatherAllIceCandidates = exports.createICECandidateErrorMessage = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* ICE Candidateの収集中に発生したエラーのメッセージを作成する
|
|
6
|
+
* @param error ICE Candidateの収集中に発生したエラー
|
|
7
|
+
* @returns エラーメッセージ
|
|
8
|
+
*/
|
|
9
|
+
const createICECandidateErrorMessage = (error) => `${error.errorCode} ${error.url} ${error.errorText}`;
|
|
10
|
+
exports.createICECandidateErrorMessage = createICECandidateErrorMessage;
|
|
11
|
+
/**
|
|
12
|
+
* すべてのICE Candidateが収集する
|
|
13
|
+
* @param connection 待機するコネクション
|
|
14
|
+
* @returns 収集結果
|
|
15
|
+
*/
|
|
16
|
+
const gatherAllIceCandidates = (connection) => {
|
|
17
|
+
let icecandidateHandler = null;
|
|
18
|
+
let icecandidateErrorHandler = null;
|
|
19
|
+
let candidates = [];
|
|
20
|
+
let iceCandidateErrors = [];
|
|
21
|
+
return new Promise((resolve) => {
|
|
22
|
+
icecandidateHandler = (event) => {
|
|
23
|
+
if (event.candidate === null) {
|
|
24
|
+
resolve({ iceCandidates: candidates, iceCandidateErrors });
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
candidates = [...candidates, event.candidate];
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
icecandidateErrorHandler = (event) => {
|
|
31
|
+
const errorMessage = (0, exports.createICECandidateErrorMessage)(event);
|
|
32
|
+
iceCandidateErrors = [...iceCandidateErrors, errorMessage];
|
|
33
|
+
};
|
|
34
|
+
connection.addEventListener("icecandidate", icecandidateHandler);
|
|
35
|
+
connection.addEventListener("icecandidateerror", icecandidateErrorHandler);
|
|
36
|
+
}).finally(() => {
|
|
37
|
+
if (icecandidateHandler) {
|
|
38
|
+
connection.removeEventListener("icecandidate", icecandidateHandler);
|
|
39
|
+
}
|
|
40
|
+
if (icecandidateErrorHandler) {
|
|
41
|
+
connection.removeEventListener("icecandidateerror", icecandidateErrorHandler);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
exports.gatherAllIceCandidates = gatherAllIceCandidates;
|