bedrock-portal 0.2.5 → 0.2.7

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 CHANGED
@@ -62,7 +62,7 @@ Modules are used to extend the functionality of the BedrockPortal class.
62
62
  Automatically adds the account's followers as friends and invites them to the game. `#.use(Modules.autoFriendAdd);`
63
63
 
64
64
  Options:
65
- - **autoInvite**: boolean - Automatically invites recently added friends to the game (default: false)
65
+ - **inviteOnAdd**: boolean - Automatically invites recently added friends to the game (default: false)
66
66
 
67
67
  ```js
68
68
  const { BedrockPortal, Modules } = require('bedrock-portal');
@@ -74,7 +74,7 @@ portal.use(Modules.autoFriendAdd);
74
74
  // or
75
75
 
76
76
  portal.use(Modules.autoFriendAdd, {
77
- autoInvite: true,
77
+ inviteOnAdd: true,
78
78
  });
79
79
  ```
80
80
 
@@ -1,4 +1,6 @@
1
1
  /* eslint-disable no-multi-spaces */
2
+ // process.env.DEBUG = 'bedrock-portal*';
3
+
2
4
  const { BedrockPortal, Modules, Joinability } = require('bedrock-portal');
3
5
  const { Authflow, Titles } = require('prismarine-auth');
4
6
 
@@ -23,9 +25,7 @@ const main = async () => {
23
25
  inviteOnAdd: true,
24
26
  });
25
27
 
26
- await portal.start(); // Starts the session
27
-
28
- await portal.invitePlayer('p3'); // gamertag or xuid to invite
28
+ // Put your event listeners before portal.start() to ensure you don't miss any events
29
29
 
30
30
  portal.on('rtaEvent', (event) => { // Emits when an RTA event is received
31
31
  console.log('RTA Event: ', event);
@@ -51,6 +51,10 @@ const main = async () => {
51
51
  console.log('Friend Added: ', player);
52
52
  });
53
53
 
54
+ await portal.start(); // Starts the session
55
+
56
+ await portal.invitePlayer('p3'); // gamertag or xuid to invite
57
+
54
58
  };
55
59
 
56
60
  main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bedrock-portal",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Creates a joinable session in Minecraft Bedrock Edition that can route players to their a specified host",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,9 +1,9 @@
1
1
  class Player {
2
- constructor(profileData = {}, sessionData = {}) {
2
+ constructor(profileData, sessionData) {
3
3
  this.profile = {};
4
4
  this.session = {};
5
- this.setXboxProfile(profileData);
6
- this.setSessionMember(sessionData);
5
+ if (profileData) this.setXboxProfile(profileData);
6
+ if (sessionData) this.setSessionMember(sessionData);
7
7
  }
8
8
 
9
9
  static fromSessionMember(data) {
@@ -7,7 +7,7 @@ const SessionConfig = {
7
7
  MinecraftTitleID: '896928775',
8
8
  MinecraftSCID: '4fc10100-5f7a-4470-899b-280835760c07',
9
9
  MinecraftTemplateName: 'MinecraftLobby',
10
- MiencraftProtocolVersion: 575,
10
+ MiencraftProtocolVersion: 589,
11
11
  };
12
12
 
13
13
  const Joinability = {
package/src/index.js CHANGED
@@ -94,7 +94,11 @@ module.exports = class BedrockPortal extends EventEmitter {
94
94
  async invitePlayer(identifier) {
95
95
  debug(`Inviting player, identifier: ${identifier}`);
96
96
 
97
- const profile = await this.#rest.getXboxProfile(identifier);
97
+ const profile = await this.#rest.getXboxProfile(identifier)
98
+ .catch(() => { throw new Error(`Failed to get profile for identifier: ${identifier}`); });
99
+
100
+ debug(`Inviting player, Got profile, xuid: ${profile.xuid}`);
101
+
98
102
  const invitePayload = {
99
103
  invitedXuid: String(profile.xuid),
100
104
  inviteAttributes: { titleId: SessionConfig.MinecraftTitleID },
@@ -220,11 +224,15 @@ module.exports = class BedrockPortal extends EventEmitter {
220
224
  });
221
225
 
222
226
  if (this.modules) {
223
- for (const mod of Object.values(this.modules)) {
224
- mod.run(this, { rest: this.#rest, rta: this.#rta })
225
- .then(() => debug(`Module ${mod.name} has run`))
226
- .catch(e => debug(`Module ${mod.name} failed to run`, e));
227
- }
227
+ Object.values(this.modules).forEach(async mod => {
228
+ try {
229
+ mod.run(this, { rest: this.#rest, rta: this.#rta });
230
+ debug(`Module ${mod.name} has run`);
231
+ }
232
+ catch (e) {
233
+ debug(`Module ${mod.name} failed to run`, e);
234
+ }
235
+ });
228
236
  }
229
237
 
230
238
  }
@@ -21,9 +21,13 @@ class AutoFriendAdd extends Module {
21
21
  .then(people => people.map(e => e.xuid))
22
22
  .catch(() => []);
23
23
 
24
+ this.debug(`Found ${friends.length} friend(s)`);
25
+
24
26
  const followers = await rest.getXboxFollowers()
25
27
  .catch(() => []);
26
28
 
29
+ this.debug(`Found ${followers.length} follower(s)`);
30
+
27
31
  const needsAdding = followers.filter(res => !friends.includes(res.xuid));
28
32
 
29
33
  if (!needsAdding.length) {
package/src/rest.js CHANGED
@@ -114,11 +114,11 @@ module.exports = class Rest {
114
114
  }
115
115
 
116
116
  async getXboxFriends() {
117
- return await this.get('https://peoplehub.xboxlive.com/users/me/people/social/decoration/details', { contractVersion: 5 }).then(res => res.people.map(e => this.#parseXboxProfile(e)));
117
+ return await this.get('https://peoplehub.xboxlive.com/users/me/people/social/decoration/detail,preferredColor', { contractVersion: 5 }).then(res => res.people.map(e => this.#parseXboxProfile(e)));
118
118
  }
119
119
 
120
120
  async getXboxFollowers() {
121
- return await this.get('https://peoplehub.xboxlive.com/users/me/people/followers/decoration/details', { contractVersion: 5 }).then(res => res.people.map(e => this.#parseXboxProfile(e)));
121
+ return await this.get('https://peoplehub.xboxlive.com/users/me/people/followers/decoration/detail,preferredColor', { contractVersion: 5 }).then(res => res.people.map(e => this.#parseXboxProfile(e)));
122
122
  }
123
123
 
124
124
  async addXboxFriend(xuid) {