bedrock-portal 0.6.4 → 0.7.3

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 CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2020
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2020
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,260 +1,260 @@
1
- # BedrockPortal
2
- [![NPM version](https://img.shields.io/npm/v/bedrock-portal.svg)](http://npmjs.com/package/bedrock-portal)
3
- [![Discord](https://img.shields.io/badge/chat-on%20discord-brightgreen.svg)](https://discord.gg/KTyd9HWuBD)
4
-
5
- Handles and creates a Minecraft Bedrock game session which will redirect players to the specified server. Join our [Discord](https://discord.com/invite/KTyd9HWuBD) for support.
6
-
7
- ## Installation
8
- ```shell
9
- npm install bedrock-portal
10
- ```
11
-
12
- ### Warning
13
- This package is not meant to be used with your main account. It is meant to be used with alt accounts. If you use this package with your main account, you may be banned from the XSAPI. This package is not affiliated with Mojang or Microsoft.
14
-
15
- ## Usage
16
-
17
- ### BedrockPortal(authflow, options)
18
- **Parameters**
19
- - authflow - Takes an **Authflow** instance from [prismarine-auth](https://github.com/PrismarineJS/prismarine-auth), you can see the documentation for this [here.](https://github.com/PrismarineJS/prismarine-auth#authflow)
20
- - options
21
- - **ip** - The IP address of the server to redirect players to (required)
22
- - **port** - The port of the server to redirect players to | default: 19132
23
- - **joinability** - The joinability of the session | default: FriendsOfFriends
24
- - **world** - The world config to use for the session. Changes the session card which is displayed in the Minecraft client. (optional)
25
- - **hostName** - string
26
- - **name** - string
27
- - **version** - string
28
- - **memberCount** - number
29
- - **maxMemberCount** - number
30
-
31
- ### Create a session redirect to a server
32
- ```js
33
- const { BedrockPortal, Joinability } = require('bedrock-portal');
34
- const { Authflow, Titles } = require('prismarine-auth');
35
-
36
- const main = async () => {
37
- const auth = new Authflow('example', './', { authTitle: Titles.MinecraftNintendoSwitch, deviceType: 'Nintendo', flow: 'live' });
38
-
39
- const portal = new BedrockPortal(auth, {
40
- // The server IP & port to redirect players to
41
- ip: 'geyserconnect.net',
42
- port: 19132,
43
-
44
- // The joinability of the session. Joinability.FriendsOfFriends, Joinability.FriendsOnly, Joinability.InviteOnly
45
- joinability: Joinability.FriendsOfFriends
46
- });
47
-
48
- await portal.start();
49
-
50
- // accepts a player's gamertag or xuid
51
- await portal.invitePlayer('p3')
52
-
53
- };
54
-
55
- main();
56
- ```
57
-
58
- ## Modules
59
-
60
- Modules are used to extend the functionality of the BedrockPortal class.
61
-
62
- ### MultipleAccounts
63
-
64
- Allows the portal to use multiple accounts to redirect players to the server. `#.use(Modules.MultipleAccounts, options);`
65
-
66
- Options:
67
- - **accounts**: Authflow[] - An array of authflows from [prismarine-auth](https://github.com/PrismarineJS/prismarine-auth), these accounts are automatically added to the host session and allows players to add them as a friend to join the game. (required)
68
-
69
- ```js
70
- const { Authflow, Titles } = require('prismarine-auth')
71
- const { BedrockPortal, Modules } = require('bedrock-portal')
72
-
73
- const main = async () => {
74
- const auth = new Authflow('example', './', { authTitle: Titles.MinecraftNintendoSwitch, deviceType: 'Nintendo', flow: 'live' })
75
-
76
- const portal = new BedrockPortal(auth, {
77
- ip: 'geyserconnect.net',
78
- port: 19132,
79
- })
80
-
81
- portal.use(Modules.AutoFriendAdd, {
82
- inviteOnAdd: true,
83
- })
84
-
85
- portal.use(Modules.MultipleAccounts, {
86
- accounts: [
87
- new Authflow('account1', './', { authTitle: Titles.MinecraftNintendoSwitch, deviceType: 'Nintendo', flow: 'live' }),
88
- new Authflow('account2', './', { authTitle: Titles.MinecraftNintendoSwitch, deviceType: 'Nintendo', flow: 'live' }),
89
- ],
90
- })
91
-
92
- await portal.start()
93
- }
94
-
95
- main()
96
- ```
97
-
98
-
99
- ### RedirectFromRealm
100
-
101
- > Requires [bedrock-protocol](https://github.com/PrismarineJS/bedrock-protocol) to be installed. `npm install bedrock-protocol`
102
-
103
- Invites players when they join a Realm to the specified server or if they use the chat command. `#.use(Modules.redirectFromRealm, options);`
104
-
105
- Options:
106
- - **clientOptions**: ClientOptions - The client options to use when connecting to the Realm. These are passed directly to a [bedrock-protocol createClient](https://github.com/PrismarineJS/bedrock-protocol/blob/master/docs/API.md#becreateclientoptions--client) function. See the documentation for more information.
107
- - **chatCommand**: object - Options for the chat command
108
- - **enabled**: boolean - Whether sending the command in chat should trigger an invite (default: true)
109
- - **message**: string - The message to send in chat to run the command (default: 'invite')
110
- - **cooldown**: number - The cooldown between being able to send the command in chat (default: 60000ms)
111
-
112
- ```js
113
- const { BedrockPortal, Modules } = require('bedrock-portal');
114
-
115
- const portal = new BedrockPortal(auth, { ... })
116
-
117
- portal.use(Modules.RedirectFromRealm, {
118
- // The client options to use when connecting to the Realm.
119
- clientOptions: {
120
- realms: {
121
- realmInvite: ''
122
- }
123
- },
124
- // Options for the chat command
125
- chatCommand: {
126
- // Whether sending the command in chat should trigger an invite (optional - defaults to true)
127
- enabled: true,
128
- // The message to send in chat to run the command (optional - defaults to 'invite')
129
- message: 'invite',
130
- // The cooldown between being able to send the command in chat (optional - defaults to 60000ms)
131
- cooldown: 60000,
132
- }
133
- }
134
- ```
135
-
136
- ### AutoFriendAdd
137
-
138
- Automatically adds the account's followers as friends and invites them to the game. `#.use(Modules.autoFriendAdd);`
139
-
140
- Options:
141
- - **inviteOnAdd**: boolean - Automatically invites recently added friends to the game (default: false)
142
- - **conditionToMeet**: (player: RawPlayer) => boolean - A function that returns a boolean. If the function returns true, followers will be added as a friend and the friends that don't will be removed (default: () => true)
143
- - **checkInterval**: number - How often to check for friends to add/remove (default: 30000ms)
144
- - **addInterval**: number - How long to wait between adding friends (default: 2000ms)
145
- - **removeInterval**: number - How long to wait between removing friends (default: 2000ms)
146
-
147
- ```js
148
- const { BedrockPortal, Modules } = require('bedrock-portal');
149
-
150
- const portal = new BedrockPortal(auth, { ... })
151
-
152
- portal.use(Modules.AutoFriendAdd);
153
-
154
- // or
155
-
156
- portal.use(Modules.AutoFriendAdd, {
157
- // When a friend is added, automatically invite them to the game
158
- inviteOnAdd: true,
159
- // Only add friends that are online and remove friends that are offline
160
- conditionToMeet: (player) => player.presenceState === 'Online',
161
- // How often to check for friends to add/remove (optional - defaults to 30000ms)
162
- checkInterval: 30000,
163
- // How long to wait between adding friends (optional - defaults to 2000ms)
164
- addInterval: 2000,
165
- // How long to wait between removing friends (optional - defaults to 2000ms)
166
- removeInterval: 2000,
167
- });
168
- ```
169
-
170
- ### InviteOnMessage
171
-
172
- Automatically invites players to the game when they send a message in the chat. `#.use(Modules.inviteOnMessage);`
173
-
174
- Options:
175
- - **command**: string - The command to use to invite players (default: 'invite')
176
- - **checkInterval**: number - How often to check for messages (default: 30000ms)
177
-
178
- ```js
179
- const { BedrockPortal, Modules } = require('bedrock-portal');
180
-
181
- const portal = new BedrockPortal(auth, { ... })
182
-
183
- portal.use(Modules.InviteOnMessage);
184
-
185
- // or
186
-
187
- portal.use(Modules.InviteOnMessage, {
188
- // The command to use to invite players (optional - defaults to 'invite')
189
- command: 'invite',
190
- // How often to check for messages (optional - defaults to 30000ms)
191
- checkInterval: 30000,
192
- });
193
- ```
194
-
195
- ## Modules API
196
-
197
- Creating a module is easy. You can create a module by extending the `Module` class.
198
-
199
- Note: The `stopped` property is set to `true` when the portal is stopped. You can use this to stop the module's loop (if one is present) else the process will not exit.
200
-
201
- ```js
202
- const { Module } = require('bedrock-portal');
203
-
204
- const myModule = class MyModule extends Module {
205
- constructor() {
206
- super('myModule', 'Description of my module');
207
- this.options = {
208
- option1: true,
209
- }
210
- }
211
-
212
- async run(portal) {
213
- // portal - The BedrockPortal instance
214
-
215
- // Do stuff here
216
- }
217
-
218
- async stop() {
219
- super.stop();
220
- // Do stuff when the module is stopped
221
- }
222
- }
223
-
224
- portal.use(myModule, {
225
- option1: false,
226
- });
227
-
228
- ```
229
-
230
- ## Events
231
-
232
- ### portal.on('sessionCreated', (session) => void)
233
- Emitted when a session is created.
234
-
235
- ### portal.on('sessionUpdated', (session) => void)
236
- Emitted when a session is updated.
237
-
238
- ### portal.on('playerJoin', (player) => void)
239
- Emitted when a player joins the session.
240
-
241
- ### portal.on('playerLeave', (player) => void)
242
- Emitted when a player leaves the session.
243
-
244
-
245
- ### portal.on('friendAdded', (player) => void)
246
- Emitted when a player is added as a friend. This event is only emitted when the `autoFriendAdd` module is enabled.
247
-
248
- ### portal.on('friendRemoved', (player) => void)
249
- Emitted when a player is removed as a friend. This event is only emitted when the `autoFriendAdd` module is enabled.
250
-
251
- ### portal.on('messageRecieved', (message) => void)
252
- Emitted when a message is recieved from a player. This event is only emitted when the `inviteOnMessage` module is enabled.
253
-
254
- ## Debugging
255
-
256
- You can enable some debugging output using the `DEBUG` enviroment variable. Through node.js, you can add `process.env.DEBUG = 'bedrock-portal*'` at the top of your code.
257
-
258
- ## License
259
-
260
- [MIT](LICENSE)
1
+ # BedrockPortal
2
+ [![NPM version](https://img.shields.io/npm/v/bedrock-portal.svg)](http://npmjs.com/package/bedrock-portal)
3
+ [![Discord](https://img.shields.io/badge/chat-on%20discord-brightgreen.svg)](https://discord.gg/KTyd9HWuBD)
4
+
5
+ Handles and creates a Minecraft Bedrock game session which will redirect players to the specified server. Join our [Discord](https://discord.com/invite/KTyd9HWuBD) for support.
6
+
7
+ ## Installation
8
+ ```shell
9
+ npm install bedrock-portal
10
+ ```
11
+
12
+ ### Warning
13
+ This package is not meant to be used with your main account. It is meant to be used with alt accounts. If you use this package with your main account, you may be banned from the XSAPI. This package is not affiliated with Mojang or Microsoft.
14
+
15
+ ## Usage
16
+
17
+ ### BedrockPortal(authflow, options)
18
+ **Parameters**
19
+ - authflow - Takes an **Authflow** instance from [prismarine-auth](https://github.com/PrismarineJS/prismarine-auth), you can see the documentation for this [here.](https://github.com/PrismarineJS/prismarine-auth#authflow)
20
+ - options
21
+ - **ip** - The IP address of the server to redirect players to (required)
22
+ - **port** - The port of the server to redirect players to | default: 19132
23
+ - **joinability** - The joinability of the session | default: FriendsOfFriends
24
+ - **world** - The world config to use for the session. Changes the session card which is displayed in the Minecraft client. (optional)
25
+ - **hostName** - string
26
+ - **name** - string
27
+ - **version** - string
28
+ - **memberCount** - number
29
+ - **maxMemberCount** - number
30
+
31
+ ### Create a session redirect to a server
32
+ ```js
33
+ const { BedrockPortal, Joinability } = require('bedrock-portal');
34
+ const { Authflow, Titles } = require('prismarine-auth');
35
+
36
+ const main = async () => {
37
+ const auth = new Authflow('example', './', { authTitle: Titles.MinecraftNintendoSwitch, deviceType: 'Nintendo', flow: 'live' });
38
+
39
+ const portal = new BedrockPortal(auth, {
40
+ // The server IP & port to redirect players to
41
+ ip: 'geyserconnect.net',
42
+ port: 19132,
43
+
44
+ // The joinability of the session. Joinability.FriendsOfFriends, Joinability.FriendsOnly, Joinability.InviteOnly
45
+ joinability: Joinability.FriendsOfFriends
46
+ });
47
+
48
+ await portal.start();
49
+
50
+ // accepts a player's gamertag or xuid
51
+ await portal.invitePlayer('p3')
52
+
53
+ };
54
+
55
+ main();
56
+ ```
57
+
58
+ ## Modules
59
+
60
+ Modules are used to extend the functionality of the BedrockPortal class.
61
+
62
+ ### MultipleAccounts
63
+
64
+ Allows the portal to use multiple accounts to redirect players to the server. `#.use(Modules.MultipleAccounts, options);`
65
+
66
+ Options:
67
+ - **accounts**: Authflow[] - An array of authflows from [prismarine-auth](https://github.com/PrismarineJS/prismarine-auth), these accounts are automatically added to the host session and allows players to add them as a friend to join the game. (required)
68
+
69
+ ```js
70
+ const { Authflow, Titles } = require('prismarine-auth')
71
+ const { BedrockPortal, Modules } = require('bedrock-portal')
72
+
73
+ const main = async () => {
74
+ const auth = new Authflow('example', './', { authTitle: Titles.MinecraftNintendoSwitch, deviceType: 'Nintendo', flow: 'live' })
75
+
76
+ const portal = new BedrockPortal(auth, {
77
+ ip: 'geyserconnect.net',
78
+ port: 19132,
79
+ })
80
+
81
+ portal.use(Modules.AutoFriendAdd, {
82
+ inviteOnAdd: true,
83
+ })
84
+
85
+ portal.use(Modules.MultipleAccounts, {
86
+ accounts: [
87
+ new Authflow('account1', './', { authTitle: Titles.MinecraftNintendoSwitch, deviceType: 'Nintendo', flow: 'live' }),
88
+ new Authflow('account2', './', { authTitle: Titles.MinecraftNintendoSwitch, deviceType: 'Nintendo', flow: 'live' }),
89
+ ],
90
+ })
91
+
92
+ await portal.start()
93
+ }
94
+
95
+ main()
96
+ ```
97
+
98
+
99
+ ### RedirectFromRealm
100
+
101
+ > Requires [bedrock-protocol](https://github.com/PrismarineJS/bedrock-protocol) to be installed. `npm install bedrock-protocol`
102
+
103
+ Invites players when they join a Realm to the specified server or if they use the chat command. `#.use(Modules.redirectFromRealm, options);`
104
+
105
+ Options:
106
+ - **clientOptions**: ClientOptions - The client options to use when connecting to the Realm. These are passed directly to a [bedrock-protocol createClient](https://github.com/PrismarineJS/bedrock-protocol/blob/master/docs/API.md#becreateclientoptions--client) function. See the documentation for more information.
107
+ - **chatCommand**: object - Options for the chat command
108
+ - **enabled**: boolean - Whether sending the command in chat should trigger an invite (default: true)
109
+ - **message**: string - The message to send in chat to run the command (default: 'invite')
110
+ - **cooldown**: number - The cooldown between being able to send the command in chat (default: 60000ms)
111
+
112
+ ```js
113
+ const { BedrockPortal, Modules } = require('bedrock-portal');
114
+
115
+ const portal = new BedrockPortal(auth, { ... })
116
+
117
+ portal.use(Modules.RedirectFromRealm, {
118
+ // The client options to use when connecting to the Realm.
119
+ clientOptions: {
120
+ realms: {
121
+ realmInvite: ''
122
+ }
123
+ },
124
+ // Options for the chat command
125
+ chatCommand: {
126
+ // Whether sending the command in chat should trigger an invite (optional - defaults to true)
127
+ enabled: true,
128
+ // The message to send in chat to run the command (optional - defaults to 'invite')
129
+ message: 'invite',
130
+ // The cooldown between being able to send the command in chat (optional - defaults to 60000ms)
131
+ cooldown: 60000,
132
+ }
133
+ }
134
+ ```
135
+
136
+ ### AutoFriendAdd
137
+
138
+ Automatically adds the account's followers as friends and invites them to the game. `#.use(Modules.autoFriendAdd);`
139
+
140
+ Options:
141
+ - **inviteOnAdd**: boolean - Automatically invites recently added friends to the game (default: false)
142
+ - **conditionToMeet**: (player: RawPlayer) => boolean - A function that returns a boolean. If the function returns true, followers will be added as a friend and the friends that don't will be removed (default: () => true)
143
+ - **checkInterval**: number - How often to check for friends to add/remove (default: 30000ms)
144
+ - **addInterval**: number - How long to wait between adding friends (default: 2000ms)
145
+ - **removeInterval**: number - How long to wait between removing friends (default: 2000ms)
146
+
147
+ ```js
148
+ const { BedrockPortal, Modules } = require('bedrock-portal');
149
+
150
+ const portal = new BedrockPortal(auth, { ... })
151
+
152
+ portal.use(Modules.AutoFriendAdd);
153
+
154
+ // or
155
+
156
+ portal.use(Modules.AutoFriendAdd, {
157
+ // When a friend is added, automatically invite them to the game
158
+ inviteOnAdd: true,
159
+ // Only add friends that are online and remove friends that are offline
160
+ conditionToMeet: (player) => player.presenceState === 'Online',
161
+ // How often to check for friends to add/remove (optional - defaults to 30000ms)
162
+ checkInterval: 30000,
163
+ // How long to wait between adding friends (optional - defaults to 2000ms)
164
+ addInterval: 2000,
165
+ // How long to wait between removing friends (optional - defaults to 2000ms)
166
+ removeInterval: 2000,
167
+ });
168
+ ```
169
+
170
+ ### InviteOnMessage
171
+
172
+ Automatically invites players to the game when they send a message in the chat. `#.use(Modules.inviteOnMessage);`
173
+
174
+ Options:
175
+ - **command**: string - The command to use to invite players (default: 'invite')
176
+ - **checkInterval**: number - How often to check for messages (default: 30000ms)
177
+
178
+ ```js
179
+ const { BedrockPortal, Modules } = require('bedrock-portal');
180
+
181
+ const portal = new BedrockPortal(auth, { ... })
182
+
183
+ portal.use(Modules.InviteOnMessage);
184
+
185
+ // or
186
+
187
+ portal.use(Modules.InviteOnMessage, {
188
+ // The command to use to invite players (optional - defaults to 'invite')
189
+ command: 'invite',
190
+ // How often to check for messages (optional - defaults to 30000ms)
191
+ checkInterval: 30000,
192
+ });
193
+ ```
194
+
195
+ ## Modules API
196
+
197
+ Creating a module is easy. You can create a module by extending the `Module` class.
198
+
199
+ Note: The `stopped` property is set to `true` when the portal is stopped. You can use this to stop the module's loop (if one is present) else the process will not exit.
200
+
201
+ ```js
202
+ const { Module } = require('bedrock-portal');
203
+
204
+ const myModule = class MyModule extends Module {
205
+ constructor() {
206
+ super('myModule', 'Description of my module');
207
+ this.options = {
208
+ option1: true,
209
+ }
210
+ }
211
+
212
+ async run(portal) {
213
+ // portal - The BedrockPortal instance
214
+
215
+ // Do stuff here
216
+ }
217
+
218
+ async stop() {
219
+ super.stop();
220
+ // Do stuff when the module is stopped
221
+ }
222
+ }
223
+
224
+ portal.use(myModule, {
225
+ option1: false,
226
+ });
227
+
228
+ ```
229
+
230
+ ## Events
231
+
232
+ ### portal.on('sessionCreated', (session) => void)
233
+ Emitted when a session is created.
234
+
235
+ ### portal.on('sessionUpdated', (session) => void)
236
+ Emitted when a session is updated.
237
+
238
+ ### portal.on('playerJoin', (player) => void)
239
+ Emitted when a player joins the session.
240
+
241
+ ### portal.on('playerLeave', (player) => void)
242
+ Emitted when a player leaves the session.
243
+
244
+
245
+ ### portal.on('friendAdded', (player) => void)
246
+ Emitted when a player is added as a friend. This event is only emitted when the `autoFriendAdd` module is enabled.
247
+
248
+ ### portal.on('friendRemoved', (player) => void)
249
+ Emitted when a player is removed as a friend. This event is only emitted when the `autoFriendAdd` module is enabled.
250
+
251
+ ### portal.on('messageRecieved', (message) => void)
252
+ Emitted when a message is recieved from a player. This event is only emitted when the `inviteOnMessage` module is enabled.
253
+
254
+ ## Debugging
255
+
256
+ You can enable some debugging output using the `DEBUG` enviroment variable. Through node.js, you can add `process.env.DEBUG = 'bedrock-portal*'` at the top of your code.
257
+
258
+ ## License
259
+
260
+ [MIT](LICENSE)
@@ -1,13 +1,4 @@
1
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
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -18,42 +9,41 @@ const xbox_rta_1 = require("xbox-rta");
18
9
  const rest_1 = __importDefault(require("../rest"));
19
10
  const debug = (0, debug_1.default)('bedrock-portal');
20
11
  class Host {
12
+ portal;
13
+ authflow;
14
+ rest;
15
+ rta = null;
16
+ profile = null;
17
+ connectionId = null;
18
+ subscriptionId = (0, uuid_1.v4)();
21
19
  constructor(portal, authflow) {
22
- this.rta = null;
23
- this.profile = null;
24
- this.connectionId = null;
25
- this.subscriptionId = (0, uuid_1.v4)();
26
20
  this.portal = portal;
27
21
  this.authflow = authflow;
28
22
  this.rest = new rest_1.default(this.authflow);
29
23
  }
30
- connect() {
31
- return __awaiter(this, void 0, void 0, function* () {
32
- const auth = yield this.authflow.getXboxToken();
33
- this.profile = yield this.rest.getProfile(auth.userXUID);
34
- this.rta = new xbox_rta_1.XboxRTA(this.authflow);
35
- yield this.rta.connect();
36
- const subResponse = yield this.rta.subscribe('https://sessiondirectory.xboxlive.com/connections/');
37
- this.connectionId = subResponse.data.ConnectionId;
38
- this.rta.on('subscribe', (event) => this.onSubscribe(event));
39
- });
24
+ async connect() {
25
+ const auth = await this.authflow.getXboxToken();
26
+ this.profile = await this.rest.getProfile(auth.userXUID);
27
+ this.rta = new xbox_rta_1.XboxRTA(this.authflow);
28
+ await this.rta.connect();
29
+ const subResponse = await this.rta.subscribe('https://sessiondirectory.xboxlive.com/connections/');
30
+ this.connectionId = subResponse.data.ConnectionId;
31
+ this.rta.on('subscribe', (event) => this.onSubscribe(event));
40
32
  }
41
- onSubscribe(event) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- debug('Received RTA subscribe event', event);
44
- const connectionId = event.data.ConnectionId;
45
- if (connectionId && typeof connectionId === 'string') {
46
- try {
47
- this.connectionId = connectionId;
48
- yield this.rest.updateConnection(this.portal.session.name, connectionId);
49
- yield this.rest.setActivity(this.portal.session.name);
50
- }
51
- catch (e) {
52
- debug('Failed to update connection, session may have been abandoned', e);
53
- yield this.portal.end(true);
54
- }
33
+ async onSubscribe(event) {
34
+ debug('Received RTA subscribe event', event);
35
+ const connectionId = event.data.ConnectionId;
36
+ if (connectionId && typeof connectionId === 'string') {
37
+ try {
38
+ this.connectionId = connectionId;
39
+ await this.rest.updateConnection(this.portal.session.name, connectionId);
40
+ await this.rest.setActivity(this.portal.session.name);
41
+ }
42
+ catch (e) {
43
+ debug('Failed to update connection, session may have been abandoned', e);
44
+ await this.portal.end(true);
55
45
  }
56
- });
46
+ }
57
47
  }
58
48
  }
59
49
  exports.default = Host;