beamable-sdk / core/Beam / Beam
Class: Beam¶
Defined in: src/core/Beam.ts:32
The main class for interacting with the Beam Client SDK.
Extends¶
BeamBase<this>.BeamServiceType
Properties¶
account¶
account:
AccountService
announcements¶
announcements:
AnnouncementsService
auth¶
auth:
AuthService
cid¶
cid:
string
Defined in: src/core/BeamBase.ts:34
The Beamable Customer ID.
Inherited from¶
content¶
content:
ContentService
leaderboards¶
leaderboards:
LeaderboardsService
pid¶
pid:
string
Defined in: src/core/BeamBase.ts:36
The Beamable Project ID.
Inherited from¶
player¶
player:
PlayerService
Defined in: src/core/Beam.ts:37
A namespace of player-related services.
Use beam.player.<method> to access player-specific operations.
requester¶
readonlyrequester:HttpRequester
Defined in: src/core/BeamBase.ts:32
The HTTP requester instance used by the Beam SDK.
Inherited from¶
stats¶
stats:
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¶
Accessors¶
env¶
Get Signature¶
get
staticenv():BeamEnvVars
Defined in: src/core/Beam.ts:75
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¶
Returns¶
Overrides¶
Methods¶
off()¶
off<
K>(context,handler?):void
Defined in: src/core/Beam.ts:269
Unsubscribes from a specific context or removes all subscriptions if no handler is provided.
Type Parameters¶
K¶
K extends keyof RefreshableServiceMap
Parameters¶
context¶
K
The context to unsubscribe from, e.g., 'inventory.refresh'.
handler?¶
(data) => void
The callback to remove. If not provided, all handlers for the context are removed.
Returns¶
void
Example¶
beam.off('inventory.refresh', handler);
// or to remove all handlers for the context
beam.off('inventory.refresh');
on()¶
on<
K>(context,handler):void
Defined in: src/core/Beam.ts:220
Subscribes to a specific context and listens for messages.
Type Parameters¶
K¶
K extends keyof RefreshableServiceMap
Parameters¶
context¶
K
The context to subscribe to, e.g., 'inventory.refresh'.
handler¶
(data) => void
The callback to process the data when a message is received.
Returns¶
void
Example¶
const handler = (data) => {
console.log('New inventory data:', data);
}
beam.use(InventoryService);
beam.on('inventory.refresh', handler);
refresh()¶
refresh(
tokenResponse?):Promise<void>
Defined in: src/core/Beam.ts:193
Refreshes the current Beam SDK instance with a new token response. This method re-initializes the SDK with the provided token, updates the internal state, and re-establishes necessary connections.
Parameters¶
tokenResponse?¶
The new token response to use for refreshing the SDK.
Returns¶
Promise<void>
Example¶
use()¶
Call Signature¶
use<
T>(ctors):this
Defined in: src/core/Beam.ts:79
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¶
orOverrides¶
Call Signature¶
use<
T>(ctor):this
Defined in: src/core/Beam.ts:82
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¶
orOverrides¶
init()¶
staticinit(config):Promise<Beam>
Defined in: src/core/Beam.ts:44
Initialize a new Beam client instance.
Parameters¶
config¶
Returns¶
Promise<Beam>