SDK
Events and state
The viewer's events, state, capabilities and error codes.
Subscribe to events
Subscribe with on(event, handler): it returns the function that unsubscribes.
const unsubscribe = viewer.on('cosmeticschange', () => {
console.log(viewer.state.stickers);
});
unsubscribe();When a handler runs, viewer.state and viewer.capabilities already hold what changed: read them rather than the event's payload. progress and the placement events are the exceptions: their payload is what they tell.
Events
readyerrorcode.reconnectcreateViewer options. Apply your state again.progressloading (false once the wait is over), ratio (the share done, from 0 to 1) and view (the view being switched to, or null).unavailablechangeviewchangesubjectchangecosmeticschangeanimationchangeplaybackchangecapabilitieschangeplacementstartplacementmoveplacementendrefusedcreateViewer rejects with the refused error instead.Save a placement
A placement does not change viewer.state: its events carry the position. The payload has target (what moves), center for a sticker or offsets for the charm (where it is now), and delta (the movement since the gesture started). On placementend, add delta to the cosmetic's offsets and save them, then pass them back with setStickers or setCharm next time.
viewer.on('placementend', ({ target, delta }) => {
if (target.kind !== 'sticker') return;
const stickers = viewer.state.stickers.map((sticker) =>
sticker.slot === target.slot
? {
...sticker,
offsetX: (sticker.offsetX ?? 0) + delta[0],
offsetY: (sticker.offsetY ?? 0) + delta[1],
}
: sticker,
);
saveStickers(stickers); // your own storage
});State
viewer.state is the viewer's last known state, readable at any time without waiting.
weaponnull.glovesnull.agentnull.subjectviewactive: whether it is on screen yet, false while it loads.environmentbackgroundwatermarkstickersuid that focus takes.charmnull.charmAnchorpatchespatchSlotsnull until known.playinganimationnull.animationsagentAnimationnull.agentAnimationssoundfirstPersonfacingplacementnull.Capabilities
viewer.capabilities says, for each view and feature, whether your plan includes it (entitled) and whether the current scene can serve it (available). Offer a control only when both are true.
const { entitled, available } = viewer.capabilities.features.placeStickers;
if (entitled && available) {
await viewer.armPlacement({ target: { kind: 'sticker', slot: 1 } });
}Views, under capabilities.views:
freefirstPersonthirdPersonFeatures, under capabilities.features:
selectWeaponsetWeapon, catalog.weapons).selectGlovessetGloves).selectAgentsetAgent, catalog.agents, catalog.weaponModels).selectEnvironmentsetEnvironment, catalog.environments).editSeededitFloateditStattrakeditNametagselectStickerselectCharmselectPatcheditStickerseditCharmsplaceStickersarmPlacement).placeCharmarmPlacement).screenshotcapture).inspectLinksubjectControlssetFacing, setFirstPersonSettings, setSound).weaponAnimationsagentAnimationscustomBackgroundsetBackground with custom).customWatermarksetWatermark with custom).Error codes
A command that fails rejects with an error that has a code and a message. Branch on the code: the message is for your logs and may change.
invalid_keyorigin_not_allowednot_entitledunsupported_viewunavailable_iteminvalid_argumentnot_readyinternalrefusedfamily says who can fix it, and refusalCode gives the reason, as a code.