@gbraver-burst-network/local-webrtc-browser-sdk 1.23.1 → 1.24.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/lib/index.d.ts +3 -2
- package/lib/index.js +7 -5
- package/lib/sdk/auth-token-manager.d.ts +23 -0
- package/lib/sdk/auth-token-manager.js +83 -0
- package/lib/sdk/create-rtc-peer-connection.d.ts +2 -2
- package/lib/sdk/create-rtc-peer-connection.js +6 -2
- package/lib/sdk/{local-webrtc-guest-sdk.d.ts → guest-local-webrtc-sdk.d.ts} +4 -2
- package/lib/sdk/{local-webrtc-guest-sdk.js → guest-local-webrtc-sdk.js} +22 -21
- package/lib/sdk/guest-webrtc-connection-manager.d.ts +3 -0
- package/lib/sdk/guest-webrtc-connection-manager.js +10 -4
- package/lib/sdk/{local-webrtc-host-sdk.d.ts → host-local-webrtc-sdk.d.ts} +4 -2
- package/lib/sdk/{local-webrtc-host-sdk.js → host-local-webrtc-sdk.js} +19 -18
- package/lib/sdk/host-webrtc-connection-manager.d.ts +3 -0
- package/lib/sdk/host-webrtc-connection-manager.js +10 -4
- package/lib/sdk/websocket-connection-manager.d.ts +9 -2
- package/lib/sdk/websocket-connection-manager.js +13 -6
- package/lib/webrtc-helper/issue-auth-token.d.ts +7 -0
- package/lib/webrtc-helper/issue-auth-token.js +29 -0
- package/lib/webrtc-helper/issue-coturn-credential.d.ts +7 -2
- package/lib/webrtc-helper/issue-coturn-credential.js +9 -2
- package/lib/webrtc-helper/response/issue-auth-token.d.ts +13 -0
- package/lib/webrtc-helper/response/issue-auth-token.js +9 -0
- package/lib/ws-signal/connect-ws-signal.d.ts +2 -1
- package/lib/ws-signal/connect-ws-signal.js +3 -2
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
export { AuthTokenManager, createAuthTokenManager, } from "./sdk/auth-token-manager";
|
|
1
2
|
export { BattleSDK } from "./sdk/battle-sdk";
|
|
2
|
-
export { createLocalWebRTCGuestSDK,
|
|
3
|
-
export { createLocalWebRTCHostSDK,
|
|
3
|
+
export { createLocalWebRTCGuestSDK, GuestLocalWebRTCSDK, } from "./sdk/guest-local-webrtc-sdk";
|
|
4
|
+
export { createLocalWebRTCHostSDK, HostLocalWebRTCSDK, } from "./sdk/host-local-webrtc-sdk";
|
|
4
5
|
export { LocalWebRTCRoom } from "./sdk/local-webrtc-room";
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createLocalWebRTCHostSDK = exports.createLocalWebRTCGuestSDK = void 0;
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
var
|
|
7
|
-
Object.defineProperty(exports, "
|
|
3
|
+
exports.createLocalWebRTCHostSDK = exports.createLocalWebRTCGuestSDK = 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, "createLocalWebRTCGuestSDK", { enumerable: true, get: function () { return guest_local_webrtc_sdk_1.createLocalWebRTCGuestSDK; } });
|
|
8
|
+
var host_local_webrtc_sdk_1 = require("./sdk/host-local-webrtc-sdk");
|
|
9
|
+
Object.defineProperty(exports, "createLocalWebRTCHostSDK", { enumerable: true, get: function () { return host_local_webrtc_sdk_1.createLocalWebRTCHostSDK; } });
|
|
@@ -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,83 @@
|
|
|
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 _AuthTokenManagerImpl_instances, _AuthTokenManagerImpl_webRTCHelperApiURL, _AuthTokenManagerImpl_authTokenPromise, _AuthTokenManagerImpl_issueAuthTokenWithReset;
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.createAuthTokenManager = void 0;
|
|
25
|
+
const issue_auth_token_1 = require("../webrtc-helper/issue-auth-token");
|
|
26
|
+
/**
|
|
27
|
+
* トークン再利用のしきい値(秒)
|
|
28
|
+
* 残り有効時間がこの値以下になったら、再利用せず再発行する
|
|
29
|
+
*/
|
|
30
|
+
const TOKEN_REUSE_CUTOFF_SECONDS = 60 * 5;
|
|
31
|
+
/**
|
|
32
|
+
* トークンを再利用できるか判定する
|
|
33
|
+
* 残り有効時間がしきい値より長い場合のみ、再利用可能とする
|
|
34
|
+
* @param authToken 認証トークン
|
|
35
|
+
* @returns 判定結果、再利用可能ならtrue、トークンの再発行が必要ならfalse
|
|
36
|
+
*/
|
|
37
|
+
const canReuseToken = (authToken) => {
|
|
38
|
+
const now = Date.now() / 1000;
|
|
39
|
+
return now < authToken.expiresAt - TOKEN_REUSE_CUTOFF_SECONDS;
|
|
40
|
+
};
|
|
41
|
+
/** 認証トークンマネージャーの実装 */
|
|
42
|
+
class AuthTokenManagerImpl {
|
|
43
|
+
/**
|
|
44
|
+
* コンストラクタ
|
|
45
|
+
* @param webRTCHelperApiURL WebRTCヘルパーAPIのURL
|
|
46
|
+
*/
|
|
47
|
+
constructor(webRTCHelperApiURL) {
|
|
48
|
+
_AuthTokenManagerImpl_instances.add(this);
|
|
49
|
+
/** WebRTCヘルパーAPIのURL */
|
|
50
|
+
_AuthTokenManagerImpl_webRTCHelperApiURL.set(this, void 0);
|
|
51
|
+
/** 認証トークンPromise、未発行時はnull */
|
|
52
|
+
_AuthTokenManagerImpl_authTokenPromise.set(this, null);
|
|
53
|
+
__classPrivateFieldSet(this, _AuthTokenManagerImpl_webRTCHelperApiURL, webRTCHelperApiURL, "f");
|
|
54
|
+
}
|
|
55
|
+
/** @override */
|
|
56
|
+
getOrIssueAuthToken() {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
if (__classPrivateFieldGet(this, _AuthTokenManagerImpl_authTokenPromise, "f") === null) {
|
|
59
|
+
__classPrivateFieldSet(this, _AuthTokenManagerImpl_authTokenPromise, __classPrivateFieldGet(this, _AuthTokenManagerImpl_instances, "m", _AuthTokenManagerImpl_issueAuthTokenWithReset).call(this), "f");
|
|
60
|
+
return __classPrivateFieldGet(this, _AuthTokenManagerImpl_authTokenPromise, "f");
|
|
61
|
+
}
|
|
62
|
+
__classPrivateFieldSet(this, _AuthTokenManagerImpl_authTokenPromise, __classPrivateFieldGet(this, _AuthTokenManagerImpl_authTokenPromise, "f").then((token) => {
|
|
63
|
+
return canReuseToken(token) ? token : __classPrivateFieldGet(this, _AuthTokenManagerImpl_instances, "m", _AuthTokenManagerImpl_issueAuthTokenWithReset).call(this);
|
|
64
|
+
}), "f");
|
|
65
|
+
return __classPrivateFieldGet(this, _AuthTokenManagerImpl_authTokenPromise, "f");
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
_AuthTokenManagerImpl_webRTCHelperApiURL = new WeakMap(), _AuthTokenManagerImpl_authTokenPromise = new WeakMap(), _AuthTokenManagerImpl_instances = new WeakSet(), _AuthTokenManagerImpl_issueAuthTokenWithReset = function _AuthTokenManagerImpl_issueAuthTokenWithReset() {
|
|
70
|
+
return (0, issue_auth_token_1.issueAuthToken)(__classPrivateFieldGet(this, _AuthTokenManagerImpl_webRTCHelperApiURL, "f")).catch((error) => {
|
|
71
|
+
__classPrivateFieldSet(this, _AuthTokenManagerImpl_authTokenPromise, null, "f");
|
|
72
|
+
throw error;
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* 認証トークンマネージャーを生成する
|
|
77
|
+
* @param webRTCHelperApiURL WebRTCヘルパーAPIのURL
|
|
78
|
+
* @returns 生成した認証トークンマネージャー
|
|
79
|
+
*/
|
|
80
|
+
const createAuthTokenManager = (webRTCHelperApiURL) => {
|
|
81
|
+
return new AuthTokenManagerImpl(webRTCHelperApiURL);
|
|
82
|
+
};
|
|
83
|
+
exports.createAuthTokenManager = createAuthTokenManager;
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
* @param options オプション
|
|
4
4
|
* @param options.webRTCHelperApiURL WebRTCヘルパーAPIのURL
|
|
5
5
|
* @param options.coturnDomainName coturnサーバーのドメイン名
|
|
6
|
+
* @param options.authToken 認証トークン
|
|
6
7
|
* @returns 作成したRTCPeerConnection
|
|
7
8
|
*/
|
|
8
9
|
export declare const createRTCPeerConnection: (options: {
|
|
9
|
-
/** WebRTCヘルパーAPIのURL */
|
|
10
10
|
webRTCHelperApiURL: string;
|
|
11
|
-
/** coturnサーバーのドメイン名 */
|
|
12
11
|
coturnDomainName: string;
|
|
12
|
+
authToken: string;
|
|
13
13
|
}) => Promise<RTCPeerConnection>;
|
|
@@ -16,11 +16,15 @@ const issue_coturn_credential_1 = require("../webrtc-helper/issue-coturn-credent
|
|
|
16
16
|
* @param options オプション
|
|
17
17
|
* @param options.webRTCHelperApiURL WebRTCヘルパーAPIのURL
|
|
18
18
|
* @param options.coturnDomainName coturnサーバーのドメイン名
|
|
19
|
+
* @param options.authToken 認証トークン
|
|
19
20
|
* @returns 作成したRTCPeerConnection
|
|
20
21
|
*/
|
|
21
22
|
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)(
|
|
23
|
+
const { webRTCHelperApiURL, coturnDomainName, authToken } = options;
|
|
24
|
+
const { username, password: credential } = yield (0, issue_coturn_credential_1.issueCoturnCredential)({
|
|
25
|
+
apiURL: webRTCHelperApiURL,
|
|
26
|
+
authToken,
|
|
27
|
+
});
|
|
24
28
|
return new RTCPeerConnection({
|
|
25
29
|
iceServers: [
|
|
26
30
|
{
|
|
@@ -3,9 +3,11 @@ import { Observable } from "rxjs";
|
|
|
3
3
|
import { BattleSDK } from "./battle-sdk";
|
|
4
4
|
import { GuestWebRTCConnectionManagerOptions } from "./guest-webrtc-connection-manager";
|
|
5
5
|
/** ローカルWebRTCゲスト用SDK */
|
|
6
|
-
export type
|
|
6
|
+
export type GuestLocalWebRTCSDK = {
|
|
7
7
|
/**
|
|
8
8
|
* ルームに参加する
|
|
9
|
+
* 本メソッドでは新しいWebRTCコネクションを生成し、シグナリングも行うため、
|
|
10
|
+
* 既存のWebRTCコネクションやシグナリングは本メソッド内で切断される
|
|
9
11
|
* @param options ルーム参加のオプション
|
|
10
12
|
* @param options.roomID ルームID
|
|
11
13
|
* @param options.armdozerId ゲストが選択したアームドーザのID
|
|
@@ -46,5 +48,5 @@ type CreateLocalWebRTCGuestSDKOptions = LocalWebRTCGuestSDKImplOptions;
|
|
|
46
48
|
* @param options オプション
|
|
47
49
|
* @returns ローカルWebRTCゲスト用SDKのインスタンス
|
|
48
50
|
*/
|
|
49
|
-
export declare function createLocalWebRTCGuestSDK(options: CreateLocalWebRTCGuestSDKOptions):
|
|
51
|
+
export declare function createLocalWebRTCGuestSDK(options: CreateLocalWebRTCGuestSDKOptions): GuestLocalWebRTCSDK;
|
|
50
52
|
export {};
|
|
@@ -19,7 +19,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
19
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
20
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
21
|
};
|
|
22
|
-
var
|
|
22
|
+
var _GuestLocalWebRTCSDKImpl_instances, _GuestLocalWebRTCSDKImpl_webRTCConnection, _GuestLocalWebRTCSDKImpl_websocketConnection, _GuestLocalWebRTCSDKImpl_signaling;
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.createLocalWebRTCGuestSDK = createLocalWebRTCGuestSDK;
|
|
25
25
|
const guest_message_1 = require("../webrtc/guest/guest-message");
|
|
@@ -33,39 +33,40 @@ const guest_battle_sdk_1 = require("./guest-battle-sdk");
|
|
|
33
33
|
const guest_webrtc_connection_manager_1 = require("./guest-webrtc-connection-manager");
|
|
34
34
|
const websocket_connection_manager_1 = require("./websocket-connection-manager");
|
|
35
35
|
/** ローカルWebRTCゲスト用SDKの実装 */
|
|
36
|
-
class
|
|
36
|
+
class GuestLocalWebRTCSDKImpl {
|
|
37
37
|
/**
|
|
38
38
|
* コンストラクタ
|
|
39
39
|
* @param options コンストラクタのオプション
|
|
40
40
|
*/
|
|
41
41
|
constructor(options) {
|
|
42
|
-
|
|
42
|
+
_GuestLocalWebRTCSDKImpl_instances.add(this);
|
|
43
43
|
/** WebRTCコネクションマネージャー */
|
|
44
|
-
|
|
44
|
+
_GuestLocalWebRTCSDKImpl_webRTCConnection.set(this, void 0);
|
|
45
45
|
/** WebSocketコネクションマネージャー */
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
__classPrivateFieldSet(this,
|
|
49
|
-
__classPrivateFieldSet(this, _LocalWebRTCGuestSDKImpl_websocketConnection, new websocket_connection_manager_1.WebSocketConnectionManager(wsSignalUrl), "f");
|
|
46
|
+
_GuestLocalWebRTCSDKImpl_websocketConnection.set(this, void 0);
|
|
47
|
+
__classPrivateFieldSet(this, _GuestLocalWebRTCSDKImpl_webRTCConnection, new guest_webrtc_connection_manager_1.GuestWebRTCConnectionManager(options), "f");
|
|
48
|
+
__classPrivateFieldSet(this, _GuestLocalWebRTCSDKImpl_websocketConnection, new websocket_connection_manager_1.WebSocketConnectionManager(options), "f");
|
|
50
49
|
}
|
|
51
50
|
/** @override */
|
|
52
51
|
joinRoom(options) {
|
|
53
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
53
|
const { roomID, armdozerId, pilotId } = options;
|
|
54
|
+
__classPrivateFieldGet(this, _GuestLocalWebRTCSDKImpl_websocketConnection, "f").gracefulDisconnect();
|
|
55
|
+
__classPrivateFieldGet(this, _GuestLocalWebRTCSDKImpl_webRTCConnection, "f").disconnect();
|
|
55
56
|
const requestSelectedPlayerPromise = (() => __awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
const dataChannel = yield __classPrivateFieldGet(this,
|
|
57
|
+
const dataChannel = yield __classPrivateFieldGet(this, _GuestLocalWebRTCSDKImpl_webRTCConnection, "f").getOrCreateConnection().dataChannelPromise;
|
|
57
58
|
return yield (0, receive_request_selected_player_1.receiveRequestSelectedPlayer)(dataChannel);
|
|
58
59
|
}))();
|
|
59
60
|
const battleStartPromise = (() => __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
const dataChannel = yield __classPrivateFieldGet(this,
|
|
61
|
+
const dataChannel = yield __classPrivateFieldGet(this, _GuestLocalWebRTCSDKImpl_webRTCConnection, "f").getOrCreateConnection().dataChannelPromise;
|
|
61
62
|
return yield (0, receive_battle_start_1.receiveBattleStart)(dataChannel);
|
|
62
63
|
}))();
|
|
63
|
-
const isSignalingSuccessful = yield __classPrivateFieldGet(this,
|
|
64
|
+
const isSignalingSuccessful = yield __classPrivateFieldGet(this, _GuestLocalWebRTCSDKImpl_instances, "m", _GuestLocalWebRTCSDKImpl_signaling).call(this, roomID);
|
|
64
65
|
if (!isSignalingSuccessful) {
|
|
65
66
|
return null;
|
|
66
67
|
}
|
|
67
68
|
const { flowID } = yield requestSelectedPlayerPromise;
|
|
68
|
-
const dataChannel = yield __classPrivateFieldGet(this,
|
|
69
|
+
const dataChannel = yield __classPrivateFieldGet(this, _GuestLocalWebRTCSDKImpl_webRTCConnection, "f").getOrCreateConnection().dataChannelPromise;
|
|
69
70
|
(0, guest_message_1.sendGuestMessage)(dataChannel, {
|
|
70
71
|
type: "send-player",
|
|
71
72
|
flowID,
|
|
@@ -78,33 +79,33 @@ class LocalWebRTCGuestSDKImpl {
|
|
|
78
79
|
guestPlayer: battleStart.guestPlayer,
|
|
79
80
|
initialState: battleStart.update,
|
|
80
81
|
initialFlowID: battleStart.flowID,
|
|
81
|
-
webRTCConnection: __classPrivateFieldGet(this,
|
|
82
|
+
webRTCConnection: __classPrivateFieldGet(this, _GuestLocalWebRTCSDKImpl_webRTCConnection, "f"),
|
|
82
83
|
});
|
|
83
84
|
});
|
|
84
85
|
}
|
|
85
86
|
/** @override */
|
|
86
87
|
websocketErrorNotifier() {
|
|
87
|
-
return __classPrivateFieldGet(this,
|
|
88
|
+
return __classPrivateFieldGet(this, _GuestLocalWebRTCSDKImpl_websocketConnection, "f").errorNotifier();
|
|
88
89
|
}
|
|
89
90
|
/** @override */
|
|
90
91
|
disconnectWebSocket() {
|
|
91
|
-
__classPrivateFieldGet(this,
|
|
92
|
+
__classPrivateFieldGet(this, _GuestLocalWebRTCSDKImpl_websocketConnection, "f").gracefulDisconnect();
|
|
92
93
|
}
|
|
93
94
|
/** @override */
|
|
94
95
|
disconnectWebRTC() {
|
|
95
|
-
__classPrivateFieldGet(this,
|
|
96
|
+
__classPrivateFieldGet(this, _GuestLocalWebRTCSDKImpl_webRTCConnection, "f").disconnect();
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
|
-
|
|
99
|
+
_GuestLocalWebRTCSDKImpl_webRTCConnection = new WeakMap(), _GuestLocalWebRTCSDKImpl_websocketConnection = new WeakMap(), _GuestLocalWebRTCSDKImpl_instances = new WeakSet(), _GuestLocalWebRTCSDKImpl_signaling = function _GuestLocalWebRTCSDKImpl_signaling(roomID) {
|
|
99
100
|
return __awaiter(this, void 0, void 0, function* () {
|
|
100
101
|
try {
|
|
101
|
-
const websocket = yield __classPrivateFieldGet(this,
|
|
102
|
+
const websocket = yield __classPrivateFieldGet(this, _GuestLocalWebRTCSDKImpl_websocketConnection, "f").getOrCreate();
|
|
102
103
|
const joinRoomAccepted = yield (0, join_room_1.joinRoom)({ websocket, roomID });
|
|
103
104
|
if (!joinRoomAccepted) {
|
|
104
105
|
return false;
|
|
105
106
|
}
|
|
106
107
|
const { sdp: hostSDP, iceCandidates: hostIceCandidates } = joinRoomAccepted;
|
|
107
|
-
const connection = yield __classPrivateFieldGet(this,
|
|
108
|
+
const connection = yield __classPrivateFieldGet(this, _GuestLocalWebRTCSDKImpl_webRTCConnection, "f").getOrCreateConnection().connectionPromise;
|
|
108
109
|
yield connection.setRemoteDescription(hostSDP);
|
|
109
110
|
yield Promise.all(hostIceCandidates.map((c) => connection.addIceCandidate(c)));
|
|
110
111
|
const guestSDP = yield connection.createAnswer();
|
|
@@ -127,7 +128,7 @@ _LocalWebRTCGuestSDKImpl_webRTCConnection = new WeakMap(), _LocalWebRTCGuestSDKI
|
|
|
127
128
|
return true;
|
|
128
129
|
}
|
|
129
130
|
finally {
|
|
130
|
-
__classPrivateFieldGet(this,
|
|
131
|
+
__classPrivateFieldGet(this, _GuestLocalWebRTCSDKImpl_websocketConnection, "f").gracefulDisconnect();
|
|
131
132
|
}
|
|
132
133
|
});
|
|
133
134
|
};
|
|
@@ -137,5 +138,5 @@ _LocalWebRTCGuestSDKImpl_webRTCConnection = new WeakMap(), _LocalWebRTCGuestSDKI
|
|
|
137
138
|
* @returns ローカルWebRTCゲスト用SDKのインスタンス
|
|
138
139
|
*/
|
|
139
140
|
function createLocalWebRTCGuestSDK(options) {
|
|
140
|
-
return new
|
|
141
|
+
return new GuestLocalWebRTCSDKImpl(options);
|
|
141
142
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { AuthTokenManager } from "./auth-token-manager";
|
|
1
2
|
/** GuestWebRTCConnectionManagerコンストラクタのオプション */
|
|
2
3
|
export type GuestWebRTCConnectionManagerOptions = {
|
|
4
|
+
/** 認証トークンマネージャー */
|
|
5
|
+
authToken: AuthTokenManager;
|
|
3
6
|
/** WebRTCヘルパーAPIのURL */
|
|
4
7
|
webRTCHelperApiURL: string;
|
|
5
8
|
/** coturnサーバーのドメイン名 */
|
|
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
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
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _GuestWebRTCConnectionManager_connectionState, _GuestWebRTCConnectionManager_webRTCHelperApiURL, _GuestWebRTCConnectionManager_coturnDomainName;
|
|
13
|
+
var _GuestWebRTCConnectionManager_authToken, _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");
|
|
@@ -21,12 +21,15 @@ class GuestWebRTCConnectionManager {
|
|
|
21
21
|
* @param options オプション
|
|
22
22
|
*/
|
|
23
23
|
constructor(options) {
|
|
24
|
+
/** 認証トークンマネージャー */
|
|
25
|
+
_GuestWebRTCConnectionManager_authToken.set(this, void 0);
|
|
24
26
|
/** コネクションの状態 */
|
|
25
27
|
_GuestWebRTCConnectionManager_connectionState.set(this, { type: "disconnected" });
|
|
26
28
|
/** WebRTCヘルパーAPIのURL */
|
|
27
29
|
_GuestWebRTCConnectionManager_webRTCHelperApiURL.set(this, void 0);
|
|
28
30
|
/** coturnサーバーのドメイン名 */
|
|
29
31
|
_GuestWebRTCConnectionManager_coturnDomainName.set(this, void 0);
|
|
32
|
+
__classPrivateFieldSet(this, _GuestWebRTCConnectionManager_authToken, options.authToken, "f");
|
|
30
33
|
__classPrivateFieldSet(this, _GuestWebRTCConnectionManager_webRTCHelperApiURL, options.webRTCHelperApiURL, "f");
|
|
31
34
|
__classPrivateFieldSet(this, _GuestWebRTCConnectionManager_coturnDomainName, options.coturnDomainName, "f");
|
|
32
35
|
}
|
|
@@ -37,10 +40,13 @@ class GuestWebRTCConnectionManager {
|
|
|
37
40
|
*/
|
|
38
41
|
getOrCreateConnection() {
|
|
39
42
|
if (__classPrivateFieldGet(this, _GuestWebRTCConnectionManager_connectionState, "f").type === "disconnected") {
|
|
40
|
-
const connectionPromise = (
|
|
43
|
+
const connectionPromise = __classPrivateFieldGet(this, _GuestWebRTCConnectionManager_authToken, "f")
|
|
44
|
+
.getOrIssueAuthToken()
|
|
45
|
+
.then((authToken) => (0, create_rtc_peer_connection_1.createRTCPeerConnection)({
|
|
41
46
|
webRTCHelperApiURL: __classPrivateFieldGet(this, _GuestWebRTCConnectionManager_webRTCHelperApiURL, "f"),
|
|
42
47
|
coturnDomainName: __classPrivateFieldGet(this, _GuestWebRTCConnectionManager_coturnDomainName, "f"),
|
|
43
|
-
|
|
48
|
+
authToken: authToken.token,
|
|
49
|
+
}));
|
|
44
50
|
const dataChannelPromise = connectionPromise.then((connection) => (0, wait_until_data_channel_1.waitUntilDataChannel)(connection));
|
|
45
51
|
__classPrivateFieldSet(this, _GuestWebRTCConnectionManager_connectionState, {
|
|
46
52
|
type: "connected",
|
|
@@ -62,4 +68,4 @@ class GuestWebRTCConnectionManager {
|
|
|
62
68
|
}
|
|
63
69
|
}
|
|
64
70
|
exports.GuestWebRTCConnectionManager = GuestWebRTCConnectionManager;
|
|
65
|
-
_GuestWebRTCConnectionManager_connectionState = new WeakMap(), _GuestWebRTCConnectionManager_webRTCHelperApiURL = new WeakMap(), _GuestWebRTCConnectionManager_coturnDomainName = new WeakMap();
|
|
71
|
+
_GuestWebRTCConnectionManager_authToken = new WeakMap(), _GuestWebRTCConnectionManager_connectionState = new WeakMap(), _GuestWebRTCConnectionManager_webRTCHelperApiURL = new WeakMap(), _GuestWebRTCConnectionManager_coturnDomainName = new WeakMap();
|
|
@@ -3,9 +3,11 @@ import { Observable } from "rxjs";
|
|
|
3
3
|
import { HostWebRTCConnectionManagerOptions } from "./host-webrtc-connection-manager";
|
|
4
4
|
import { LocalWebRTCRoom } from "./local-webrtc-room";
|
|
5
5
|
/** ローカルWebRTCホスト用SDK */
|
|
6
|
-
export type
|
|
6
|
+
export type HostLocalWebRTCSDK = {
|
|
7
7
|
/**
|
|
8
8
|
* ルームを生成する
|
|
9
|
+
* 本メソッドでは新しいWebRTCコネクションを生成し、シグナリングも行うため、
|
|
10
|
+
* 既存のWebRTCコネクションやシグナリングは本メソッド内で切断される
|
|
9
11
|
* @param options ルーム生成のオプション
|
|
10
12
|
* @param options.armdozerId ホストが選択したアームドーザのID
|
|
11
13
|
* @param options.pilotId ホストが選択したパイロットのID
|
|
@@ -44,5 +46,5 @@ type CreateLocalWebRTCHostSDKOptions = LocalWebRTCHostSDKImplOptions;
|
|
|
44
46
|
* @param options SDK生成のオプション
|
|
45
47
|
* @returns ローカルWebRTCホスト用SDKのインスタンス
|
|
46
48
|
*/
|
|
47
|
-
export declare function createLocalWebRTCHostSDK(options: CreateLocalWebRTCHostSDKOptions):
|
|
49
|
+
export declare function createLocalWebRTCHostSDK(options: CreateLocalWebRTCHostSDKOptions): HostLocalWebRTCSDK;
|
|
48
50
|
export {};
|
|
@@ -19,7 +19,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
19
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
20
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
21
|
};
|
|
22
|
-
var
|
|
22
|
+
var _HostLocalWebRTCSDKImpl_webRTCConnection, _HostLocalWebRTCSDKImpl_websocketConnection;
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.createLocalWebRTCHostSDK = createLocalWebRTCHostSDK;
|
|
25
25
|
const wait_untilIce_candidate_1 = require("../webrtc/wait-untilIce-candidate");
|
|
@@ -28,71 +28,72 @@ const host_webrtc_connection_manager_1 = require("./host-webrtc-connection-manag
|
|
|
28
28
|
const local_webrtc_room_1 = require("./local-webrtc-room");
|
|
29
29
|
const websocket_connection_manager_1 = require("./websocket-connection-manager");
|
|
30
30
|
/** ローカルWebRTCホスト用SDKの実装 */
|
|
31
|
-
class
|
|
31
|
+
class HostLocalWebRTCSDKImpl {
|
|
32
32
|
/**
|
|
33
33
|
* コンストラクタ
|
|
34
34
|
* @param options コンストラクタのオプション
|
|
35
35
|
*/
|
|
36
36
|
constructor(options) {
|
|
37
37
|
/** WebRTCコネクションマネージャー */
|
|
38
|
-
|
|
38
|
+
_HostLocalWebRTCSDKImpl_webRTCConnection.set(this, void 0);
|
|
39
39
|
/** WebSocketコネクションマネージャー */
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
__classPrivateFieldSet(this,
|
|
43
|
-
__classPrivateFieldSet(this, _LocalWebRTCHostSDKImpl_webRTCConnection, new host_webrtc_connection_manager_1.HostWebRTCConnectionManager(options), "f");
|
|
40
|
+
_HostLocalWebRTCSDKImpl_websocketConnection.set(this, void 0);
|
|
41
|
+
__classPrivateFieldSet(this, _HostLocalWebRTCSDKImpl_websocketConnection, new websocket_connection_manager_1.WebSocketConnectionManager(options), "f");
|
|
42
|
+
__classPrivateFieldSet(this, _HostLocalWebRTCSDKImpl_webRTCConnection, new host_webrtc_connection_manager_1.HostWebRTCConnectionManager(options), "f");
|
|
44
43
|
}
|
|
45
44
|
/** @override */
|
|
46
45
|
createRoom(options) {
|
|
47
46
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
47
|
try {
|
|
49
|
-
|
|
48
|
+
__classPrivateFieldGet(this, _HostLocalWebRTCSDKImpl_websocketConnection, "f").gracefulDisconnect();
|
|
49
|
+
__classPrivateFieldGet(this, _HostLocalWebRTCSDKImpl_webRTCConnection, "f").disconnect();
|
|
50
|
+
const connection = yield __classPrivateFieldGet(this, _HostLocalWebRTCSDKImpl_webRTCConnection, "f").getOrCreateConnection().connectionPromise;
|
|
50
51
|
const sdp = yield connection.createOffer();
|
|
51
52
|
const [iceCandidates] = yield Promise.all([
|
|
52
53
|
// icecandidateイベントはsetLocalDescriptionの後に発生するため、先に待機しておく
|
|
53
54
|
(0, wait_untilIce_candidate_1.waitUntilIceCandidate)(connection),
|
|
54
55
|
connection.setLocalDescription(sdp),
|
|
55
56
|
]);
|
|
56
|
-
const websocket = yield __classPrivateFieldGet(this,
|
|
57
|
+
const websocket = yield __classPrivateFieldGet(this, _HostLocalWebRTCSDKImpl_websocketConnection, "f").getOrCreate();
|
|
57
58
|
const roomID = yield (0, create_room_1.createRoom)({ websocket, sdp, iceCandidates });
|
|
58
59
|
if (roomID === null) {
|
|
59
|
-
__classPrivateFieldGet(this,
|
|
60
|
+
__classPrivateFieldGet(this, _HostLocalWebRTCSDKImpl_websocketConnection, "f").gracefulDisconnect();
|
|
60
61
|
return null;
|
|
61
62
|
}
|
|
62
63
|
const { armdozerId: hostArmdozerId, pilotId: hostPilotId } = options;
|
|
63
64
|
return new local_webrtc_room_1.LocalWebRTCRoomImpl({
|
|
64
65
|
roomID,
|
|
65
|
-
webRTCConnection: __classPrivateFieldGet(this,
|
|
66
|
-
websocketConnection: __classPrivateFieldGet(this,
|
|
66
|
+
webRTCConnection: __classPrivateFieldGet(this, _HostLocalWebRTCSDKImpl_webRTCConnection, "f"),
|
|
67
|
+
websocketConnection: __classPrivateFieldGet(this, _HostLocalWebRTCSDKImpl_websocketConnection, "f"),
|
|
67
68
|
hostArmdozerId,
|
|
68
69
|
hostPilotId,
|
|
69
70
|
});
|
|
70
71
|
}
|
|
71
72
|
catch (e) {
|
|
72
|
-
__classPrivateFieldGet(this,
|
|
73
|
+
__classPrivateFieldGet(this, _HostLocalWebRTCSDKImpl_websocketConnection, "f").gracefulDisconnect();
|
|
73
74
|
throw e;
|
|
74
75
|
}
|
|
75
76
|
});
|
|
76
77
|
}
|
|
77
78
|
/** @override */
|
|
78
79
|
websocketErrorNotifier() {
|
|
79
|
-
return __classPrivateFieldGet(this,
|
|
80
|
+
return __classPrivateFieldGet(this, _HostLocalWebRTCSDKImpl_websocketConnection, "f").errorNotifier();
|
|
80
81
|
}
|
|
81
82
|
/** @override */
|
|
82
83
|
disconnectWebSocket() {
|
|
83
|
-
__classPrivateFieldGet(this,
|
|
84
|
+
__classPrivateFieldGet(this, _HostLocalWebRTCSDKImpl_websocketConnection, "f").gracefulDisconnect();
|
|
84
85
|
}
|
|
85
86
|
/** @override */
|
|
86
87
|
disconnectWebRTC() {
|
|
87
|
-
__classPrivateFieldGet(this,
|
|
88
|
+
__classPrivateFieldGet(this, _HostLocalWebRTCSDKImpl_webRTCConnection, "f").disconnect();
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
|
-
|
|
91
|
+
_HostLocalWebRTCSDKImpl_webRTCConnection = new WeakMap(), _HostLocalWebRTCSDKImpl_websocketConnection = new WeakMap();
|
|
91
92
|
/**
|
|
92
93
|
* ローカルWebRTCホスト用SDKを生成する
|
|
93
94
|
* @param options SDK生成のオプション
|
|
94
95
|
* @returns ローカルWebRTCホスト用SDKのインスタンス
|
|
95
96
|
*/
|
|
96
97
|
function createLocalWebRTCHostSDK(options) {
|
|
97
|
-
return new
|
|
98
|
+
return new HostLocalWebRTCSDKImpl(options);
|
|
98
99
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { AuthTokenManager } from "./auth-token-manager";
|
|
1
2
|
/** HostWebRTCConnectionManagerコンストラクタのオプション */
|
|
2
3
|
export type HostWebRTCConnectionManagerOptions = {
|
|
4
|
+
/** 認証トークンマネージャー */
|
|
5
|
+
authToken: AuthTokenManager;
|
|
3
6
|
/** WebRTCヘルパーAPIのURL */
|
|
4
7
|
webRTCHelperApiURL: string;
|
|
5
8
|
/** coturnサーバーのドメイン名 */
|
|
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
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
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _HostWebRTCConnectionManager_connectionState, _HostWebRTCConnectionManager_webRTCHelperApiURL, _HostWebRTCConnectionManager_coturnDomainName;
|
|
13
|
+
var _HostWebRTCConnectionManager_authToken, _HostWebRTCConnectionManager_connectionState, _HostWebRTCConnectionManager_webRTCHelperApiURL, _HostWebRTCConnectionManager_coturnDomainName;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.HostWebRTCConnectionManager = void 0;
|
|
16
16
|
const create_rtc_peer_connection_1 = require("./create-rtc-peer-connection");
|
|
@@ -21,12 +21,15 @@ class HostWebRTCConnectionManager {
|
|
|
21
21
|
* @param options オプション
|
|
22
22
|
*/
|
|
23
23
|
constructor(options) {
|
|
24
|
+
/** 認証トークンマネージャー */
|
|
25
|
+
_HostWebRTCConnectionManager_authToken.set(this, void 0);
|
|
24
26
|
/** コネクションの状態 */
|
|
25
27
|
_HostWebRTCConnectionManager_connectionState.set(this, { type: "disconnected" });
|
|
26
28
|
/** WebRTCヘルパーAPIのURL */
|
|
27
29
|
_HostWebRTCConnectionManager_webRTCHelperApiURL.set(this, void 0);
|
|
28
30
|
/** coturnサーバーのドメイン名 */
|
|
29
31
|
_HostWebRTCConnectionManager_coturnDomainName.set(this, void 0);
|
|
32
|
+
__classPrivateFieldSet(this, _HostWebRTCConnectionManager_authToken, options.authToken, "f");
|
|
30
33
|
__classPrivateFieldSet(this, _HostWebRTCConnectionManager_webRTCHelperApiURL, options.webRTCHelperApiURL, "f");
|
|
31
34
|
__classPrivateFieldSet(this, _HostWebRTCConnectionManager_coturnDomainName, options.coturnDomainName, "f");
|
|
32
35
|
}
|
|
@@ -37,10 +40,13 @@ class HostWebRTCConnectionManager {
|
|
|
37
40
|
*/
|
|
38
41
|
getOrCreateConnection() {
|
|
39
42
|
if (__classPrivateFieldGet(this, _HostWebRTCConnectionManager_connectionState, "f").type === "disconnected") {
|
|
40
|
-
const connectionPromise = (
|
|
43
|
+
const connectionPromise = __classPrivateFieldGet(this, _HostWebRTCConnectionManager_authToken, "f")
|
|
44
|
+
.getOrIssueAuthToken()
|
|
45
|
+
.then((authToken) => (0, create_rtc_peer_connection_1.createRTCPeerConnection)({
|
|
41
46
|
webRTCHelperApiURL: __classPrivateFieldGet(this, _HostWebRTCConnectionManager_webRTCHelperApiURL, "f"),
|
|
42
47
|
coturnDomainName: __classPrivateFieldGet(this, _HostWebRTCConnectionManager_coturnDomainName, "f"),
|
|
43
|
-
|
|
48
|
+
authToken: authToken.token,
|
|
49
|
+
}));
|
|
44
50
|
const dataChannelPromise = connectionPromise.then((connection) => connection.createDataChannel("sendDataChannel"));
|
|
45
51
|
__classPrivateFieldSet(this, _HostWebRTCConnectionManager_connectionState, {
|
|
46
52
|
type: "connected",
|
|
@@ -66,4 +72,4 @@ class HostWebRTCConnectionManager {
|
|
|
66
72
|
}
|
|
67
73
|
}
|
|
68
74
|
exports.HostWebRTCConnectionManager = HostWebRTCConnectionManager;
|
|
69
|
-
_HostWebRTCConnectionManager_connectionState = new WeakMap(), _HostWebRTCConnectionManager_webRTCHelperApiURL = new WeakMap(), _HostWebRTCConnectionManager_coturnDomainName = new WeakMap();
|
|
75
|
+
_HostWebRTCConnectionManager_authToken = new WeakMap(), _HostWebRTCConnectionManager_connectionState = new WeakMap(), _HostWebRTCConnectionManager_webRTCHelperApiURL = new WeakMap(), _HostWebRTCConnectionManager_coturnDomainName = new WeakMap();
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { Observable } from "rxjs";
|
|
2
|
+
import { AuthTokenManager } from "./auth-token-manager";
|
|
3
|
+
/** WebSocketコネクション管理 */
|
|
2
4
|
export declare class WebSocketConnectionManager {
|
|
3
5
|
#private;
|
|
4
6
|
/** WebSocketシグナルサーバーのURL */
|
|
5
7
|
readonly wsSignalUrl: string;
|
|
6
8
|
/**
|
|
7
9
|
* コンストラクタ
|
|
8
|
-
* @param
|
|
10
|
+
* @param options オプション
|
|
11
|
+
* @param options.wsSignalUrl WebSocketシグナルサーバーのURL
|
|
12
|
+
* @param options.authToken 認証トークンマネージャー
|
|
9
13
|
*/
|
|
10
|
-
constructor(
|
|
14
|
+
constructor(options: {
|
|
15
|
+
wsSignalUrl: string;
|
|
16
|
+
authToken: AuthTokenManager;
|
|
17
|
+
});
|
|
11
18
|
/**
|
|
12
19
|
* WebSocketクライアントの取得を行う
|
|
13
20
|
* WebSocketクライアントが存在しない場合は、本メソッド内で生成してから返す
|
|
@@ -19,24 +19,30 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
19
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
20
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
21
|
};
|
|
22
|
-
var _WebSocketConnectionManager_websocket, _WebSocketConnectionManager_websocketError, _WebSocketConnectionManager_websocketSubscriptions;
|
|
22
|
+
var _WebSocketConnectionManager_authToken, _WebSocketConnectionManager_websocket, _WebSocketConnectionManager_websocketError, _WebSocketConnectionManager_websocketSubscriptions;
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.WebSocketConnectionManager = void 0;
|
|
25
25
|
const rxjs_1 = require("rxjs");
|
|
26
26
|
const connect_ws_signal_1 = require("../ws-signal/connect-ws-signal");
|
|
27
|
+
/** WebSocketコネクション管理 */
|
|
27
28
|
class WebSocketConnectionManager {
|
|
28
29
|
/**
|
|
29
30
|
* コンストラクタ
|
|
30
|
-
* @param
|
|
31
|
+
* @param options オプション
|
|
32
|
+
* @param options.wsSignalUrl WebSocketシグナルサーバーのURL
|
|
33
|
+
* @param options.authToken 認証トークンマネージャー
|
|
31
34
|
*/
|
|
32
|
-
constructor(
|
|
35
|
+
constructor(options) {
|
|
36
|
+
/** 認証トークンマネージャー */
|
|
37
|
+
_WebSocketConnectionManager_authToken.set(this, void 0);
|
|
33
38
|
/** WebSocketコネクション */
|
|
34
39
|
_WebSocketConnectionManager_websocket.set(this, null);
|
|
35
40
|
/** Web Socket エラー通知 */
|
|
36
41
|
_WebSocketConnectionManager_websocketError.set(this, void 0);
|
|
37
42
|
/** Web Socket イベントストリーム */
|
|
38
43
|
_WebSocketConnectionManager_websocketSubscriptions.set(this, void 0);
|
|
39
|
-
this.wsSignalUrl = wsSignalUrl;
|
|
44
|
+
this.wsSignalUrl = options.wsSignalUrl;
|
|
45
|
+
__classPrivateFieldSet(this, _WebSocketConnectionManager_authToken, options.authToken, "f");
|
|
40
46
|
__classPrivateFieldSet(this, _WebSocketConnectionManager_websocketError, new rxjs_1.Subject(), "f");
|
|
41
47
|
__classPrivateFieldSet(this, _WebSocketConnectionManager_websocketSubscriptions, [], "f");
|
|
42
48
|
}
|
|
@@ -50,7 +56,8 @@ class WebSocketConnectionManager {
|
|
|
50
56
|
if (__classPrivateFieldGet(this, _WebSocketConnectionManager_websocket, "f")) {
|
|
51
57
|
return __classPrivateFieldGet(this, _WebSocketConnectionManager_websocket, "f");
|
|
52
58
|
}
|
|
53
|
-
const
|
|
59
|
+
const authToken = yield __classPrivateFieldGet(this, _WebSocketConnectionManager_authToken, "f").getOrIssueAuthToken();
|
|
60
|
+
const websocket = yield (0, connect_ws_signal_1.connectWSSignal)(this.wsSignalUrl, authToken.token);
|
|
54
61
|
__classPrivateFieldSet(this, _WebSocketConnectionManager_websocketSubscriptions, [
|
|
55
62
|
(0, rxjs_1.fromEvent)(websocket, "error").subscribe(__classPrivateFieldGet(this, _WebSocketConnectionManager_websocketError, "f")),
|
|
56
63
|
(0, rxjs_1.fromEvent)(websocket, "close").subscribe(__classPrivateFieldGet(this, _WebSocketConnectionManager_websocketError, "f")),
|
|
@@ -81,4 +88,4 @@ class WebSocketConnectionManager {
|
|
|
81
88
|
}
|
|
82
89
|
}
|
|
83
90
|
exports.WebSocketConnectionManager = WebSocketConnectionManager;
|
|
84
|
-
_WebSocketConnectionManager_websocket = new WeakMap(), _WebSocketConnectionManager_websocketError = new WeakMap(), _WebSocketConnectionManager_websocketSubscriptions = new WeakMap();
|
|
91
|
+
_WebSocketConnectionManager_authToken = new WeakMap(), _WebSocketConnectionManager_websocket = new WeakMap(), _WebSocketConnectionManager_websocketError = new WeakMap(), _WebSocketConnectionManager_websocketSubscriptions = new WeakMap();
|
|
@@ -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;
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { IssueCoturnCredentialResponse } from "./response/issue-coturn-credential";
|
|
2
2
|
/**
|
|
3
3
|
* coturnクレデンシャルを発行する
|
|
4
|
-
* @param
|
|
4
|
+
* @param options オプション
|
|
5
|
+
* @param options.apiURL WebRTCヘルパーREST APIのURL
|
|
6
|
+
* @param options.authToken 認証トークン
|
|
5
7
|
* @returns 発行したクレデンシャル
|
|
6
8
|
*/
|
|
7
|
-
export declare const issueCoturnCredential: (
|
|
9
|
+
export declare const issueCoturnCredential: (options: {
|
|
10
|
+
apiURL: string;
|
|
11
|
+
authToken: string;
|
|
12
|
+
}) => Promise<IssueCoturnCredentialResponse>;
|
|
@@ -13,12 +13,19 @@ exports.issueCoturnCredential = void 0;
|
|
|
13
13
|
const issue_coturn_credential_1 = require("./response/issue-coturn-credential");
|
|
14
14
|
/**
|
|
15
15
|
* coturnクレデンシャルを発行する
|
|
16
|
-
* @param
|
|
16
|
+
* @param options オプション
|
|
17
|
+
* @param options.apiURL WebRTCヘルパーREST APIのURL
|
|
18
|
+
* @param options.authToken 認証トークン
|
|
17
19
|
* @returns 発行したクレデンシャル
|
|
18
20
|
*/
|
|
19
|
-
const issueCoturnCredential = (
|
|
21
|
+
const issueCoturnCredential = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
const { apiURL, authToken } = options;
|
|
20
23
|
const response = yield fetch(`${apiURL}/coturn/credentials`, {
|
|
21
24
|
method: "POST",
|
|
25
|
+
headers: {
|
|
26
|
+
"Content-Type": "application/json",
|
|
27
|
+
Authorization: `Bearer ${authToken}`,
|
|
28
|
+
},
|
|
22
29
|
});
|
|
23
30
|
if (response.status !== 201) {
|
|
24
31
|
throw new Error(`Failed to issue coturn credential: ${response.status}`);
|
|
@@ -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
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WebSocketシグナルサーバーに接続する
|
|
3
3
|
* @param url 接続先のWebSocketシグナルサーバーのURL
|
|
4
|
+
* @param token 認証トークン
|
|
4
5
|
* @returns 接続に成功したWebSocket、接続に失敗した場合はPromiseがrejectされる
|
|
5
6
|
*/
|
|
6
|
-
export declare function connectWSSignal(url: string): Promise<WebSocket>;
|
|
7
|
+
export declare function connectWSSignal(url: string, token: string): Promise<WebSocket>;
|
|
@@ -4,12 +4,13 @@ exports.connectWSSignal = connectWSSignal;
|
|
|
4
4
|
/**
|
|
5
5
|
* WebSocketシグナルサーバーに接続する
|
|
6
6
|
* @param url 接続先のWebSocketシグナルサーバーのURL
|
|
7
|
+
* @param token 認証トークン
|
|
7
8
|
* @returns 接続に成功したWebSocket、接続に失敗した場合はPromiseがrejectされる
|
|
8
9
|
*/
|
|
9
|
-
function connectWSSignal(url) {
|
|
10
|
+
function connectWSSignal(url, token) {
|
|
10
11
|
let handler = null;
|
|
11
12
|
let errorHandler = null;
|
|
12
|
-
const websocket = new WebSocket(url);
|
|
13
|
+
const websocket = new WebSocket(`${url}?token=${token}`);
|
|
13
14
|
return new Promise((resolve, reject) => {
|
|
14
15
|
handler = () => {
|
|
15
16
|
resolve(websocket);
|
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.
|
|
4
|
+
"version": "1.24.0",
|
|
5
5
|
"author": "Y.Takeuchi",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/kaidouji85/gbraver-burst-network/issues",
|