bedrock-portal 0.0.8 → 0.0.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +21 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bedrock-portal",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
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": {
package/src/index.js CHANGED
@@ -39,7 +39,6 @@ module.exports = class BedrockPortal extends EventEmitter {
39
39
  }
40
40
 
41
41
  async start() {
42
-
43
42
  this.sessionOwner = await this.#rest.getXboxProfile('me');
44
43
 
45
44
  if (!this.options.disableAltCheck) {
@@ -51,6 +50,16 @@ module.exports = class BedrockPortal extends EventEmitter {
51
50
 
52
51
  const connectionId = await this.#rta.subscribe('https://sessiondirectory.xboxlive.com/connections/').then(e => e.data.ConnectionId);
53
52
 
53
+ const session = await this.createAndPublishSession(connectionId);
54
+
55
+ await this.#handleSessionEvents();
56
+
57
+ return session;
58
+ }
59
+
60
+ async createAndPublishSession(connectionId) {
61
+ this.players = [];
62
+
54
63
  await this.updateSession(this.#createSessionBody(connectionId));
55
64
 
56
65
  debug(`Created session, name: ${this.session.name}`);
@@ -61,8 +70,6 @@ module.exports = class BedrockPortal extends EventEmitter {
61
70
 
62
71
  await this.updateSession({ properties: session.properties });
63
72
 
64
- await this.#handleSessionEvents();
65
-
66
73
  debug(`Published session, name: ${this.session.name}`);
67
74
 
68
75
  return session;
@@ -135,13 +142,23 @@ module.exports = class BedrockPortal extends EventEmitter {
135
142
  async #handleSessionEvents() {
136
143
  this.#rta.on('reconnect', async () => {
137
144
  const connectionId = await this.#rta.subscribe('https://sessiondirectory.xboxlive.com/connections/').then(e => e.data.ConnectionId);
138
- await this.updateConnection(connectionId);
145
+
146
+ try {
147
+ await this.updateConnection(connectionId);
148
+ await this.updateHandle(this.#createHandleBody('activity'));
149
+ }
150
+ catch (e) {
151
+ debug('Failed to update connection, session may have been abandoned', e);
152
+ await this.createAndPublishSession(connectionId);
153
+ }
139
154
  });
140
155
 
141
156
  this.#rta.on('event', async ({ type, subId, data }) => {
142
157
  this.emit('rtaEvent', { type, subId, data });
143
158
  const session = await this.getSession();
144
159
 
160
+ debug('Received RTA event, session has been updated', session);
161
+
145
162
  const sessionMembers = Object.keys(session.members).map(key => session.members[key]).filter(member => member.constants.system.xuid !== this.sessionOwner.xuid);
146
163
  const xuids = sessionMembers.map(e => e.constants.system.xuid);
147
164