bedrock-portal 0.5.1 → 0.6.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.
- package/README.md +75 -244
- package/dist/classes/Host.d.ts +17 -0
- package/dist/classes/Host.js +59 -0
- package/dist/classes/Module.d.ts +13 -0
- package/dist/classes/Module.js +38 -0
- package/dist/classes/Player.d.ts +15 -0
- package/dist/classes/Player.js +22 -0
- package/dist/common/constants.d.ts +38 -0
- package/dist/common/constants.js +42 -0
- package/dist/handlers/Event.d.ts +4 -0
- package/dist/handlers/Event.js +45 -0
- package/dist/index.d.ts +149 -0
- package/dist/index.js +245 -0
- package/dist/modules/autoFriendAdd.d.ts +9 -0
- package/dist/modules/autoFriendAdd.js +93 -0
- package/dist/modules/inviteOnMessage.d.ts +11 -0
- package/dist/modules/inviteOnMessage.js +77 -0
- package/dist/modules/multipleAccounts.d.ts +13 -0
- package/dist/modules/multipleAccounts.js +75 -0
- package/dist/modules/redirectFromRealm.d.ts +12 -0
- package/dist/modules/redirectFromRealm.js +104 -0
- package/dist/rest.d.ts +46 -0
- package/dist/rest.js +187 -0
- package/dist/types/peoplehub.d.ts +124 -0
- package/dist/types/peoplehub.js +27 -0
- package/dist/types/sessiondirectory.d.ts +166 -0
- package/dist/types/sessiondirectory.js +2 -0
- package/dist/types/xblmessaging.d.ts +64 -0
- package/dist/types/xblmessaging.js +2 -0
- package/package.json +14 -4
- package/.eslintrc.json +0 -46
- package/.github/codeql-config.yml +0 -4
- package/.github/workflows/ci.yml +0 -30
- package/.github/workflows/codeql.yml +0 -76
- package/.github/workflows/publish.yml +0 -32
- package/examples/portal.js +0 -77
- package/examples/realm.js +0 -58
- package/index.d.ts +0 -498
- package/index.js +0 -14
- package/src/classes/Module.js +0 -20
- package/src/classes/Player.js +0 -52
- package/src/common/constants.js +0 -35
- package/src/common/util.js +0 -16
- package/src/index.js +0 -310
- package/src/modules/autoFriendAdd.js +0 -84
- package/src/modules/inviteOnMessage.js +0 -68
- package/src/modules/redirectFromRealm.js +0 -81
- package/src/rest.js +0 -161
package/README.md
CHANGED
|
@@ -19,15 +19,14 @@ This package is not meant to be used with your main account. It is meant to be u
|
|
|
19
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
20
|
- options
|
|
21
21
|
- **ip** - The IP address of the server to redirect players to (required)
|
|
22
|
-
- **port** - The port of the server to redirect players to
|
|
23
|
-
- **
|
|
24
|
-
- **
|
|
25
|
-
|
|
26
|
-
- **
|
|
27
|
-
- **
|
|
28
|
-
- **
|
|
29
|
-
- **
|
|
30
|
-
- **maxMemberCount** - number (default: 10)
|
|
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
|
|
31
30
|
|
|
32
31
|
### Create a session redirect to a server
|
|
33
32
|
```js
|
|
@@ -38,9 +37,12 @@ const main = async () => {
|
|
|
38
37
|
const auth = new Authflow('example', './', { authTitle: Titles.MinecraftNintendoSwitch, deviceType: 'Nintendo', flow: 'live' });
|
|
39
38
|
|
|
40
39
|
const portal = new BedrockPortal(auth, {
|
|
41
|
-
|
|
40
|
+
// The server IP & port to redirect players to
|
|
41
|
+
ip: 'geyserconnect.net',
|
|
42
42
|
port: 19132,
|
|
43
|
-
|
|
43
|
+
|
|
44
|
+
// The joinability of the session. Joinability.FriendsOfFriends, Joinability.FriendsOnly, Joinability.InviteOnly
|
|
45
|
+
joinability: Joinability.FriendsOfFriends
|
|
44
46
|
});
|
|
45
47
|
|
|
46
48
|
await portal.start();
|
|
@@ -57,7 +59,44 @@ main();
|
|
|
57
59
|
|
|
58
60
|
Modules are used to extend the functionality of the BedrockPortal class.
|
|
59
61
|
|
|
60
|
-
###
|
|
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
|
|
61
100
|
|
|
62
101
|
> Requires [bedrock-protocol](https://github.com/PrismarineJS/bedrock-protocol) to be installed. `npm install bedrock-protocol`
|
|
63
102
|
|
|
@@ -75,7 +114,7 @@ const { BedrockPortal, Modules } = require('bedrock-portal');
|
|
|
75
114
|
|
|
76
115
|
const portal = new BedrockPortal(auth, { ... })
|
|
77
116
|
|
|
78
|
-
portal.use(Modules.
|
|
117
|
+
portal.use(Modules.RedirectFromRealm, {
|
|
79
118
|
// The client options to use when connecting to the Realm.
|
|
80
119
|
clientOptions: {
|
|
81
120
|
realms: {
|
|
@@ -94,7 +133,7 @@ portal.use(Modules.redirectFromRealm, {
|
|
|
94
133
|
}
|
|
95
134
|
```
|
|
96
135
|
|
|
97
|
-
###
|
|
136
|
+
### AutoFriendAdd
|
|
98
137
|
|
|
99
138
|
Automatically adds the account's followers as friends and invites them to the game. `#.use(Modules.autoFriendAdd);`
|
|
100
139
|
|
|
@@ -110,11 +149,11 @@ const { BedrockPortal, Modules } = require('bedrock-portal');
|
|
|
110
149
|
|
|
111
150
|
const portal = new BedrockPortal(auth, { ... })
|
|
112
151
|
|
|
113
|
-
portal.use(Modules.
|
|
152
|
+
portal.use(Modules.AutoFriendAdd);
|
|
114
153
|
|
|
115
154
|
// or
|
|
116
155
|
|
|
117
|
-
portal.use(Modules.
|
|
156
|
+
portal.use(Modules.AutoFriendAdd, {
|
|
118
157
|
// When a friend is added, automatically invite them to the game
|
|
119
158
|
inviteOnAdd: true,
|
|
120
159
|
// Only add friends that are online and remove friends that are offline
|
|
@@ -128,7 +167,7 @@ portal.use(Modules.autoFriendAdd, {
|
|
|
128
167
|
});
|
|
129
168
|
```
|
|
130
169
|
|
|
131
|
-
###
|
|
170
|
+
### InviteOnMessage
|
|
132
171
|
|
|
133
172
|
Automatically invites players to the game when they send a message in the chat. `#.use(Modules.inviteOnMessage);`
|
|
134
173
|
|
|
@@ -141,11 +180,11 @@ const { BedrockPortal, Modules } = require('bedrock-portal');
|
|
|
141
180
|
|
|
142
181
|
const portal = new BedrockPortal(auth, { ... })
|
|
143
182
|
|
|
144
|
-
portal.use(Modules.
|
|
183
|
+
portal.use(Modules.InviteOnMessage);
|
|
145
184
|
|
|
146
185
|
// or
|
|
147
186
|
|
|
148
|
-
portal.use(Modules.
|
|
187
|
+
portal.use(Modules.InviteOnMessage, {
|
|
149
188
|
// The command to use to invite players (optional - defaults to 'invite')
|
|
150
189
|
command: 'invite',
|
|
151
190
|
// How often to check for messages (optional - defaults to 30000ms)
|
|
@@ -170,256 +209,48 @@ const myModule = class MyModule extends Module {
|
|
|
170
209
|
}
|
|
171
210
|
}
|
|
172
211
|
|
|
173
|
-
async run(portal
|
|
212
|
+
async run(portal) {
|
|
174
213
|
// portal - The BedrockPortal instance
|
|
175
|
-
// rest - The REST API instance
|
|
176
|
-
// rta - The RTA API instance
|
|
177
214
|
|
|
178
215
|
// Do stuff here
|
|
179
216
|
}
|
|
217
|
+
|
|
218
|
+
async stop() {
|
|
219
|
+
super.stop();
|
|
220
|
+
// Do stuff when the module is stopped
|
|
221
|
+
}
|
|
180
222
|
}
|
|
181
223
|
|
|
182
|
-
portal.use(myModule
|
|
224
|
+
portal.use(myModule, {
|
|
225
|
+
option1: false,
|
|
226
|
+
});
|
|
227
|
+
|
|
183
228
|
```
|
|
184
229
|
|
|
185
230
|
## Events
|
|
186
231
|
|
|
187
|
-
### portal.on('sessionCreated', (session) =>
|
|
232
|
+
### portal.on('sessionCreated', (session) => void)
|
|
188
233
|
Emitted when a session is created.
|
|
189
234
|
|
|
190
|
-
|
|
191
|
-
- session - [Session](#session) object
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
### portal.on('sessionUpdated', (session) => {})
|
|
235
|
+
### portal.on('sessionUpdated', (session) => void)
|
|
195
236
|
Emitted when a session is updated.
|
|
196
237
|
|
|
197
|
-
|
|
198
|
-
- session - [Session](#session) object
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
### portal.on('playerJoin', (player) => {})
|
|
238
|
+
### portal.on('playerJoin', (player) => void)
|
|
202
239
|
Emitted when a player joins the session.
|
|
203
240
|
|
|
204
|
-
|
|
205
|
-
- player - [Player](#player) object
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
### portal.on('playerLeave', (player) => {})
|
|
241
|
+
### portal.on('playerLeave', (player) => void)
|
|
209
242
|
Emitted when a player leaves the session.
|
|
210
243
|
|
|
211
|
-
**Parameters**
|
|
212
|
-
- player - [Player](#player) object
|
|
213
|
-
|
|
214
244
|
|
|
215
|
-
### portal.on('friendAdded', (player) =>
|
|
245
|
+
### portal.on('friendAdded', (player) => void)
|
|
216
246
|
Emitted when a player is added as a friend. This event is only emitted when the `autoFriendAdd` module is enabled.
|
|
217
247
|
|
|
218
|
-
|
|
219
|
-
- player - [Player](#player) object
|
|
220
|
-
|
|
221
|
-
### portal.on('friendRemoved', (player) => {})
|
|
248
|
+
### portal.on('friendRemoved', (player) => void)
|
|
222
249
|
Emitted when a player is removed as a friend. This event is only emitted when the `autoFriendAdd` module is enabled.
|
|
223
250
|
|
|
224
|
-
|
|
225
|
-
- player - [Player](#player) object
|
|
226
|
-
|
|
227
|
-
### portal.on('messageRecieved', (message) => {})
|
|
251
|
+
### portal.on('messageRecieved', (message) => void)
|
|
228
252
|
Emitted when a message is recieved from a player. This event is only emitted when the `inviteOnMessage` module is enabled.
|
|
229
253
|
|
|
230
|
-
## Objects
|
|
231
|
-
|
|
232
|
-
### Player
|
|
233
|
-
|
|
234
|
-
```ts
|
|
235
|
-
{
|
|
236
|
-
profile?: {
|
|
237
|
-
xuid: string,
|
|
238
|
-
avatar: string,
|
|
239
|
-
gamerscore: string,
|
|
240
|
-
gamertag: string,
|
|
241
|
-
tier: string,
|
|
242
|
-
reputation: string,
|
|
243
|
-
colour: {
|
|
244
|
-
primaryColour: string,
|
|
245
|
-
secondaryColour: string,
|
|
246
|
-
tertiaryColour: string
|
|
247
|
-
},
|
|
248
|
-
realname: string,
|
|
249
|
-
bio: string,
|
|
250
|
-
location: string,
|
|
251
|
-
modernGamertag: string,
|
|
252
|
-
modernGamertagSuffix: string,
|
|
253
|
-
uniqueModernGamertag: string,
|
|
254
|
-
realnameOverride: string,
|
|
255
|
-
tenureLevel: string,
|
|
256
|
-
watermarks: string,
|
|
257
|
-
isQuarantined: boolean,
|
|
258
|
-
linkedAccounts: []
|
|
259
|
-
}
|
|
260
|
-
session?: {
|
|
261
|
-
titleId: string
|
|
262
|
-
joinTime: string
|
|
263
|
-
index: number
|
|
264
|
-
connectionId: string
|
|
265
|
-
subscriptionId: string
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
### Session
|
|
271
|
-
|
|
272
|
-
```ts
|
|
273
|
-
{
|
|
274
|
-
membersInfo: {
|
|
275
|
-
first: number,
|
|
276
|
-
next: number,
|
|
277
|
-
count: number,
|
|
278
|
-
accepted: number,
|
|
279
|
-
active: number
|
|
280
|
-
},
|
|
281
|
-
constants: {
|
|
282
|
-
system: {
|
|
283
|
-
readyRemovalTimeout: number,
|
|
284
|
-
reservedRemovalTimeout: number,
|
|
285
|
-
sessionEmptyTimeout: number,
|
|
286
|
-
inactiveRemovalTimeout: number,
|
|
287
|
-
version: number,
|
|
288
|
-
maxMembersCount: number,
|
|
289
|
-
visibility: string,
|
|
290
|
-
capabilities: {
|
|
291
|
-
connectivity: boolean,
|
|
292
|
-
connectionRequiredForActiveMembers: boolean,
|
|
293
|
-
gameplay: boolean,
|
|
294
|
-
crossPlay: boolean,
|
|
295
|
-
userAuthorizationStyle: boolean
|
|
296
|
-
},
|
|
297
|
-
inviteProtocol: string,
|
|
298
|
-
memberInitialization: {
|
|
299
|
-
membersNeededToStart: number,
|
|
300
|
-
}
|
|
301
|
-
},
|
|
302
|
-
custom: {}
|
|
303
|
-
},
|
|
304
|
-
properties: {
|
|
305
|
-
system: {
|
|
306
|
-
joinRestriction: 'followed' | 'local',
|
|
307
|
-
readRestriction: string,
|
|
308
|
-
turn: []
|
|
309
|
-
},
|
|
310
|
-
custom: {
|
|
311
|
-
Joinability: string,
|
|
312
|
-
hostName: string,
|
|
313
|
-
ownerId: string,
|
|
314
|
-
rakNetGUID: string,
|
|
315
|
-
version: string,
|
|
316
|
-
worldName: string,
|
|
317
|
-
worldType: string,
|
|
318
|
-
protocol: number,
|
|
319
|
-
MemberCount: number,
|
|
320
|
-
MaxMemberCount: number,
|
|
321
|
-
BroadcastSetting: number,
|
|
322
|
-
UsesWebSocketsWebRTCSignaling: boolean,
|
|
323
|
-
UsesMPSDWebRTCSignaling: boolean,
|
|
324
|
-
netherNetEnabled: boolean,
|
|
325
|
-
OnlineCrossPlatformGame: boolean,
|
|
326
|
-
CrossPlayDisabled: boolean,
|
|
327
|
-
TitleId: number,
|
|
328
|
-
SupportedConnections: SessionConnection[],
|
|
329
|
-
levelId: string,
|
|
330
|
-
LanGame: boolean
|
|
331
|
-
}
|
|
332
|
-
},
|
|
333
|
-
servers: {},
|
|
334
|
-
members: {
|
|
335
|
-
[index: number]: SessionMember
|
|
336
|
-
}
|
|
337
|
-
correlationId: string,
|
|
338
|
-
contractVersion: number,
|
|
339
|
-
branch: string,
|
|
340
|
-
changeNumber: number,
|
|
341
|
-
startTime: string
|
|
342
|
-
}
|
|
343
|
-
```
|
|
344
|
-
|
|
345
|
-
### RawPlayer
|
|
346
|
-
|
|
347
|
-
```ts
|
|
348
|
-
{
|
|
349
|
-
xuid: string;
|
|
350
|
-
isFavorite: boolean;
|
|
351
|
-
isFollowingCaller: boolean;
|
|
352
|
-
isFollowedByCaller: boolean;
|
|
353
|
-
isIdentityShared: boolean;
|
|
354
|
-
addedDateTimeUtc: string;
|
|
355
|
-
displayName: string;
|
|
356
|
-
realName: string;
|
|
357
|
-
displayPicRaw: string;
|
|
358
|
-
showUserAsAvatar: string;
|
|
359
|
-
gamertag: string;
|
|
360
|
-
gamerScore: string;
|
|
361
|
-
modernGamertag: string;
|
|
362
|
-
modernGamertagSuffix: string;
|
|
363
|
-
uniqueModernGamertag: string;
|
|
364
|
-
xboxOneRep: string;
|
|
365
|
-
presenceState: string;
|
|
366
|
-
presenceText: string;
|
|
367
|
-
presenceDevices: null | any[];
|
|
368
|
-
isBroadcasting: boolean;
|
|
369
|
-
isCloaked: null | boolean;
|
|
370
|
-
isQuarantined: boolean;
|
|
371
|
-
isXbox360Gamerpic: boolean;
|
|
372
|
-
lastSeenDateTimeUtc: string;
|
|
373
|
-
suggestion: null;
|
|
374
|
-
recommendation: null;
|
|
375
|
-
search: null;
|
|
376
|
-
titleHistory: null;
|
|
377
|
-
multiplayerSummary: null;
|
|
378
|
-
recentPlayer: null;
|
|
379
|
-
follower: {
|
|
380
|
-
text: string;
|
|
381
|
-
followedDateTime: string;
|
|
382
|
-
};
|
|
383
|
-
preferredColor: {
|
|
384
|
-
primaryColor: string;
|
|
385
|
-
secondaryColor: string;
|
|
386
|
-
tertiaryColor: string;
|
|
387
|
-
};
|
|
388
|
-
presenceDetails: null;
|
|
389
|
-
titlePresence: null;
|
|
390
|
-
titleSummaries: null;
|
|
391
|
-
presenceTitleIds: null;
|
|
392
|
-
detail: {
|
|
393
|
-
accountTier: string;
|
|
394
|
-
bio: string;
|
|
395
|
-
isVerified: boolean;
|
|
396
|
-
location: string;
|
|
397
|
-
tenure: string;
|
|
398
|
-
watermarks: any[];
|
|
399
|
-
blocked: boolean;
|
|
400
|
-
mute: boolean;
|
|
401
|
-
followerCount: number;
|
|
402
|
-
followingCount: number;
|
|
403
|
-
hasGamePass: boolean;
|
|
404
|
-
};
|
|
405
|
-
communityManagerTitles: null;
|
|
406
|
-
socialManager: null;
|
|
407
|
-
broadcast: null;
|
|
408
|
-
avatar: null;
|
|
409
|
-
linkedAccounts: {
|
|
410
|
-
networkName: string;
|
|
411
|
-
displayName: string;
|
|
412
|
-
showOnProfile: boolean;
|
|
413
|
-
isFamilyFriendly: boolean;
|
|
414
|
-
deeplink: null;
|
|
415
|
-
}[];
|
|
416
|
-
colorTheme: string;
|
|
417
|
-
preferredFlag: string;
|
|
418
|
-
preferredPlatforms: string[];
|
|
419
|
-
}
|
|
420
|
-
```
|
|
421
|
-
|
|
422
|
-
|
|
423
254
|
## Debugging
|
|
424
255
|
|
|
425
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.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Authflow } from 'prismarine-auth';
|
|
2
|
+
import { XboxRTA } from 'xbox-rta';
|
|
3
|
+
import { BedrockPortal } from '..';
|
|
4
|
+
import { Person } from '../types/peoplehub';
|
|
5
|
+
import Rest from '../rest';
|
|
6
|
+
export default class Host {
|
|
7
|
+
portal: BedrockPortal;
|
|
8
|
+
authflow: Authflow;
|
|
9
|
+
rest: Rest;
|
|
10
|
+
rta: XboxRTA | null;
|
|
11
|
+
profile: Person | null;
|
|
12
|
+
connectionId: string | null;
|
|
13
|
+
subscriptionId: string;
|
|
14
|
+
constructor(portal: BedrockPortal, authflow: Authflow);
|
|
15
|
+
connect(): Promise<void>;
|
|
16
|
+
private onSubscribe;
|
|
17
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const debug_1 = __importDefault(require("debug"));
|
|
16
|
+
const uuid_1 = require("uuid");
|
|
17
|
+
const xbox_rta_1 = require("xbox-rta");
|
|
18
|
+
const rest_1 = __importDefault(require("../rest"));
|
|
19
|
+
const debug = (0, debug_1.default)('bedrock-portal');
|
|
20
|
+
class Host {
|
|
21
|
+
constructor(portal, authflow) {
|
|
22
|
+
this.rta = null;
|
|
23
|
+
this.profile = null;
|
|
24
|
+
this.connectionId = null;
|
|
25
|
+
this.subscriptionId = (0, uuid_1.v4)();
|
|
26
|
+
this.portal = portal;
|
|
27
|
+
this.authflow = authflow;
|
|
28
|
+
this.rest = new rest_1.default(this.authflow);
|
|
29
|
+
}
|
|
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
|
+
});
|
|
40
|
+
}
|
|
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
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.default = Host;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import debugFn from 'debug';
|
|
2
|
+
import { BedrockPortal } from '..';
|
|
3
|
+
export default class Module {
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
stopped: boolean;
|
|
7
|
+
options: any;
|
|
8
|
+
debug: debugFn.Debugger;
|
|
9
|
+
constructor(name: string, description: string);
|
|
10
|
+
applyOptions(options: any): void;
|
|
11
|
+
stop(): Promise<void>;
|
|
12
|
+
run(_portal: BedrockPortal): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const debug_1 = __importDefault(require("debug"));
|
|
16
|
+
class Module {
|
|
17
|
+
constructor(name, description) {
|
|
18
|
+
this.name = name;
|
|
19
|
+
this.description = description;
|
|
20
|
+
this.stopped = false;
|
|
21
|
+
this.options = {};
|
|
22
|
+
this.debug = (0, debug_1.default)(`bedrock-portal:${this.name}`);
|
|
23
|
+
}
|
|
24
|
+
applyOptions(options) {
|
|
25
|
+
this.options = Object.assign(Object.assign({}, this.options), options);
|
|
26
|
+
}
|
|
27
|
+
stop() {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
this.stopped = true;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
run(_portal) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
throw Error('Module.run() must be implemented');
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.default = Module;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Person } from '../types/peoplehub';
|
|
2
|
+
import type { SessionMember } from '../types/sessiondirectory';
|
|
3
|
+
type PlayerSession = {
|
|
4
|
+
titleId: string;
|
|
5
|
+
joinTime: string;
|
|
6
|
+
index: number;
|
|
7
|
+
connectionId: string;
|
|
8
|
+
subscriptionId: string;
|
|
9
|
+
};
|
|
10
|
+
export default class Player {
|
|
11
|
+
profile: Partial<Person>;
|
|
12
|
+
session: Partial<PlayerSession>;
|
|
13
|
+
constructor(profileData: Person | null, sessionData: SessionMember | null);
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class Player {
|
|
4
|
+
constructor(profileData, sessionData) {
|
|
5
|
+
var _a;
|
|
6
|
+
this.profile = {};
|
|
7
|
+
this.session = {};
|
|
8
|
+
if (profileData) {
|
|
9
|
+
this.profile = profileData;
|
|
10
|
+
}
|
|
11
|
+
if (sessionData) {
|
|
12
|
+
this.session = {
|
|
13
|
+
titleId: sessionData.activeTitleId,
|
|
14
|
+
joinTime: sessionData.joinTime,
|
|
15
|
+
index: sessionData.constants.system.index,
|
|
16
|
+
connectionId: sessionData.properties.system.connection,
|
|
17
|
+
subscriptionId: (_a = sessionData.properties.system.subscription) === null || _a === void 0 ? void 0 : _a.id,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.default = Player;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export declare const SessionConfig: {
|
|
2
|
+
MinecraftTitleID: string;
|
|
3
|
+
MinecraftSCID: string;
|
|
4
|
+
MinecraftTemplateName: string;
|
|
5
|
+
MiencraftProtocolVersion: number;
|
|
6
|
+
};
|
|
7
|
+
export declare enum Joinability {
|
|
8
|
+
/**
|
|
9
|
+
* Only players who have been invited can join the session.
|
|
10
|
+
* */
|
|
11
|
+
InviteOnly = "invite_only",
|
|
12
|
+
/**
|
|
13
|
+
* Friends of the authenticating account can join/view the session without an invite.
|
|
14
|
+
* */
|
|
15
|
+
FriendsOnly = "friends_only",
|
|
16
|
+
/**
|
|
17
|
+
* Anyone that's a friend or friend of a friend can join/view the session without an invite.
|
|
18
|
+
* @default
|
|
19
|
+
* */
|
|
20
|
+
FriendsOfFriends = "friends_of_friends"
|
|
21
|
+
}
|
|
22
|
+
export declare const JoinabilityConfig: {
|
|
23
|
+
invite_only: {
|
|
24
|
+
joinability: string;
|
|
25
|
+
joinRestriction: string;
|
|
26
|
+
broadcastSetting: number;
|
|
27
|
+
};
|
|
28
|
+
friends_only: {
|
|
29
|
+
joinability: string;
|
|
30
|
+
joinRestriction: string;
|
|
31
|
+
broadcastSetting: number;
|
|
32
|
+
};
|
|
33
|
+
friends_of_friends: {
|
|
34
|
+
joinability: string;
|
|
35
|
+
joinRestriction: string;
|
|
36
|
+
broadcastSetting: number;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JoinabilityConfig = exports.Joinability = exports.SessionConfig = void 0;
|
|
4
|
+
exports.SessionConfig = {
|
|
5
|
+
MinecraftTitleID: '896928775',
|
|
6
|
+
MinecraftSCID: '4fc10100-5f7a-4470-899b-280835760c07',
|
|
7
|
+
MinecraftTemplateName: 'MinecraftLobby',
|
|
8
|
+
MiencraftProtocolVersion: 649,
|
|
9
|
+
};
|
|
10
|
+
var Joinability;
|
|
11
|
+
(function (Joinability) {
|
|
12
|
+
/**
|
|
13
|
+
* Only players who have been invited can join the session.
|
|
14
|
+
* */
|
|
15
|
+
Joinability["InviteOnly"] = "invite_only";
|
|
16
|
+
/**
|
|
17
|
+
* Friends of the authenticating account can join/view the session without an invite.
|
|
18
|
+
* */
|
|
19
|
+
Joinability["FriendsOnly"] = "friends_only";
|
|
20
|
+
/**
|
|
21
|
+
* Anyone that's a friend or friend of a friend can join/view the session without an invite.
|
|
22
|
+
* @default
|
|
23
|
+
* */
|
|
24
|
+
Joinability["FriendsOfFriends"] = "friends_of_friends";
|
|
25
|
+
})(Joinability || (exports.Joinability = Joinability = {}));
|
|
26
|
+
exports.JoinabilityConfig = {
|
|
27
|
+
[Joinability.InviteOnly]: {
|
|
28
|
+
joinability: 'invite_only',
|
|
29
|
+
joinRestriction: 'local',
|
|
30
|
+
broadcastSetting: 1,
|
|
31
|
+
},
|
|
32
|
+
[Joinability.FriendsOnly]: {
|
|
33
|
+
joinability: 'joinable_by_friends',
|
|
34
|
+
joinRestriction: 'followed',
|
|
35
|
+
broadcastSetting: 2,
|
|
36
|
+
},
|
|
37
|
+
[Joinability.FriendsOfFriends]: {
|
|
38
|
+
joinability: 'joinable_by_friends',
|
|
39
|
+
joinRestriction: 'followed',
|
|
40
|
+
broadcastSetting: 3,
|
|
41
|
+
},
|
|
42
|
+
};
|