bedrock-portal 0.1.3 → 0.2.0

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/.eslintrc.json CHANGED
@@ -5,14 +5,15 @@
5
5
  "es2022": true
6
6
  },
7
7
  "rules": {
8
- "brace-style": ["error", "stroustrup", { "allowSingleLine": true }],
8
+ "eol-last": ["error", "always"],
9
+ "brace-style": ["error", "stroustrup", { "allowSingleLine": true }],
9
10
  "comma-dangle": ["error", "always-multiline"],
10
11
  "comma-spacing": "error",
11
12
  "comma-style": "error",
12
13
  "curly": ["error", "multi-line", "consistent"],
13
14
  "dot-location": ["error", "property"],
14
15
  "handle-callback-err": "off",
15
- "indent": ["error", "tab", { "SwitchCase": 1 }],
16
+ "indent": ["error", 2, { "SwitchCase": 1 }],
16
17
  "max-nested-callbacks": ["error", { "max": 4 }],
17
18
  "max-statements-per-line": ["error", { "max": 2 }],
18
19
  "no-console": "off",
@@ -0,0 +1,30 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: ['*']
6
+ pull_request:
7
+ branches: ['*']
8
+ workflow_dispatch:
9
+ inputs:
10
+ via:
11
+ description: 'trigger origin'
12
+ required: true
13
+
14
+ jobs:
15
+ build:
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ os: [ubuntu-latest, windows-latest]
20
+ node-version: [16.x]
21
+ runs-on: ${{ matrix.os }}
22
+ timeout-minutes: 12
23
+ steps:
24
+ - uses: actions/checkout@v2
25
+ - name: Use Node.js ${{ matrix.node-version }}
26
+ uses: actions/setup-node@v1
27
+ with:
28
+ node-version: ${{ matrix.node-version }}
29
+ - run: npm install
30
+ - run: npm run lint
package/README.md CHANGED
@@ -14,40 +14,39 @@ This package is not meant to be used with your main account. It is meant to be u
14
14
 
15
15
  ## Usage
16
16
 
17
- ### BedrockPortal(authflow)
17
+ ### BedrockPortal(authflow, options)
18
18
  **Parameters**
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
- - **ip** - The IP address of the server to redirect players to
22
- - **port** - The port of the server to redirect players to
23
- - **disableAltCheck** - Disables the alt check.
24
- - **joinability** - The joinability of the session, Can be 'friends_of_friends', 'friends_only', 'invite_only'
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
+ - **disableAltCheck** - Disables the alt check (default: false)
24
+ - **joinability** - The joinability of the session (default: Joinability.FriendsOfFriends)
25
25
  - **world** - The world config to use for the session. Changes the session card which is displayed in the Minecraft client.
26
- - **hostName** - string
27
- - **name** - string
28
- - **version** - string
29
- - **memberCount** - number
30
- - **maxMemberCount** - number
31
- - **modules** - An object containing modules to enable. See [Modules](#modules) for more information.
26
+ - **hostName** - string (default: '{gamertag}'s Portal')
27
+ - **name** - string (default: 'BedrockPortal')
28
+ - **version** - string (default: '{BedrockPortal version}')
29
+ - **memberCount** - number (default: 0)
30
+ - **maxMemberCount** - number (default: 10)
32
31
 
33
32
  ### Create a session redirect to a server
34
33
  ```js
35
- const { BedrockPortal } = require('bedrock-portal');
34
+ const { BedrockPortal, Joinability } = require('bedrock-portal');
36
35
  const { Authflow, Titles } = require('prismarine-auth');
37
36
 
38
37
  const main = async () => {
39
- const auth = new Authflow('example', './', { authTitle: Titles.MinecraftNintendoSwitch, deviceType: 'Nintendo' });
38
+ const auth = new Authflow('example', './', { authTitle: Titles.MinecraftNintendoSwitch, deviceType: 'Nintendo', flow: 'live' });
40
39
 
41
- const session = new BedrockPortal(auth, {
40
+ const portal = new BedrockPortal(auth, {
42
41
  ip: 'geyserconnect.net', // The server IP & port to redirect players to
43
42
  port: 19132,
44
- joinability: 'friends_of_friends', // The joinability of the session. Can be 'friends_of_friends', 'friends_only', 'invite_only'
43
+ joinability: Joinability.InviteOnly, // The joinability of the session. Joinability.FriendsOfFriends, Joinability.FriendsOnly, Joinability.InviteOnly
45
44
  });
46
45
 
47
- await session.start();
46
+ await portal.start();
48
47
 
49
48
  // accepts a player's gamertag or xuid
50
- await session.invitePlayer('p3')
49
+ await portal.invitePlayer('p3')
51
50
 
52
51
  };
53
52
 
@@ -56,26 +55,213 @@ main();
56
55
 
57
56
  ## Modules
58
57
 
59
- Modules are used to extend the functionality of the BedrockPortal class. You can find a list of modules below.
58
+ Modules are used to extend the functionality of the BedrockPortal class.
59
+
60
+ ### autoFriendAdd
61
+
62
+ Automatically adds the account's followers as friends and invites them to the game. `#.use(Modules.autoFriendAdd);`
63
+
64
+ Options:
65
+ - **autoInvite**: boolean - Automatically invites recently added friends to the game (default: false)
60
66
 
61
67
  ```js
62
- new BedrockPortal(auth, {
63
- ...,
64
- modules: {
65
- autoFriendAdd: true, // Automatically add friends to the session
66
- },
67
- })
68
+ const { Modules } = require('bedrock-portal');
69
+
70
+ const portal = new BedrockPortal(auth, { ... })
71
+
72
+ portal.use(Modules.autoFriendAdd);
73
+
74
+ // or
75
+
76
+ portal.use(Modules.autoFriendAdd, {
77
+ autoInvite: true,
78
+ });
68
79
  ```
69
80
 
70
- ### autoFriendAdd
81
+ ## Modules API
82
+
83
+ Creating a module is easy. You can create a module by extending the `Module` class.
84
+
85
+ Note: The `stopped` property is set to `true` when the module is stopped. You can use this to stop the module's loop (if one is present) else the process will not exit.
86
+
87
+ ```js
88
+ const { Module } = require('bedrock-portal');
89
+
90
+ const myModule = class MyModule extends Module {
91
+ constructor() {
92
+ super('myModule', 'Description of my module');
93
+ this.options = {
94
+ option1: true,
95
+ }
96
+ }
97
+
98
+ async run(portal, { rest, rta }) {
99
+ // portal - The BedrockPortal instance
100
+ // rest - The REST API instance
101
+ // rta - The RTA API instance
102
+
103
+ // Do stuff here
104
+ }
105
+ }
106
+
107
+ portal.use(myModule);
108
+ ```
109
+
110
+ ## Events
111
+
112
+ ### portal.on('sessionCreated', (session) => {})
113
+ Emitted when a session is created.
114
+
115
+ **Parameters**
116
+ - session - [Session](#session) object
117
+
71
118
 
72
- Automatically adds the account's followers as friends so the session can be joined by them.
73
- * Add `autoFriendAdd: true` to the modules object in the BedrockPortal constructor.
119
+ ### portal.on('sessionUpdated', (session) => {})
120
+ Emitted when a session is updated.
121
+
122
+ **Parameters**
123
+ - session - [Session](#session) object
124
+
125
+
126
+ ### portal.on('playerJoin', (player) => {})
127
+ Emitted when a player joins the session.
128
+
129
+ **Parameters**
130
+ - player - [Player](#player) object
131
+
132
+
133
+ ### portal.on('playerLeave', (player) => {})
134
+ Emitted when a player leaves the session.
135
+
136
+ **Parameters**
137
+ - player - [Player](#player) object
138
+
139
+
140
+ ### portal.on('friendAdded', (player) => {})
141
+ Emitted when a player is added as a friend. This event is only emitted when the `autoFriendAdd` module is enabled.
142
+
143
+ **Parameters**
144
+ - player - [Player](#player) object
145
+
146
+ ## Objects
147
+
148
+ ### Player
149
+
150
+ ```ts
151
+ {
152
+ profile?: {
153
+ xuid: string,
154
+ avatar: string,
155
+ gamerscore: string,
156
+ gamertag: string,
157
+ tier: string,
158
+ reputation: string,
159
+ colour: {
160
+ primaryColour: string,
161
+ secondaryColour: string,
162
+ tertiaryColour: string
163
+ },
164
+ realname: string,
165
+ bio: string,
166
+ location: string,
167
+ modernGamertag: string,
168
+ modernGamertagSuffix: string,
169
+ uniqueModernGamertag: string,
170
+ realnameOverride: string,
171
+ tenureLevel: string,
172
+ watermarks: string,
173
+ isQuarantined: boolean,
174
+ linkedAccounts: []
175
+ }
176
+ session?: {
177
+ titleId: string
178
+ joinTime: string
179
+ index: number
180
+ connectionId: string
181
+ subscriptionId: string
182
+ }
183
+ }
184
+ ```
185
+
186
+ ### Session
187
+
188
+ ```ts
189
+ {
190
+ membersInfo: {
191
+ first: number,
192
+ next: number,
193
+ count: number,
194
+ accepted: number,
195
+ active: number
196
+ },
197
+ constants: {
198
+ system: {
199
+ readyRemovalTimeout: number,
200
+ reservedRemovalTimeout: number,
201
+ sessionEmptyTimeout: number,
202
+ inactiveRemovalTimeout: number,
203
+ version: number,
204
+ maxMembersCount: number,
205
+ visibility: string,
206
+ capabilities: {
207
+ connectivity: boolean,
208
+ connectionRequiredForActiveMembers: boolean,
209
+ gameplay: boolean,
210
+ crossPlay: boolean,
211
+ userAuthorizationStyle: boolean
212
+ },
213
+ inviteProtocol: string,
214
+ memberInitialization: {
215
+ membersNeededToStart: number,
216
+ }
217
+ },
218
+ custom: {}
219
+ },
220
+ properties: {
221
+ system: {
222
+ joinRestriction: 'followed' | 'local',
223
+ readRestriction: string,
224
+ turn: []
225
+ },
226
+ custom: {
227
+ Joinability: string,
228
+ hostName: string,
229
+ ownerId: string,
230
+ rakNetGUID: string,
231
+ version: string,
232
+ worldName: string,
233
+ worldType: string,
234
+ protocol: number,
235
+ MemberCount: number,
236
+ MaxMemberCount: number,
237
+ BroadcastSetting: number,
238
+ UsesWebSocketsWebRTCSignaling: boolean,
239
+ UsesMPSDWebRTCSignaling: boolean,
240
+ netherNetEnabled: boolean,
241
+ OnlineCrossPlatformGame: boolean,
242
+ CrossPlayDisabled: boolean,
243
+ TitleId: number,
244
+ SupportedConnections: SessionConnection[],
245
+ levelId: string,
246
+ LanGame: boolean
247
+ }
248
+ },
249
+ servers: {},
250
+ members: {
251
+ [index: number]: SessionMember
252
+ }
253
+ correlationId: string,
254
+ contractVersion: number,
255
+ branch: string,
256
+ changeNumber: number,
257
+ startTime: string
258
+ }
259
+ ```
74
260
 
75
261
 
76
262
  ## Debugging
77
263
 
78
- 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.
264
+ 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.
79
265
 
80
266
  ## License
81
267
 
@@ -0,0 +1,56 @@
1
+ /* eslint-disable no-multi-spaces */
2
+ const { BedrockPortal, Modules, Joinability } = require('bedrock-portal');
3
+ const { Authflow, Titles } = require('prismarine-auth');
4
+
5
+ const main = async () => {
6
+ const auth = new Authflow('example', './', { authTitle: Titles.MinecraftNintendoSwitch, deviceType: 'Nintendo', flow: 'live' });
7
+
8
+ const portal = new BedrockPortal(auth, {
9
+ ip: 'geyserconnect.net',
10
+ port: 19132, // The port of the server (optional - defaults to 19132)
11
+ joinability: Joinability.FriendsOfFriends, // The joinability of the session (optional - defaults to Joinability.FriendsOfFriends)
12
+ disableAltCheck: false, // Disables the alt check (optional - defaults to false)
13
+ world: { // Only affects the join world card in the friends list (optional)
14
+ hostName: 'BedrockPortal', // Displays as the host name of the world
15
+ name: 'BedrockPortal', // Displays as the name of the world
16
+ version: '1', // Displays as the version of the world
17
+ memberCount: 0, // The current member count of the world
18
+ maxMemberCount: 10, // The max member count of the world
19
+ },
20
+ });
21
+
22
+ portal.use(Modules.autoFriendAdd, { // Automatically adds friends to the session
23
+ inviteOnAdd: true,
24
+ });
25
+
26
+ await portal.start(); // Starts the session
27
+
28
+ await portal.invitePlayer('p3'); // gamertag or xuid to invite
29
+
30
+ portal.on('rtaEvent', (event) => { // Emits when an RTA event is received
31
+ console.log('RTA Event: ', event);
32
+ });
33
+
34
+ portal.on('sessionCreated', (session) => { // Emits when the session is created'
35
+ console.log('Session Created: ', session);
36
+ });
37
+
38
+ portal.on('sessionUpdated', (session) => { // Emits when the session is updated
39
+ console.log('Session Updated: ', session);
40
+ });
41
+
42
+ portal.on('playerJoin', (player) => { // Emits when a player joins the session
43
+ console.log('Player Join: ', player);
44
+ });
45
+
46
+ portal.on('playerLeave', (player) => { // Emits when a player leaves the session
47
+ console.log('Player Leave: ', player);
48
+ });
49
+
50
+ portal.on('friendAdded', (player) => { // Emits when a friend is added. Only emitted if autoFriendAdd module is used
51
+ console.log('Friend Added: ', player);
52
+ });
53
+
54
+ };
55
+
56
+ main();