Skip to content

beamable-sdk / core/BeamServer / BeamServer

Class: BeamServer

Defined in: src/core/BeamServer.ts:30

The main class for interacting with the Beam Server SDK.

Extends

Properties

account()

account: (userId) => AccountService

Parameters

userId

string

Returns

AccountService


announcements()

announcements: (userId) => AnnouncementsService

Parameters

userId

string

Returns

AnnouncementsService


auth()

auth: (userId) => AuthService

Parameters

userId

string

Returns

AuthService


cid

cid: string

Defined in: src/core/BeamBase.ts:34

The Beamable Customer ID.

Inherited from

BeamBase.cid


content()

content: (userId) => ContentService

Parameters

userId

string

Returns

ContentService


leaderboards()

leaderboards: (userId) => LeaderboardsService

Parameters

userId

string

Returns

LeaderboardsService


pid

pid: string

Defined in: src/core/BeamBase.ts:36

The Beamable Project ID.

Inherited from

BeamBase.pid


requester

readonly requester: HttpRequester

Defined in: src/core/BeamBase.ts:32

The HTTP requester instance used by the Beam SDK.

Inherited from

BeamBase.requester


stats()

stats: (userId) => StatsService

Parameters

userId

string

Returns

StatsService


tokenStorage

tokenStorage: TokenStorage

Defined in: src/core/BeamBase.ts:42

The token storage instance used by the client SDK. Defaults to BrowserTokenStorage in browser environments and NodeTokenStorage in Node.js environments. Can be overridden via the tokenStorage option in the BeamConfig.

Inherited from

BeamBase.tokenStorage

Accessors

env

Get Signature

get static env(): BeamEnvVars

Defined in: src/core/BeamServer.ts:61

Environment variables that can be set to configure the Beam SDK.

Remarks

These values must be supplied at runtime via real environment variables (e.g. process.env.REALM_SECRET), and must not be committed directly into your source code.

Example
BeamBase.env.REALM_SECRET = process.env.REALM_SECRET;
const beam = await Beam.init({ ... });
Returns

BeamEnvVars

Overrides

BeamBase.env

Methods

off()

off<K>(eventType, handler?): void

Defined in: src/core/BeamServer.ts:168

Unsubscribes from a specific server-event or removes all subscriptions if no handler is provided.

Type Parameters

K

K extends ServerEventType

Parameters

eventType

K

The server-event to unsubscribe from, e.g., 'content.manifest'.

handler?

(data) => void

The callback to remove. If not provided, all handlers for the server-event are removed.

Returns

void

Example

beamServer.off('content.manifest', handler);
// or to remove all handlers for the server-event
beamServer.off('content.manifest');

on()

on<K>(eventType, handler): void

Defined in: src/core/BeamServer.ts:137

Subscribes to a server-event and listens for messages.

Type Parameters

K

K extends ServerEventType

Parameters

eventType

K

The server-event to subscribe to, e.g., 'content.manifest'.

handler

(data) => void

The callback to process the data when a message is received.

Returns

void

Example

const handler = (data) => {
  console.log('Content manifest received:', data);
};
beamServer.on('content.manifest', handler);

use()

Call Signature

use<T>(ctors): this

Defined in: src/core/BeamServer.ts:65

Dynamically adds multiple api services or microservice clients to the Beam SDK.

Type Parameters
T

T extends ApiServiceCtor<any> | BeamMicroServiceClientCtor<any>

Parameters
ctors

readonly T[]

An array of constructors for the api service or microservice client.

Returns

this

The current instance of BeamBase.

Example

const beam = await Beam.init({ ... });
beam.use([LeadboardService, StatsService]);
or
const beam = await Beam.init({ ... });
beam.use([MyMicroserviceClient, MyOtherMicroserviceClient]);

Overrides

BeamBase.use

Call Signature

use<T>(ctor): this

Defined in: src/core/BeamServer.ts:68

Dynamically adds a single api service or microservice client to the Beam SDK.

Type Parameters
T

T extends ApiServiceCtor<any> | BeamMicroServiceClientCtor<any>

Parameters
ctor

T

The constructor for the api service or microservice client.

Returns

this

The current instance of BeamBase.

Example

const beam = await Beam.init({ ... });
beam.use(StatsService);
or
const beam = await Beam.init({ ... });
beam.use(MyMicroserviceClient);

Overrides

BeamBase.use


init()

static init(config): Promise<BeamServer>

Defined in: src/core/BeamServer.ts:36

Initialize a new Beam server instance.

Parameters

config

BeamServerConfig

Returns

Promise<BeamServer>