import type { RESTSessionResponse, SessionRequest } from './types/sessiondirectory'; import type { Message } from 'xbox-message'; import { EventResponse } from 'xbox-rta'; import { TypedEmitter } from 'tiny-typed-emitter'; import { Server } from 'bedrock-portal-nethernet'; import { Authflow, CacheFactory, MicrosoftAuthFlowOptions, ServerDeviceCodeResponse } from 'prismarine-auth'; import Host from './classes/Host'; import Player from './classes/Player'; import Module from './classes/Module'; import { Joinability } from './common/constants'; import AutoFriendAdd from './modules/autoFriendAdd'; import InviteOnMessage from './modules/inviteOnMessage'; import RedirectFromRealm from './modules/redirectFromRealm'; import AutoFriendAccept from './modules/autoFriendAccept'; import UpdateMemberCount from './modules/updateMemberCount'; import ServerFromList from './modules/serverFormList'; type AuthflowOptions = { username?: string; cache?: string | CacheFactory; options?: MicrosoftAuthFlowOptions; onMsaCode?: (res: ServerDeviceCodeResponse) => void; }; type BedrockPortalOptions = { /** * The ip of the server to redirect users to. */ ip: string; /** * The port the server is running on. * @default 19132 */ port: number; /** * The joinability of the session. * @default Joinability.FriendsOfFriends * @see {@link Joinability} * @example * const { BedrockPortal, Joinability } = require('bedrock-portal') * * portal = new BedrockPortal(auth, { * joinability: Joinability.InviteOnly * }) * * portal = new BedrockPortal(auth, { * joinability: Joinability.FriendsOnly * }) * * portal = new BedrockPortal(auth, { * joinability: Joinability.FriendsOfFriends * }) */ joinability: Joinability; /** * The WebRTC network ID to use for the session. */ webRTCNetworkId: bigint; /** * Whether or not to update the presence of the host. If true the account will be displayed as playing Minecraft in the Xbox app. * @default true */ updatePresence: boolean; /** * The authflow options or authflow instance to use for the host account. */ host: AuthflowOptions | Authflow; /** * Additional accounts which are connected to the session and can be used to join the portal.. * @default [] */ peers: (AuthflowOptions | Authflow)[]; /** * The world config to use for the session. Changes the session card which is displayed in the Minecraft client */ world: { /** * The host name of the world. */ hostName: string; /** * The name of the world. */ name: string; /** * The version of the world. Doesn't have to be a real version. */ version: string; /** * The current player count of the world. * @default 0 */ memberCount: number; /** * The max player count of the world. Doesn't affect the session. * @default 10 */ maxMemberCount: number; /** * Whether or not the world is hardcore. * @default false */ isHardcore: boolean; /** * Whether or not the world is an editor world. * @default false */ isEditor: boolean; }; }; interface ExtendedModule extends Module { options: any; } type ExtendedModuleConstructor = new (...args: any[]) => T; interface PortalEvents { sessionCreated: (session: RESTSessionResponse) => void; sessionUpdated: (session: RESTSessionResponse) => void; rtaEvent: (event: EventResponse) => void; playerJoin: (player: Player) => void; playerLeave: (player: Player) => void; messageRecieved: (message: Message) => void; messageReceived: (message: Message) => void; friendRemoved: (player: Player) => void; friendAdded: (player: Player) => void; memberCountUpdate: (data: { online: number; max: number; cycle: number; }) => void; } export declare class BedrockPortal extends TypedEmitter { host: Host; options: BedrockPortalOptions; session: { name: string; }; players: Map; peers: Map; modules: Map; server: Server; constructor(options?: Partial & { world?: Partial; }>); validateOptions(options: BedrockPortalOptions): void; /** * Starts the BedrockPortal instance. */ start(): Promise; /** * Ends the BedrockPortal instance. */ end(resume?: boolean): Promise; /** * Returns the current members in the session. */ getSessionMembers(): Map; getHostAndPeers(): Host[]; /** * Invites a player to the BedrockPortal instance. * @param identifyer The player's gamertag or XUID. */ invitePlayer(identifier: string): Promise; /** * Updates the current member count which is displayed in the Minecraft client. * @param count The new member count. * @param maxCount The new max member count. */ updateMemberCount(count: number, maxCount?: number): Promise; /** * Gets the current session of the BedrockPortal instance. */ getSession(): Promise; /** * Updates the current session of the BedrockPortal instance with the specified payload. * @param payload The payload to update the session with. */ updateSession(payload: SessionRequest): Promise; /** * Enables a module for the BedrockPortal instance. * @see [Modules](https://github.com/LucienHH/bedrock-portal#modules) for a list of available modules or to create your own. * @example * portal.use(Modules.autoFriendAdd) * @example * portal.use(Modules.autoFriendAdd, { * inviteOnAdd: true * }) */ use(mod: ExtendedModuleConstructor, options?: Partial): void; onServerConnection: (client: any) => void; private createAndPublishSession; private connectPeers; private disconnectPeers; private createSessionBody; } export { Joinability } from './common/constants'; export { Module }; declare const Modules: { AutoFriendAdd: typeof AutoFriendAdd; InviteOnMessage: typeof InviteOnMessage; RedirectFromRealm: typeof RedirectFromRealm; AutoFriendAccept: typeof AutoFriendAccept; UpdateMemberCount: typeof UpdateMemberCount; ServerFromList: typeof ServerFromList; }; export { Modules };