@gbraver-burst-network/browser-sdk 1.5.8 → 1.5.10
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/auth0/client.js +2 -5
- package/lib/auth0/client.js.flow +14 -9
- package/lib/auth0/login-redirect.js +2 -3
- package/lib/auth0/login-redirect.js.flow +2 -2
- package/lib/browser-sdk/battle-sdk.js +6 -16
- package/lib/browser-sdk/battle-sdk.js.flow +27 -16
- package/lib/browser-sdk/browser-sdk.js +24 -55
- package/lib/browser-sdk/browser-sdk.js.flow +77 -34
- package/lib/http-request/delete-user.js +2 -2
- package/lib/http-request/delete-user.js.flow +8 -5
- package/lib/index.js +0 -1
- package/lib/index.js.flow +2 -2
- package/lib/json/parse.js.flow +1 -1
- package/lib/promise/promise.js.flow +1 -1
- package/lib/request/battle-progress-polling.js.flow +3 -3
- package/lib/request/enter-casual-match.js.flow +3 -3
- package/lib/request/ping.js.flow +2 -2
- package/lib/request/request.js.flow +8 -8
- package/lib/request/send-command.js.flow +4 -4
- package/lib/response/accept-command.js +1 -1
- package/lib/response/accept-command.js.flow +3 -5
- package/lib/response/battle-end.js +1 -1
- package/lib/response/battle-end.js.flow +5 -5
- package/lib/response/battle-progressed.js +1 -1
- package/lib/response/battle-progressed.js.flow +7 -6
- package/lib/response/battle-start.js +1 -1
- package/lib/response/battle-start.js.flow +23 -12
- package/lib/response/entered-casual-match.js +1 -1
- package/lib/response/entered-casual-match.js.flow +4 -4
- package/lib/response/error.js +1 -1
- package/lib/response/error.js.flow +4 -4
- package/lib/response/not-ready-battle-progress.js +1 -1
- package/lib/response/not-ready-battle-progress.js.flow +7 -5
- package/lib/response/pong.js +1 -1
- package/lib/response/pong.js.flow +6 -6
- package/lib/response/suddenly-battle-end.js +1 -1
- package/lib/response/suddenly-battle-end.js.flow +4 -4
- package/lib/response/websocket-api-response.js.flow +18 -18
- package/lib/wait/wait.js.flow +2 -2
- package/lib/websocket/connect.js +4 -5
- package/lib/websocket/connect.js.flow +7 -8
- package/lib/websocket/enter-casual-match.js +3 -7
- package/lib/websocket/enter-casual-match.js.flow +26 -14
- package/lib/websocket/ping.js +2 -6
- package/lib/websocket/ping.js.flow +16 -13
- package/lib/websocket/send-command.js +10 -30
- package/lib/websocket/send-command.js.flow +100 -62
- package/lib/websocket/send-to-api-server.js.flow +6 -3
- package/lib/websocket/wait-until.js +5 -6
- package/lib/websocket/wait-until.js.flow +17 -11
- package/package.json +22 -14
package/lib/auth0/client.js
CHANGED
|
@@ -4,16 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createAuth0ClientHelper = createAuth0ClientHelper;
|
|
7
|
-
|
|
8
7
|
var _auth0SpaJs = _interopRequireWildcard(require("@auth0/auth0-spa-js"));
|
|
9
|
-
|
|
10
8
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
11
|
-
|
|
12
9
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
13
10
|
|
|
14
11
|
/**
|
|
15
12
|
* Auth0Clientを生成するヘルパー関数
|
|
16
|
-
*
|
|
13
|
+
*
|
|
17
14
|
* @param domain auth0ドメイン
|
|
18
15
|
* @param clientID auth0クライアントID
|
|
19
16
|
* @param audience auth0 audience
|
|
@@ -24,7 +21,7 @@ function createAuth0ClientHelper(domain, clientID, audience, redirectURI) {
|
|
|
24
21
|
return (0, _auth0SpaJs.default)({
|
|
25
22
|
domain: domain,
|
|
26
23
|
client_id: clientID,
|
|
27
|
-
responseType:
|
|
24
|
+
responseType: "token id_token",
|
|
28
25
|
audience: audience,
|
|
29
26
|
redirectUri: redirectURI
|
|
30
27
|
});
|
package/lib/auth0/client.js.flow
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
|
|
3
|
-
import createAuth0Client, {Auth0Client} from
|
|
3
|
+
import createAuth0Client, { Auth0Client } from "@auth0/auth0-spa-js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Auth0Clientを生成するヘルパー関数
|
|
7
|
-
*
|
|
7
|
+
*
|
|
8
8
|
* @param domain auth0ドメイン
|
|
9
9
|
* @param clientID auth0クライアントID
|
|
10
10
|
* @param audience auth0 audience
|
|
11
11
|
* @param redirectURI リダイレクト元となるGブレイバーバーストのURL
|
|
12
12
|
* @return Auth0Client
|
|
13
13
|
*/
|
|
14
|
-
export function createAuth0ClientHelper(
|
|
14
|
+
export function createAuth0ClientHelper(
|
|
15
|
+
domain: string,
|
|
16
|
+
clientID: string,
|
|
17
|
+
audience: string,
|
|
18
|
+
redirectURI: string
|
|
19
|
+
): Promise<typeof Auth0Client> {
|
|
15
20
|
return createAuth0Client({
|
|
16
|
-
domain: domain,
|
|
17
|
-
client_id: clientID,
|
|
18
|
-
responseType:
|
|
19
|
-
audience: audience,
|
|
20
|
-
redirectUri: redirectURI
|
|
21
|
+
domain: domain,
|
|
22
|
+
client_id: clientID,
|
|
23
|
+
responseType: "token id_token",
|
|
24
|
+
audience: audience,
|
|
25
|
+
redirectUri: redirectURI,
|
|
21
26
|
});
|
|
22
|
-
}
|
|
27
|
+
}
|
|
@@ -9,18 +9,17 @@ exports.isLoginSuccessRedirect = isLoginSuccessRedirect;
|
|
|
9
9
|
/**
|
|
10
10
|
* ログイン成功時のリダイレクトか否かを判定する
|
|
11
11
|
* trueでログイン成功時のリダイレクトである
|
|
12
|
-
*
|
|
12
|
+
*
|
|
13
13
|
* @return 判定結果
|
|
14
14
|
*/
|
|
15
15
|
function isLoginSuccessRedirect() {
|
|
16
16
|
const query = window.location.search;
|
|
17
17
|
return query.includes("code=") && query.includes("state=");
|
|
18
18
|
}
|
|
19
|
+
|
|
19
20
|
/**
|
|
20
21
|
* ログインリダイレクトのヒストリーをクリアする
|
|
21
22
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
24
23
|
function clearLoginHistory() {
|
|
25
24
|
window.history.replaceState({}, document.title, "/");
|
|
26
25
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* ログイン成功時のリダイレクトか否かを判定する
|
|
5
5
|
* trueでログイン成功時のリダイレクトである
|
|
6
|
-
*
|
|
6
|
+
*
|
|
7
7
|
* @return 判定結果
|
|
8
8
|
*/
|
|
9
9
|
export function isLoginSuccessRedirect(): boolean {
|
|
@@ -16,4 +16,4 @@ export function isLoginSuccessRedirect(): boolean {
|
|
|
16
16
|
*/
|
|
17
17
|
export function clearLoginHistory(): void {
|
|
18
18
|
window.history.replaceState({}, document.title, "/");
|
|
19
|
-
}
|
|
19
|
+
}
|
|
@@ -4,14 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.BattleSDK = void 0;
|
|
7
|
-
|
|
8
|
-
var _sendCommand = require("../websocket/send-command");
|
|
9
|
-
|
|
10
7
|
var _rxjs = require("rxjs");
|
|
11
|
-
|
|
12
8
|
var _parse = require("../json/parse");
|
|
13
|
-
|
|
14
9
|
var _suddenlyBattleEnd = require("../response/suddenly-battle-end");
|
|
10
|
+
var _sendCommand = require("../websocket/send-command");
|
|
15
11
|
|
|
16
12
|
/** バトルSDK */
|
|
17
13
|
class BattleSDK {
|
|
@@ -23,7 +19,7 @@ class BattleSDK {
|
|
|
23
19
|
|
|
24
20
|
/**
|
|
25
21
|
* コンストラクタ
|
|
26
|
-
*
|
|
22
|
+
*
|
|
27
23
|
* @param param パラメータ
|
|
28
24
|
*/
|
|
29
25
|
constructor(param) {
|
|
@@ -34,27 +30,21 @@ class BattleSDK {
|
|
|
34
30
|
this._battleID = param.battleID;
|
|
35
31
|
this._flowID = param.initialFlowID;
|
|
36
32
|
this._isPoller = param.isPoller;
|
|
37
|
-
this._suddenlyBattleEnd = (0, _rxjs.fromEvent)(this._websocket,
|
|
33
|
+
this._suddenlyBattleEnd = (0, _rxjs.fromEvent)(this._websocket, "message").pipe((0, _rxjs.map)(e => (0, _parse.parseJSON)(e.data)), (0, _rxjs.filter)(data => data), (0, _rxjs.map)(data => (0, _suddenlyBattleEnd.parseSuddenlyBattleEnd)(data)), (0, _rxjs.filter)(sudenlyBattleEnd => sudenlyBattleEnd));
|
|
38
34
|
}
|
|
39
|
-
/** @override */
|
|
40
|
-
|
|
41
35
|
|
|
36
|
+
/** @override */
|
|
42
37
|
async progress(command) {
|
|
43
38
|
const result = this._isPoller ? await (0, _sendCommand.sendCommandWithPolling)(this._websocket, this._battleID, this._flowID, command) : await (0, _sendCommand.sendCommand)(this._websocket, this._battleID, this._flowID, command);
|
|
44
|
-
|
|
45
|
-
if (result.action === 'battle-progressed') {
|
|
39
|
+
if (result.action === "battle-progressed") {
|
|
46
40
|
this._flowID = result.flowID;
|
|
47
41
|
}
|
|
48
|
-
|
|
49
42
|
return result.update;
|
|
50
43
|
}
|
|
51
|
-
/** @override */
|
|
52
|
-
|
|
53
44
|
|
|
45
|
+
/** @override */
|
|
54
46
|
suddenlyBattleNotifier() {
|
|
55
47
|
return this._suddenlyBattleEnd;
|
|
56
48
|
}
|
|
57
|
-
|
|
58
49
|
}
|
|
59
|
-
|
|
60
50
|
exports.BattleSDK = BattleSDK;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import {parseJSON} from "../json/parse";
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
3
|
+
import type { Battle } from "@gbraver-burst-network/browser-core";
|
|
4
|
+
import type { Command,GameState, Player } from "gbraver-burst-core";
|
|
5
|
+
import { filter,fromEvent, map, Observable } from "rxjs";
|
|
6
|
+
|
|
7
|
+
import { parseJSON } from "../json/parse";
|
|
8
|
+
import type { SuddenlyBattleEnd } from "../response/suddenly-battle-end";
|
|
9
|
+
import { parseSuddenlyBattleEnd } from "../response/suddenly-battle-end";
|
|
10
|
+
import { sendCommand, sendCommandWithPolling } from "../websocket/send-command";
|
|
10
11
|
|
|
11
12
|
/** コンストラクタのパラメータ */
|
|
12
13
|
type Param = {
|
|
@@ -34,7 +35,7 @@ export class BattleSDK implements Battle {
|
|
|
34
35
|
enemy: Player;
|
|
35
36
|
/** @override */
|
|
36
37
|
initialState: GameState[];
|
|
37
|
-
|
|
38
|
+
|
|
38
39
|
_websocket: WebSocket;
|
|
39
40
|
_battleID: string;
|
|
40
41
|
_flowID: string;
|
|
@@ -43,7 +44,7 @@ export class BattleSDK implements Battle {
|
|
|
43
44
|
|
|
44
45
|
/**
|
|
45
46
|
* コンストラクタ
|
|
46
|
-
*
|
|
47
|
+
*
|
|
47
48
|
* @param param パラメータ
|
|
48
49
|
*/
|
|
49
50
|
constructor(param: Param) {
|
|
@@ -54,20 +55,30 @@ export class BattleSDK implements Battle {
|
|
|
54
55
|
this._battleID = param.battleID;
|
|
55
56
|
this._flowID = param.initialFlowID;
|
|
56
57
|
this._isPoller = param.isPoller;
|
|
57
|
-
this._suddenlyBattleEnd = fromEvent(this._websocket,
|
|
58
|
+
this._suddenlyBattleEnd = fromEvent(this._websocket, "message").pipe(
|
|
58
59
|
map((e: MessageEvent) => parseJSON(e.data)),
|
|
59
60
|
filter((data: ?Object) => data),
|
|
60
61
|
map((data: Object) => parseSuddenlyBattleEnd(data)),
|
|
61
|
-
filter((sudenlyBattleEnd: ?SuddenlyBattleEnd) => sudenlyBattleEnd)
|
|
62
|
+
filter((sudenlyBattleEnd: ?SuddenlyBattleEnd) => sudenlyBattleEnd)
|
|
62
63
|
);
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
+
|
|
65
66
|
/** @override */
|
|
66
67
|
async progress(command: Command): Promise<GameState[]> {
|
|
67
68
|
const result = this._isPoller
|
|
68
|
-
? await sendCommandWithPolling(
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
? await sendCommandWithPolling(
|
|
70
|
+
this._websocket,
|
|
71
|
+
this._battleID,
|
|
72
|
+
this._flowID,
|
|
73
|
+
command
|
|
74
|
+
)
|
|
75
|
+
: await sendCommand(
|
|
76
|
+
this._websocket,
|
|
77
|
+
this._battleID,
|
|
78
|
+
this._flowID,
|
|
79
|
+
command
|
|
80
|
+
);
|
|
81
|
+
if (result.action === "battle-progressed") {
|
|
71
82
|
this._flowID = result.flowID;
|
|
72
83
|
}
|
|
73
84
|
return result.update;
|
|
@@ -77,4 +88,4 @@ export class BattleSDK implements Battle {
|
|
|
77
88
|
suddenlyBattleNotifier(): typeof Observable {
|
|
78
89
|
return this._suddenlyBattleEnd;
|
|
79
90
|
}
|
|
80
|
-
}
|
|
91
|
+
}
|
|
@@ -4,24 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createBrowserSDK = createBrowserSDK;
|
|
7
|
-
|
|
8
|
-
var _rxjs = require("rxjs");
|
|
9
|
-
|
|
10
|
-
var _battleSdk = require("./battle-sdk");
|
|
11
|
-
|
|
12
7
|
var _auth0SpaJs = require("@auth0/auth0-spa-js");
|
|
13
|
-
|
|
8
|
+
var _rxjs = require("rxjs");
|
|
14
9
|
var _client = require("../auth0/client");
|
|
15
|
-
|
|
16
10
|
var _loginRedirect = require("../auth0/login-redirect");
|
|
17
|
-
|
|
18
|
-
var _ping = require("../websocket/ping");
|
|
19
|
-
|
|
11
|
+
var _deleteUser = require("../http-request/delete-user");
|
|
20
12
|
var _connect = require("../websocket/connect");
|
|
21
|
-
|
|
22
13
|
var _enterCasualMatch = require("../websocket/enter-casual-match");
|
|
23
|
-
|
|
24
|
-
var
|
|
14
|
+
var _ping = require("../websocket/ping");
|
|
15
|
+
var _battleSdk = require("./battle-sdk");
|
|
25
16
|
|
|
26
17
|
/** ブラウザSDK実装 */
|
|
27
18
|
class BrowserSDKImpl {
|
|
@@ -43,87 +34,74 @@ class BrowserSDKImpl {
|
|
|
43
34
|
this._websocketUnintentionalCloseNotifier = new _rxjs.Subject();
|
|
44
35
|
this._websocketSubscriptions = [];
|
|
45
36
|
}
|
|
46
|
-
/** @override */
|
|
47
|
-
|
|
48
37
|
|
|
38
|
+
/** @override */
|
|
49
39
|
isLoginSuccessRedirect() {
|
|
50
40
|
return (0, _loginRedirect.isLoginSuccessRedirect)();
|
|
51
41
|
}
|
|
52
|
-
/** @override */
|
|
53
|
-
|
|
54
42
|
|
|
43
|
+
/** @override */
|
|
55
44
|
async afterLoginSuccess() {
|
|
56
45
|
await this._auth0Client.handleRedirectCallback();
|
|
57
46
|
(0, _loginRedirect.clearLoginHistory)();
|
|
58
47
|
}
|
|
59
|
-
/** @override */
|
|
60
|
-
|
|
61
48
|
|
|
49
|
+
/** @override */
|
|
62
50
|
async gotoLoginPage() {
|
|
63
51
|
await this._auth0Client.loginWithRedirect({
|
|
64
52
|
redirect_uri: this._ownURL
|
|
65
53
|
});
|
|
66
54
|
}
|
|
67
|
-
/** @override */
|
|
68
|
-
|
|
69
55
|
|
|
56
|
+
/** @override */
|
|
70
57
|
isLogin() {
|
|
71
58
|
return this._auth0Client.isAuthenticated();
|
|
72
59
|
}
|
|
73
|
-
/** @override */
|
|
74
|
-
|
|
75
60
|
|
|
61
|
+
/** @override */
|
|
76
62
|
async logout() {
|
|
77
63
|
await this._auth0Client.logout({
|
|
78
64
|
returnTo: this._ownURL
|
|
79
65
|
});
|
|
80
66
|
}
|
|
81
|
-
/** @override */
|
|
82
|
-
|
|
83
67
|
|
|
68
|
+
/** @override */
|
|
84
69
|
async getUserName() {
|
|
85
70
|
const user = await this._auth0Client.getUser();
|
|
86
|
-
return user?.nickname ??
|
|
71
|
+
return user?.nickname ?? "";
|
|
87
72
|
}
|
|
88
|
-
/** @override */
|
|
89
|
-
|
|
90
73
|
|
|
74
|
+
/** @override */
|
|
91
75
|
async getUserPictureURL() {
|
|
92
76
|
const user = await this._auth0Client.getUser();
|
|
93
|
-
return user?.picture ??
|
|
77
|
+
return user?.picture ?? "";
|
|
94
78
|
}
|
|
95
79
|
/** @override */
|
|
96
|
-
|
|
97
|
-
|
|
98
80
|
async getMail() {
|
|
99
81
|
const user = await this._auth0Client.getUser();
|
|
100
|
-
return user?.email ??
|
|
82
|
+
return user?.email ?? "";
|
|
101
83
|
}
|
|
102
|
-
/** @override */
|
|
103
|
-
|
|
104
84
|
|
|
85
|
+
/** @override */
|
|
105
86
|
async isMailVerified() {
|
|
106
87
|
const user = await this._auth0Client.getUser();
|
|
107
88
|
return user?.email_verified;
|
|
108
89
|
}
|
|
109
|
-
/** @override */
|
|
110
|
-
|
|
111
90
|
|
|
91
|
+
/** @override */
|
|
112
92
|
async deleteLoggedInUser() {
|
|
113
93
|
const accessToken = await this._auth0Client.getTokenSilently();
|
|
114
94
|
await (0, _deleteUser.deleteLoggedInUser)(this._restAPIURL, accessToken);
|
|
115
95
|
}
|
|
116
|
-
/** @override */
|
|
117
|
-
|
|
118
96
|
|
|
97
|
+
/** @override */
|
|
119
98
|
async ping() {
|
|
120
99
|
const websocket = await this._getOrCreateWebSocket();
|
|
121
100
|
const resp = await (0, _ping.ping)(websocket);
|
|
122
101
|
return resp.message;
|
|
123
102
|
}
|
|
124
|
-
/** @override */
|
|
125
|
-
|
|
126
103
|
|
|
104
|
+
/** @override */
|
|
127
105
|
async startCasualMatch(armdozerId, pilotId) {
|
|
128
106
|
const websocket = await this._getOrCreateWebSocket();
|
|
129
107
|
const resp = await (0, _enterCasualMatch.enterCasualMatch)(websocket, armdozerId, pilotId);
|
|
@@ -137,52 +115,45 @@ class BrowserSDKImpl {
|
|
|
137
115
|
websocket
|
|
138
116
|
});
|
|
139
117
|
}
|
|
140
|
-
/** @override */
|
|
141
|
-
|
|
142
118
|
|
|
119
|
+
/** @override */
|
|
143
120
|
async disconnectWebsocket() {
|
|
144
121
|
this._websocket && this._websocket.close();
|
|
145
122
|
this._websocket = null;
|
|
146
|
-
|
|
147
123
|
this._websocketSubscriptions.forEach(v => {
|
|
148
124
|
v.unsubscribe();
|
|
149
125
|
});
|
|
150
|
-
|
|
151
126
|
this._websocketSubscriptions = [];
|
|
152
127
|
}
|
|
153
|
-
/** @override */
|
|
154
|
-
|
|
155
128
|
|
|
129
|
+
/** @override */
|
|
156
130
|
websocketErrorNotifier() {
|
|
157
131
|
return this._websocketError;
|
|
158
132
|
}
|
|
159
|
-
/** @override */
|
|
160
|
-
|
|
161
133
|
|
|
134
|
+
/** @override */
|
|
162
135
|
websocketUnintentionalCloseNotifier() {
|
|
163
136
|
return this._websocketUnintentionalCloseNotifier;
|
|
164
137
|
}
|
|
138
|
+
|
|
165
139
|
/**
|
|
166
140
|
* WebSocketクライアントの取得を行う
|
|
167
141
|
* WebSocketクライアントが存在しない場合は、本メソッド内で生成してから返す
|
|
168
142
|
*
|
|
169
143
|
* @return 取得、生成結果
|
|
170
144
|
*/
|
|
171
|
-
|
|
172
|
-
|
|
173
145
|
async _getOrCreateWebSocket() {
|
|
174
146
|
if (this._websocket) {
|
|
175
147
|
return this._websocket;
|
|
176
148
|
}
|
|
177
|
-
|
|
178
149
|
const accessToken = await this._auth0Client.getTokenSilently();
|
|
179
150
|
const websocket = await (0, _connect.connect)(`${this._websocketAPIURL}?token=${accessToken}`);
|
|
180
|
-
this._websocketSubscriptions = [(0, _rxjs.fromEvent)(websocket,
|
|
151
|
+
this._websocketSubscriptions = [(0, _rxjs.fromEvent)(websocket, "error").subscribe(this._websocketError), (0, _rxjs.fromEvent)(websocket, "close").subscribe(this._websocketError)];
|
|
181
152
|
this._websocket = websocket;
|
|
182
153
|
return websocket;
|
|
183
154
|
}
|
|
184
|
-
|
|
185
155
|
}
|
|
156
|
+
|
|
186
157
|
/**
|
|
187
158
|
* GブレイバーバーストブラウザSDKを生成する
|
|
188
159
|
*
|
|
@@ -194,8 +165,6 @@ class BrowserSDKImpl {
|
|
|
194
165
|
* @param auth0Audience auth0 audience
|
|
195
166
|
* @return GブレイバーバーストブラウザSDK
|
|
196
167
|
*/
|
|
197
|
-
|
|
198
|
-
|
|
199
168
|
async function createBrowserSDK(ownURL, restAPIURL, websocketAPIURL, auth0Domain, auth0ClientID, auth0Audience) {
|
|
200
169
|
const auth0Client = await (0, _client.createAuth0ClientHelper)(auth0Domain, auth0ClientID, auth0Audience, ownURL);
|
|
201
170
|
return new BrowserSDKImpl(ownURL, restAPIURL, websocketAPIURL, auth0Client);
|
|
@@ -1,36 +1,51 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { Auth0Client } from "@auth0/auth0-spa-js";
|
|
4
4
|
import type {
|
|
5
5
|
Battle,
|
|
6
6
|
CasualMatch,
|
|
7
7
|
LoggedInUserDelete,
|
|
8
8
|
LoginCheck,
|
|
9
9
|
Logout,
|
|
10
|
+
MailVerify,
|
|
10
11
|
Ping,
|
|
11
12
|
UniversalLogin,
|
|
13
|
+
UserMailGet,
|
|
12
14
|
UserNameGet,
|
|
13
15
|
UserPictureGet,
|
|
14
|
-
UserMailGet,
|
|
15
|
-
MailVerify,
|
|
16
16
|
WebsocketDisconnect,
|
|
17
17
|
WebsocketErrorNotifier,
|
|
18
|
-
WebsocketUnintentionalCloseNotifier
|
|
19
|
-
} from
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
import {createAuth0ClientHelper} from
|
|
24
|
-
import {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
import {deleteLoggedInUser} from "../http-request/delete-user";
|
|
18
|
+
WebsocketUnintentionalCloseNotifier,
|
|
19
|
+
} from "@gbraver-burst-network/browser-core";
|
|
20
|
+
import type { ArmDozerId, PilotId } from "gbraver-burst-core";
|
|
21
|
+
import { fromEvent, Observable, Subject, Subscription } from "rxjs";
|
|
22
|
+
|
|
23
|
+
import { createAuth0ClientHelper } from "../auth0/client";
|
|
24
|
+
import {
|
|
25
|
+
clearLoginHistory,
|
|
26
|
+
isLoginSuccessRedirect,
|
|
27
|
+
} from "../auth0/login-redirect";
|
|
28
|
+
import { deleteLoggedInUser } from "../http-request/delete-user";
|
|
29
|
+
import { connect } from "../websocket/connect";
|
|
30
|
+
import { enterCasualMatch } from "../websocket/enter-casual-match";
|
|
31
|
+
import { ping } from "../websocket/ping";
|
|
32
|
+
import { BattleSDK } from "./battle-sdk";
|
|
29
33
|
|
|
30
34
|
/** ブラウザSDK */
|
|
31
|
-
export interface BrowserSDK
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
export interface BrowserSDK
|
|
36
|
+
extends UniversalLogin,
|
|
37
|
+
LoginCheck,
|
|
38
|
+
Logout,
|
|
39
|
+
Ping,
|
|
40
|
+
CasualMatch,
|
|
41
|
+
UserNameGet,
|
|
42
|
+
UserPictureGet,
|
|
43
|
+
UserMailGet,
|
|
44
|
+
MailVerify,
|
|
45
|
+
LoggedInUserDelete,
|
|
46
|
+
WebsocketDisconnect,
|
|
47
|
+
WebsocketErrorNotifier,
|
|
48
|
+
WebsocketUnintentionalCloseNotifier {}
|
|
34
49
|
|
|
35
50
|
/** ブラウザSDK実装 */
|
|
36
51
|
class BrowserSDKImpl implements BrowserSDK {
|
|
@@ -51,7 +66,12 @@ class BrowserSDKImpl implements BrowserSDK {
|
|
|
51
66
|
* @param websocketAPIURL Websocket API のURL
|
|
52
67
|
* @param auth0Client auth0クライアント
|
|
53
68
|
*/
|
|
54
|
-
constructor(
|
|
69
|
+
constructor(
|
|
70
|
+
ownURL: string,
|
|
71
|
+
restAPIURL: string,
|
|
72
|
+
websocketAPIURL: string,
|
|
73
|
+
auth0Client: typeof Auth0Client
|
|
74
|
+
) {
|
|
55
75
|
this._ownURL = ownURL;
|
|
56
76
|
this._restAPIURL = restAPIURL;
|
|
57
77
|
this._websocketAPIURL = websocketAPIURL;
|
|
@@ -75,7 +95,7 @@ class BrowserSDKImpl implements BrowserSDK {
|
|
|
75
95
|
|
|
76
96
|
/** @override */
|
|
77
97
|
async gotoLoginPage(): Promise<void> {
|
|
78
|
-
await this._auth0Client.loginWithRedirect({redirect_uri: this._ownURL});
|
|
98
|
+
await this._auth0Client.loginWithRedirect({ redirect_uri: this._ownURL });
|
|
79
99
|
}
|
|
80
100
|
|
|
81
101
|
/** @override */
|
|
@@ -85,24 +105,24 @@ class BrowserSDKImpl implements BrowserSDK {
|
|
|
85
105
|
|
|
86
106
|
/** @override */
|
|
87
107
|
async logout(): Promise<void> {
|
|
88
|
-
await this._auth0Client.logout({returnTo: this._ownURL});
|
|
108
|
+
await this._auth0Client.logout({ returnTo: this._ownURL });
|
|
89
109
|
}
|
|
90
110
|
|
|
91
111
|
/** @override */
|
|
92
112
|
async getUserName(): Promise<string> {
|
|
93
113
|
const user = await this._auth0Client.getUser();
|
|
94
|
-
return user?.nickname ??
|
|
114
|
+
return user?.nickname ?? "";
|
|
95
115
|
}
|
|
96
116
|
|
|
97
117
|
/** @override */
|
|
98
118
|
async getUserPictureURL(): Promise<string> {
|
|
99
119
|
const user = await this._auth0Client.getUser();
|
|
100
|
-
return user?.picture ??
|
|
120
|
+
return user?.picture ?? "";
|
|
101
121
|
}
|
|
102
122
|
/** @override */
|
|
103
123
|
async getMail(): Promise<string> {
|
|
104
124
|
const user = await this._auth0Client.getUser();
|
|
105
|
-
return user?.email ??
|
|
125
|
+
return user?.email ?? "";
|
|
106
126
|
}
|
|
107
127
|
|
|
108
128
|
/** @override */
|
|
@@ -125,22 +145,31 @@ class BrowserSDKImpl implements BrowserSDK {
|
|
|
125
145
|
}
|
|
126
146
|
|
|
127
147
|
/** @override */
|
|
128
|
-
async startCasualMatch(
|
|
148
|
+
async startCasualMatch(
|
|
149
|
+
armdozerId: ArmDozerId,
|
|
150
|
+
pilotId: PilotId
|
|
151
|
+
): Promise<Battle> {
|
|
129
152
|
const websocket = await this._getOrCreateWebSocket();
|
|
130
153
|
const resp = await enterCasualMatch(websocket, armdozerId, pilotId);
|
|
131
|
-
return new BattleSDK({
|
|
132
|
-
|
|
154
|
+
return new BattleSDK({
|
|
155
|
+
player: resp.player,
|
|
156
|
+
enemy: resp.enemy,
|
|
157
|
+
initialState: resp.stateHistory,
|
|
158
|
+
battleID: resp.battleID,
|
|
159
|
+
initialFlowID: resp.flowID,
|
|
160
|
+
isPoller: resp.isPoller,
|
|
161
|
+
websocket,
|
|
162
|
+
});
|
|
133
163
|
}
|
|
134
164
|
|
|
135
165
|
/** @override */
|
|
136
166
|
async disconnectWebsocket(): Promise<void> {
|
|
137
167
|
this._websocket && this._websocket.close();
|
|
138
168
|
this._websocket = null;
|
|
139
|
-
this._websocketSubscriptions.forEach(v => {
|
|
169
|
+
this._websocketSubscriptions.forEach((v) => {
|
|
140
170
|
v.unsubscribe();
|
|
141
171
|
});
|
|
142
172
|
this._websocketSubscriptions = [];
|
|
143
|
-
|
|
144
173
|
}
|
|
145
174
|
|
|
146
175
|
/** @override */
|
|
@@ -165,10 +194,12 @@ class BrowserSDKImpl implements BrowserSDK {
|
|
|
165
194
|
}
|
|
166
195
|
|
|
167
196
|
const accessToken = await this._auth0Client.getTokenSilently();
|
|
168
|
-
const websocket = await connect(
|
|
197
|
+
const websocket = await connect(
|
|
198
|
+
`${this._websocketAPIURL}?token=${accessToken}`
|
|
199
|
+
);
|
|
169
200
|
this._websocketSubscriptions = [
|
|
170
|
-
fromEvent(websocket,
|
|
171
|
-
fromEvent(websocket,
|
|
201
|
+
fromEvent(websocket, "error").subscribe(this._websocketError),
|
|
202
|
+
fromEvent(websocket, "close").subscribe(this._websocketError),
|
|
172
203
|
];
|
|
173
204
|
this._websocket = websocket;
|
|
174
205
|
return websocket;
|
|
@@ -186,7 +217,19 @@ class BrowserSDKImpl implements BrowserSDK {
|
|
|
186
217
|
* @param auth0Audience auth0 audience
|
|
187
218
|
* @return GブレイバーバーストブラウザSDK
|
|
188
219
|
*/
|
|
189
|
-
export async function createBrowserSDK(
|
|
190
|
-
|
|
220
|
+
export async function createBrowserSDK(
|
|
221
|
+
ownURL: string,
|
|
222
|
+
restAPIURL: string,
|
|
223
|
+
websocketAPIURL: string,
|
|
224
|
+
auth0Domain: string,
|
|
225
|
+
auth0ClientID: string,
|
|
226
|
+
auth0Audience: string
|
|
227
|
+
): Promise<BrowserSDK> {
|
|
228
|
+
const auth0Client = await createAuth0ClientHelper(
|
|
229
|
+
auth0Domain,
|
|
230
|
+
auth0ClientID,
|
|
231
|
+
auth0Audience,
|
|
232
|
+
ownURL
|
|
233
|
+
);
|
|
191
234
|
return new BrowserSDKImpl(ownURL, restAPIURL, websocketAPIURL, auth0Client);
|
|
192
|
-
}
|
|
235
|
+
}
|
|
@@ -14,10 +14,10 @@ exports.deleteLoggedInUser = deleteLoggedInUser;
|
|
|
14
14
|
*/
|
|
15
15
|
async function deleteLoggedInUser(restAPIURL, accessToken) {
|
|
16
16
|
await fetch(`${restAPIURL}`, {
|
|
17
|
-
mode:
|
|
17
|
+
mode: "cors",
|
|
18
18
|
headers: {
|
|
19
19
|
Authorization: `Bearer ${accessToken}`
|
|
20
20
|
},
|
|
21
|
-
method:
|
|
21
|
+
method: "DELETE"
|
|
22
22
|
});
|
|
23
23
|
}
|
|
@@ -7,12 +7,15 @@
|
|
|
7
7
|
* @param accessToken Auth0 アクセストークン
|
|
8
8
|
* @return 処理が完了したら発火するPromise
|
|
9
9
|
*/
|
|
10
|
-
export async function deleteLoggedInUser(
|
|
10
|
+
export async function deleteLoggedInUser(
|
|
11
|
+
restAPIURL: string,
|
|
12
|
+
accessToken: string
|
|
13
|
+
): Promise<void> {
|
|
11
14
|
await fetch(`${restAPIURL}`, {
|
|
12
|
-
mode:
|
|
15
|
+
mode: "cors",
|
|
13
16
|
headers: {
|
|
14
|
-
Authorization: `Bearer ${accessToken}
|
|
17
|
+
Authorization: `Bearer ${accessToken}`,
|
|
15
18
|
},
|
|
16
|
-
method:
|
|
19
|
+
method: "DELETE",
|
|
17
20
|
});
|
|
18
|
-
}
|
|
21
|
+
}
|