@gbraver-burst-network/anonymous-browser-sdk 2.6.0 → 2.7.0-beta.1

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.
@@ -19,28 +19,23 @@ 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 _GuestAnonymousSDKImpl_instances, _GuestAnonymousSDKImpl_webRTCConnection, _GuestAnonymousSDKImpl_websocketConnection, _GuestAnonymousSDKImpl_frontendLog, _GuestAnonymousSDKImpl_abortManager, _GuestAnonymousSDKImpl_signaling;
22
+ var _GuestAnonymousSDKImpl_webRTCConnection, _GuestAnonymousSDKImpl_websocketConnection, _GuestAnonymousSDKImpl_frontendLog, _GuestAnonymousSDKImpl_abortManager;
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.createGuestAnonymousSDK = createGuestAnonymousSDK;
25
25
  const nanoid_1 = require("nanoid");
26
- const rxjs_1 = require("rxjs");
27
26
  const abort_error_1 = require("../../abort-controller/abort-error");
28
27
  const abort_manager_1 = require("../../abort-controller/abort-manager");
29
- const gather_all_ice_candidate_1 = require("../../webrtc/gather-all-ice-candidate");
30
- const get_selected_ice_candidate_summary_1 = require("../../webrtc/get-selected-ice-candidate-summary");
31
28
  const guest_message_1 = require("../../webrtc/guest/guest-message");
32
29
  const guest_ping_pong_check_1 = require("../../webrtc/guest/guest-ping-pong-check");
33
30
  const receive_battle_start_1 = require("../../webrtc/guest/receive-battle-start");
34
31
  const receive_request_selected_player_1 = require("../../webrtc/guest/receive-request-selected-player");
35
- const wait_until_connected_1 = require("../../webrtc/wait-until-connected");
36
32
  const join_room_1 = require("../../websocket-api/join-room");
37
- const notify_ice_candidate_recieved_1 = require("../../websocket-api/notify-ice-candidate-recieved");
38
- const send_to_ws_signal_1 = require("../../websocket-api/send-to-ws-signal");
39
33
  const wait_until_sdp_recieve_1 = require("../../websocket-api/wait-until-sdp-recieve");
40
34
  const frontend_log_manager_1 = require("../frontend-log-manager");
41
35
  const websocket_connection_manager_1 = require("../websocket-connection-manager");
42
36
  const guest_battle_sdk_1 = require("./guest-battle-sdk");
43
37
  const guest_webrtc_connection_manager_1 = require("./guest-webrtc-connection-manager");
38
+ const signaling_1 = require("./signaling");
44
39
  /** ゲスト用匿名バックエンドSDKの実装 */
45
40
  class GuestAnonymousSDKImpl {
46
41
  /**
@@ -48,7 +43,6 @@ class GuestAnonymousSDKImpl {
48
43
  * @param options コンストラクタのオプション
49
44
  */
50
45
  constructor(options) {
51
- _GuestAnonymousSDKImpl_instances.add(this);
52
46
  /** WebRTCコネクションマネージャー */
53
47
  _GuestAnonymousSDKImpl_webRTCConnection.set(this, void 0);
54
48
  /** WebSocketコネクションマネージャー */
@@ -74,22 +68,38 @@ class GuestAnonymousSDKImpl {
74
68
  const { roomID, armdozerId, pilotId } = options;
75
69
  __classPrivateFieldGet(this, _GuestAnonymousSDKImpl_websocketConnection, "f").gracefulDisconnect();
76
70
  __classPrivateFieldGet(this, _GuestAnonymousSDKImpl_webRTCConnection, "f").disconnect();
77
- const websocket = yield __classPrivateFieldGet(this, _GuestAnonymousSDKImpl_websocketConnection, "f").getOrCreate();
71
+ const { connectionPromise, dataChannelPromise } = __classPrivateFieldGet(this, _GuestAnonymousSDKImpl_webRTCConnection, "f").getOrCreateConnection();
72
+ const [websocket, connection] = yield Promise.all([
73
+ __classPrivateFieldGet(this, _GuestAnonymousSDKImpl_websocketConnection, "f").getOrCreate(),
74
+ connectionPromise,
75
+ ]);
76
+ // joinRoomの成功直後にSDPが送信されるので、取りこぼし防止のために先にイベントを登録する
77
+ const waitUntilSDPReceivePromise = (0, wait_until_sdp_recieve_1.waitUntilSDPReceive)({
78
+ websocket,
79
+ signal,
80
+ });
78
81
  const joinRoomAccepted = yield (0, join_room_1.joinRoom)({ websocket, roomID, signal });
79
82
  if (!joinRoomAccepted) {
80
83
  return null;
81
84
  }
82
- // イベントの取りこぼしを防ぐために、あらかじリスナーを登録する
83
- const pingPongPromise = (() => __awaiter(this, void 0, void 0, function* () {
84
- const dataChannel = yield __classPrivateFieldGet(this, _GuestAnonymousSDKImpl_webRTCConnection, "f").getOrCreateConnection()
85
- .dataChannelPromise;
86
- yield (0, guest_ping_pong_check_1.guestPingPongCheck)({ dataChannel, signal });
87
- }))();
88
85
  const { signalingID } = joinRoomAccepted;
89
- yield __classPrivateFieldGet(this, _GuestAnonymousSDKImpl_instances, "m", _GuestAnonymousSDKImpl_signaling).call(this, { signalingID, spanId, signal });
90
- yield pingPongPromise;
86
+ const remoteSDP = yield waitUntilSDPReceivePromise;
87
+ // signalingの成功直後にホストからPingが送信されるので、取りこぼし防止のために先にイベントを登録する
88
+ const guestPingPongCheckPromise = dataChannelPromise.then((dataChannel) => (0, guest_ping_pong_check_1.guestPingPongCheck)({ dataChannel, signal }));
89
+ yield (0, signaling_1.signaling)({
90
+ signalingID,
91
+ spanId,
92
+ remoteSDP,
93
+ frontendLog: __classPrivateFieldGet(this, _GuestAnonymousSDKImpl_frontendLog, "f"),
94
+ websocket,
95
+ connection,
96
+ signal,
97
+ });
98
+ const [dataChannel] = yield Promise.all([
99
+ dataChannelPromise,
100
+ guestPingPongCheckPromise,
101
+ ]);
91
102
  __classPrivateFieldGet(this, _GuestAnonymousSDKImpl_websocketConnection, "f").gracefulDisconnect();
92
- const dataChannel = yield __classPrivateFieldGet(this, _GuestAnonymousSDKImpl_webRTCConnection, "f").getOrCreateConnection().dataChannelPromise;
93
103
  const { flowID } = yield (0, receive_request_selected_player_1.receiveRequestSelectedPlayer)({
94
104
  dataChannel,
95
105
  signal,
@@ -135,82 +145,7 @@ class GuestAnonymousSDKImpl {
135
145
  .abort((0, abort_error_1.createAbortError)("WebRTC disconnected"));
136
146
  }
137
147
  }
138
- _GuestAnonymousSDKImpl_webRTCConnection = new WeakMap(), _GuestAnonymousSDKImpl_websocketConnection = new WeakMap(), _GuestAnonymousSDKImpl_frontendLog = new WeakMap(), _GuestAnonymousSDKImpl_abortManager = new WeakMap(), _GuestAnonymousSDKImpl_instances = new WeakSet(), _GuestAnonymousSDKImpl_signaling = function _GuestAnonymousSDKImpl_signaling(options) {
139
- return __awaiter(this, void 0, void 0, function* () {
140
- const { signalingID, spanId, signal } = options;
141
- if (signal.aborted) {
142
- return Promise.reject(signal.reason);
143
- }
144
- let unSubscribers = [];
145
- try {
146
- yield __classPrivateFieldGet(this, _GuestAnonymousSDKImpl_frontendLog, "f").log({
147
- type: "SIGNALING_START",
148
- spanId,
149
- });
150
- const websocket = yield __classPrivateFieldGet(this, _GuestAnonymousSDKImpl_websocketConnection, "f").getOrCreate();
151
- const { connectionPromise } = __classPrivateFieldGet(this, _GuestAnonymousSDKImpl_webRTCConnection, "f").getOrCreateConnection();
152
- const connection = yield connectionPromise;
153
- let isRemoteDescriptionSet = false;
154
- const pendingIceCandidates = [];
155
- // イベントを取り逃がさないように、あらかじめハンドラをセットしておく
156
- unSubscribers = [
157
- (0, notify_ice_candidate_recieved_1.notifyIceCandidateReceived)(websocket).subscribe((iceCandidate) => {
158
- if (isRemoteDescriptionSet) {
159
- connection.addIceCandidate(iceCandidate);
160
- }
161
- else {
162
- pendingIceCandidates.push(iceCandidate);
163
- }
164
- }),
165
- (0, rxjs_1.fromEvent)(connection, "icecandidate").subscribe((event) => {
166
- if (event.candidate) {
167
- (0, send_to_ws_signal_1.sendToWSSignal)(websocket, {
168
- action: "send-ice-candidate",
169
- signalingID,
170
- iceCandidate: event.candidate,
171
- });
172
- }
173
- }),
174
- (0, rxjs_1.fromEvent)(connection, "icecandidateerror").subscribe((event) => {
175
- __classPrivateFieldGet(this, _GuestAnonymousSDKImpl_frontendLog, "f").log({
176
- type: "ICE_CANDIDATE_ERROR",
177
- spanId,
178
- error: (0, gather_all_ice_candidate_1.createICECandidateErrorMessage)(event),
179
- });
180
- }),
181
- ];
182
- const remoteSDP = yield (0, wait_until_sdp_recieve_1.waitUntilSDPReceive)({ websocket, signal });
183
- yield connection.setRemoteDescription(remoteSDP);
184
- isRemoteDescriptionSet = true;
185
- pendingIceCandidates.forEach((iceCandidate) => {
186
- connection.addIceCandidate(iceCandidate);
187
- });
188
- const sdp = yield connection.createAnswer();
189
- yield connection.setLocalDescription(sdp);
190
- (0, send_to_ws_signal_1.sendToWSSignal)(websocket, {
191
- action: "send-sdp",
192
- signalingID,
193
- sdp,
194
- });
195
- yield (0, wait_until_connected_1.waitUntilConnected)(connection, { signal });
196
- yield __classPrivateFieldGet(this, _GuestAnonymousSDKImpl_frontendLog, "f").log({
197
- type: "SIGNALING_END",
198
- spanId,
199
- });
200
- const selectedLocalIceCandidateSummary = yield (0, get_selected_ice_candidate_summary_1.getSelectedIceCandidateSummary)(connection);
201
- if (selectedLocalIceCandidateSummary !== null) {
202
- yield __classPrivateFieldGet(this, _GuestAnonymousSDKImpl_frontendLog, "f").log({
203
- type: "SELECTED_ICE_CANDIDATE_SUMMARY",
204
- spanId,
205
- summary: selectedLocalIceCandidateSummary,
206
- });
207
- }
208
- }
209
- finally {
210
- unSubscribers.forEach((unSubscriber) => unSubscriber.unsubscribe());
211
- }
212
- });
213
- };
148
+ _GuestAnonymousSDKImpl_webRTCConnection = new WeakMap(), _GuestAnonymousSDKImpl_websocketConnection = new WeakMap(), _GuestAnonymousSDKImpl_frontendLog = new WeakMap(), _GuestAnonymousSDKImpl_abortManager = new WeakMap();
214
149
  /**
215
150
  * ゲスト用匿名バックエンドSDKを生成する
216
151
  * @param options オプション
@@ -0,0 +1,23 @@
1
+ import { SignalContainer } from "../../abort-controller/signal-container";
2
+ import { FrontendLogManager } from "../frontend-log-manager";
3
+ /**
4
+ * シグナリングを行う
5
+ * 本処理の前にRemoteSDPを取得しておく必要がある
6
+ * @param options シグナリングのオプション
7
+ * @param options.signalingID シグナリングID
8
+ * @param options.spanId ログ用の識別子
9
+ * @param options.remoteSDP ホスト側のSDP
10
+ * @param options.frontendLog フロントエンドのログマネージャー
11
+ * @param options.rconnection WebRTCコネクション
12
+ * @param options.websocket WebSocketコネクション
13
+ * @param options.signal アボートシグナル
14
+ * @returns シグナリングが完了したら発火するPromise
15
+ */
16
+ export declare const signaling: (options: {
17
+ signalingID: string;
18
+ spanId: string;
19
+ remoteSDP: RTCSessionDescriptionInit;
20
+ frontendLog: FrontendLogManager;
21
+ websocket: WebSocket;
22
+ connection: RTCPeerConnection;
23
+ } & SignalContainer) => Promise<void>;
@@ -0,0 +1,95 @@
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.signaling = void 0;
13
+ const rxjs_1 = require("rxjs");
14
+ const gather_all_ice_candidate_1 = require("../../webrtc/gather-all-ice-candidate");
15
+ const get_selected_ice_candidate_summary_1 = require("../../webrtc/get-selected-ice-candidate-summary");
16
+ const wait_until_connected_1 = require("../../webrtc/wait-until-connected");
17
+ const notify_ice_candidate_recieved_1 = require("../../websocket-api/notify-ice-candidate-recieved");
18
+ const send_to_ws_signal_1 = require("../../websocket-api/send-to-ws-signal");
19
+ /**
20
+ * シグナリングを行う
21
+ * 本処理の前にRemoteSDPを取得しておく必要がある
22
+ * @param options シグナリングのオプション
23
+ * @param options.signalingID シグナリングID
24
+ * @param options.spanId ログ用の識別子
25
+ * @param options.remoteSDP ホスト側のSDP
26
+ * @param options.frontendLog フロントエンドのログマネージャー
27
+ * @param options.rconnection WebRTCコネクション
28
+ * @param options.websocket WebSocketコネクション
29
+ * @param options.signal アボートシグナル
30
+ * @returns シグナリングが完了したら発火するPromise
31
+ */
32
+ const signaling = (options) => __awaiter(void 0, void 0, void 0, function* () {
33
+ const { signalingID, spanId, remoteSDP, frontendLog, websocket, connection, signal, } = options;
34
+ if (signal.aborted) {
35
+ return Promise.reject(signal.reason);
36
+ }
37
+ let unSubscribers = [];
38
+ try {
39
+ yield frontendLog.log({
40
+ type: "SIGNALING_START",
41
+ spanId,
42
+ });
43
+ const setRemoteSDPPromise = connection.setRemoteDescription(remoteSDP);
44
+ unSubscribers = [
45
+ (0, notify_ice_candidate_recieved_1.notifyIceCandidateReceived)(websocket).subscribe((iceCandidate) => {
46
+ // RemoteSDPがセットされた後にICE Candidateを追加する
47
+ // そのためにsetRemoteSDPPromiseを使って、RemoteSDPがセットされるまで待機する
48
+ setRemoteSDPPromise.then(() => {
49
+ connection.addIceCandidate(iceCandidate);
50
+ });
51
+ }),
52
+ (0, rxjs_1.fromEvent)(connection, "icecandidate").subscribe((event) => {
53
+ if (event.candidate) {
54
+ (0, send_to_ws_signal_1.sendToWSSignal)(websocket, {
55
+ action: "send-ice-candidate",
56
+ signalingID,
57
+ iceCandidate: event.candidate,
58
+ });
59
+ }
60
+ }),
61
+ (0, rxjs_1.fromEvent)(connection, "icecandidateerror").subscribe((event) => {
62
+ frontendLog.log({
63
+ type: "ICE_CANDIDATE_ERROR",
64
+ spanId,
65
+ error: (0, gather_all_ice_candidate_1.createICECandidateErrorMessage)(event),
66
+ });
67
+ }),
68
+ ];
69
+ yield setRemoteSDPPromise;
70
+ const sdp = yield connection.createAnswer();
71
+ yield connection.setLocalDescription(sdp);
72
+ (0, send_to_ws_signal_1.sendToWSSignal)(websocket, {
73
+ action: "send-sdp",
74
+ signalingID,
75
+ sdp,
76
+ });
77
+ yield (0, wait_until_connected_1.waitUntilConnected)(connection, { signal });
78
+ yield frontendLog.log({
79
+ type: "SIGNALING_END",
80
+ spanId,
81
+ });
82
+ const selectedLocalIceCandidateSummary = yield (0, get_selected_ice_candidate_summary_1.getSelectedIceCandidateSummary)(connection);
83
+ if (selectedLocalIceCandidateSummary !== null) {
84
+ yield frontendLog.log({
85
+ type: "SELECTED_ICE_CANDIDATE_SUMMARY",
86
+ spanId,
87
+ summary: selectedLocalIceCandidateSummary,
88
+ });
89
+ }
90
+ }
91
+ finally {
92
+ unSubscribers.forEach((unSubscriber) => unSubscriber.unsubscribe());
93
+ }
94
+ });
95
+ exports.signaling = signaling;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gbraver-burst-network/anonymous-browser-sdk",
3
3
  "description": "gbraver burst anonymous browser sdk",
4
- "version": "2.6.0",
4
+ "version": "2.7.0-beta.1",
5
5
  "author": "Y.Takeuchi",
6
6
  "bugs": {
7
7
  "url": "https://github.com/kaidouji85/gbraver-burst-network/issues",