npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bedrock-portal

v0.9.3

Published

Creates a joinable session in Minecraft Bedrock Edition that can route players to their a specified host

Downloads

360

Readme

BedrockPortal

NPM version Discord

Handles and creates a Minecraft Bedrock game session which will redirect players to the specified server. Join our Discord for support.

Installation

npm install bedrock-portal

Warning

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.

Usage

BedrockPortal(authflow, options)

Parameters

  • authflow - Takes an Authflow instance from prismarine-auth, you can see the documentation for this here.
  • options
    • ip - The IP address of the server to redirect players to (required)
    • port - The port of the server to redirect players to | default: 19132
    • joinability - The joinability of the session | default: FriendsOfFriends
    • world - The world config to use for the session. Changes the session card which is displayed in the Minecraft client. (optional)
      • hostName - string
      • name - string
      • version - string
      • memberCount - number
      • maxMemberCount - number

Create a session redirect to a server

const { BedrockPortal, Joinability } = require('bedrock-portal');
const { Authflow, Titles } = require('prismarine-auth');

const main = async () => {
  const auth = new Authflow('example', './', { authTitle: Titles.MinecraftNintendoSwitch, deviceType: 'Nintendo', flow: 'live' });
  
  const portal = new BedrockPortal(auth, {
    // The server IP & port to redirect players to
    ip: 'geyserconnect.net',
    port: 19132,

     // The joinability of the session. Joinability.FriendsOfFriends, Joinability.FriendsOnly, Joinability.InviteOnly
    joinability: Joinability.FriendsOfFriends
  });

  await portal.start();
	
  // accepts a player's gamertag or xuid
  await portal.invitePlayer('p3')

};

main();

Modules

Modules are used to extend the functionality of the BedrockPortal class.

ServerFormList

Instead of redirecting players to a server, the portal will display a list of servers to join from a form. #.use(Modules.serverFormList, options);

Options:

  • form: Form - The form to display to the player. At the moment only simple forms are supported. (required)
  • timeout: number - The time in milliseconds before the player is kicked from the session if they don't select a server (default: 60000ms)
  • timeoutMessage: string - The message to display to the player when they are kicked from the session (default: 'You took too long to select a server!')

The form will be sent to the player when they join the server and every 5 seconds after they clost the form.

const { BedrockPortal, Joinability, Modules } = require('bedrock-portal')
const { Authflow, Titles } = require('prismarine-auth')

const main = async () => {
  const auth = new Authflow('example', './', { authTitle: Titles.XboxAppIOS, deviceType: 'iOS', flow: 'sisu' })

  const portal = new BedrockPortal(auth)

  portal.use(Modules.ServerFromList, {
    form: {
      title: '§l§aServer Form List',
      content: '§7Please select a server to join',
      buttons: [
        { text: '§8Anarchy Server\n§7Click Here§!', ip: 'bedrock.opblocks.com', port: 19132 },
        { text: '§7Creative Server\n§7Click Here§', ip: 'bedrock.opblocks.com', port: 19132 },
        { text: '§6Survival Server\n§7Click Here§!', ip: 'bedrock.opblocks.com', port: 19132 },
      ],
    },
    timeout: 60000,
    timeoutMessage: '§cYou took too long to select a server!',
  })

  await portal.start()
}

main()

MultipleAccounts

Allows the portal to use multiple accounts to redirect players to the server. #.use(Modules.MultipleAccounts, options);

Options:

  • accounts: Authflow[] - An array of authflows from 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)
const { Authflow, Titles } = require('prismarine-auth')
const { BedrockPortal, Modules } = require('bedrock-portal')

const main = async () => {
  const auth = new Authflow('example', './', { authTitle: Titles.MinecraftNintendoSwitch, deviceType: 'Nintendo', flow: 'live' })

  const portal = new BedrockPortal(auth, {
    ip: 'geyserconnect.net',
    port: 19132,
  })

  portal.use(Modules.AutoFriendAdd, {
    inviteOnAdd: true,
  })

  portal.use(Modules.MultipleAccounts, {
    accounts: [
      new Authflow('account1', './', { authTitle: Titles.MinecraftNintendoSwitch, deviceType: 'Nintendo', flow: 'live' }),
      new Authflow('account2', './', { authTitle: Titles.MinecraftNintendoSwitch, deviceType: 'Nintendo', flow: 'live' }),
    ],
  })

  await portal.start()
}

main()

RedirectFromRealm

Requires bedrock-protocol to be installed. npm install bedrock-protocol

Invites players when they join a Realm to the specified server or if they use the chat command. #.use(Modules.redirectFromRealm, options);

Options:

  • clientOptions: ClientOptions - The client options to use when connecting to the Realm. These are passed directly to a bedrock-protocol createClient function. See the documentation for more information.
  • chatCommand: object - Options for the chat command
    • enabled: boolean - Whether sending the command in chat should trigger an invite (default: true)
    • message: string - The message to send in chat to run the command (default: 'invite')
    • cooldown: number - The cooldown between being able to send the command in chat (default: 60000ms)
const { BedrockPortal, Modules } = require('bedrock-portal');

const portal = new BedrockPortal(auth, { ... })

portal.use(Modules.RedirectFromRealm, {
  // The client options to use when connecting to the Realm.
  clientOptions: {
    realms: {
      realmInvite: ''
    }
  },
  // Options for the chat command
  chatCommand: {
    // Whether sending the command in chat should trigger an invite (optional - defaults to true)
    enabled: true,
    // The message to send in chat to run the command (optional - defaults to 'invite')
    message: 'invite',
    // The cooldown between being able to send the command in chat (optional - defaults to 60000ms)
    cooldown: 60000,
  }
}

UpdateMemberCount

Requires bedrock-protocol to be installed. npm install bedrock-protocol

Periodically updates the member count of the session. #.use(Modules.UpdateMemberCount, options);

Options:

  • updateInterval: number - How often to update the member count (default: 60000ms)
  • updateMaxMemberCount: boolean - Whether to update the max member count (default: true)
const { BedrockPortal, Modules } = require('bedrock-portal');

const portal = new BedrockPortal(auth, { ... })

portal.use(Modules.UpdateMemberCount, {
  updateInterval: 60000,
  updateMaxMemberCount: true,
});

AutoFriendAdd

Automatically adds the account's followers as friends and invites them to the game. #.use(Modules.autoFriendAdd);

Options:

  • inviteOnAdd: boolean - Automatically invites recently added friends to the game (default: false)
  • 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)
  • checkInterval: number - How often to check for friends to add/remove (default: 30000ms)
  • addInterval: number - How long to wait between adding friends (default: 2000ms)
  • removeInterval: number - How long to wait between removing friends (default: 2000ms)
const { BedrockPortal, Modules } = require('bedrock-portal');

const portal = new BedrockPortal(auth, { ... })

portal.use(Modules.AutoFriendAdd);

// or

portal.use(Modules.AutoFriendAdd, {
  // When a friend is added, automatically invite them to the game
  inviteOnAdd: true,
  // Only add friends that are online and remove friends that are offline
  conditionToMeet: (player) => player.presenceState === 'Online',
  // How often to check for friends to add/remove (optional - defaults to 30000ms)
  checkInterval: 30000,
  // How long to wait between adding friends (optional - defaults to 2000ms)
  addInterval: 2000,
  // How long to wait between removing friends (optional - defaults to 2000ms)
  removeInterval: 2000,
});

AutoFriendAccept

Automatically accepts friend requests sent to the account. #.use(Modules.autoFriendAdd);

Options:

  • inviteOnAdd: boolean - Automatically invites added friends to the game (default: false)
  • conditionToMeet: (player: Player) => boolean - If the function returns true then the request will be accepted (default: () => true)
const { BedrockPortal, Modules } = require('bedrock-portal');

const portal = new BedrockPortal(auth, { ... })

portal.use(Modules.AutoFriendAccept);

// or

portal.use(Modules.AutoFriendAccept, {
  // When a friend is added invite them to the game
  inviteOnAdd: true,
  // Only accept friends that have 'elite' in their gamertag
  conditionToMeet: (player) => player.gamertag.includes('elite'),
});

InviteOnMessage

Automatically invites players to the game when they send a message in the chat. #.use(Modules.inviteOnMessage);

Options:

  • command: string - The command to use to invite players (default: 'invite')
  • checkInterval: number - How often to check for messages (default: 30000ms)
const { BedrockPortal, Modules } = require('bedrock-portal');

const portal = new BedrockPortal(auth, { ... })

portal.use(Modules.InviteOnMessage);

// or

portal.use(Modules.InviteOnMessage, {
  // The command to use to invite players (optional - defaults to 'invite')
  command: 'invite',
  // How often to check for messages (optional - defaults to 30000ms)
  checkInterval: 30000,
});

Modules API

Creating a module is easy. You can create a module by extending the Module class.

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.

const { Module } = require('bedrock-portal');

const myModule = class MyModule extends Module {
  constructor() {
    super('myModule', 'Description of my module');
    this.options = {
      option1: true,
    }
  }

  async run(portal) {
    // portal - The BedrockPortal instance

    // Do stuff here
  }

  async stop() {
    super.stop();
    // Do stuff when the module is stopped
  }
}

portal.use(myModule, {
  option1: false,
});

Events

portal.on('sessionCreated', (session) => void)

Emitted when a session is created.

portal.on('sessionUpdated', (session) => void)

Emitted when a session is updated.

portal.on('playerJoin', (player) => void)

Emitted when a player joins the session.

portal.on('playerLeave', (player) => void)

Emitted when a player leaves the session.

portal.on('friendAdded', (player) => void)

Emitted when a player is added as a friend. This event is only emitted when the autoFriendAdd module is enabled.

portal.on('friendRemoved', (player) => void)

Emitted when a player is removed as a friend. This event is only emitted when the autoFriendAdd module is enabled.

portal.on('messageReceived', (message) => void)

Emitted when a message is received from a player. This event is only emitted when the inviteOnMessage module is enabled.

portal.on('memberCountUpdate', (memberCount) => void)

Emitted when the member count of the session is updated. This event is only emitted when the updateMemberCount module is enabled.

Debugging

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.

License

MIT