ModulesEvent Module

Event

The Event module in ZDK manages live, single-session events such as webinars, AMAs, workshops, and concerts. It tracks user lifecycle events (join/leave) and provides a built-in chat channel for real-time interaction. Participants can post messages, ask questions, and receive announcements directly within the session interface.

The module also exposes a DASH-compliant livestream URL, which can be integrated with any compatible media player (e.g., ShakaPlayer, dash.js, video.js). This design enables developers to embed both live video and chat seamlessly, offering a self-contained solution for interactive, time-boxed sessions.

Dependencies
  • core
  • user
  • websocket

Initialization

file.ts
const event = new createEvent({
 webSocketModule: webSocket,
 userModule: user,
 config: {
   host: 'event.dev.zu.casa'
 }
});

Actions

joinEvent

Action type

(token: string) => Promise<void>

Description

It gives the client the possibility to join to selected event and connect to media server.

Parameters
  • token - a short-lived, server-issued token created on request that encodes the user’s permissions for the specific event they’re joining.
Return value

Returns a promise that resolves once the user entered the event.

Possible errors
  • ActionCallError - Can not perform this action (joinEvent) while module is not connected with WebSocket.
  • ActionCallError - You’ve already joined a event
  • other error types may occur, the list will be expanded during development

leaveEvent

Action type

() => void

Description

Removes user from the event. It automatically clears the state of the event and sets eventModule status to disconnected.

Possible errors
  • ActionCallError - Can not perform this action (leaveEvent) while module is not connected with WebSocket
  • ActionCallError - Invalid token.
  • ActionCallError - Expired token.
  • ActionCallError - Can not perform this action (leaveEvent) because you are not in any event.
  • other error types may occur, the list will be expanded during development

kickMember

Action type

(userId: string, reason?: string) => Promise<void>

Description Kicks the targeted user from the current event.

Parameters
  • userId - id of the targeted user
  • reason - cause for removing someone from an event
Return value

Returns a promise that resolves when request is successfully sent.

Possible errors
  • ActionCallError - Can not perform this action (kickMember) while module is not connected with WebSocket.
  • ActionCallError - Can not perform this action (kickMember) because you did not join any event.
  • ActionCallError - Can not perform this action (kickMember) on yourself.
  • other error types may occur, the list will be expanded during development

blockMember

Action type

(userId: string, duration: bigint, reason?: string) => Promise<void>

Description Blocks the targeted user, establishing a restriction that prevents the user from entering the current event, and if the user is currently in the event, they will be kicked out immediately. Parameters

  • userId - id of the targeted user
  • duration - time in minutes the block remains active; 0 implies a permanent block
  • reason - cause for blocking user
Return value

Returns a promise that resolves when request is successfully sent.

Possible errors
  • ActionCallError - Can not perform this action (blockMember) while module is not connected with WebSocket.
  • ActionCallError - Can not perform this action (blockMember) because you did not join any event.
  • ActionCallError - Can not perform this action (blockMember) on yourself.
  • other error types may occur, the list will be expanded during development

unblockMember

Action type

(userId: string) => Promise<void>

Description Removes the block on the targeted user, allowing entry to the event again. If the user was removed, they can now rejoin. Parameters

  • userId - id of the targeted user
Return value

Returns a promise that resolves when request is successfully sent.

Possible errors
  • ActionCallError - Can not perform this action (unblockMember) while module is not connected with WebSocket.
  • ActionCallError - Can not perform this action (unblockMember) because you did not join any event.
  • ActionCallError - Can not perform this action (unblockMember) on yourself.
  • ActionCallError - Can not perform this action (unblockMember) on member which is not blocked.
  • other error types may occur, the list will be expanded during development

generateLivestreamUrl

Action type

() => Promise<string>

Description

It gives the client the possibility to generate DASH-compliant livestream URL.

Return value

Returns a promise that resolves with livestream URL.

Possible errors
  • ActionCallError - Can not perform this action (joinEvent) while module is not connected with WebSocket.
  • ActionCallError - Can not perform this action (joinEvent) while user is not connected to an event.
  • ActionCallError - Can not perform this action (joinEvent) while event is not started yet.
  • other error types may occur, the list will be expanded during development

Data (Getters)

status

Getter output type: 'disconnected' | 'connecting' | 'connected' | 'reloading'

Description
  • disconnected - not connected to any event
  • connecting - trying to connect to selected event
  • connected - connected and data about the event is available - ready to display event UI
  • reloading - because of connection lost, the event state can be temporarily desynchronized, this state appear after we are trying to synchronize all the data again. You can still show the user the whole event UI based on old data, but you can inform them that we are ‘reloading’ it and soon user will be fully connected.

eventStatus

Getter output type: 'unavailable' | 'pending' | 'started' | 'finished' | 'canceled'

Description
  • unavailable - not connected to any event
  • pending - created but not started event
  • started - event is currently live
  • finished - event completed successfully
  • canceled - event aborted before completion

chatId

Getter output type: string | undefined

Description

Gives access to chatId associated with the event.
If the client did not enter any event, undefined will be returned.

eventId

Getter output type: string | undefined

Description

Gives access to eventId of the current event.
If the client did not enter any event, undefined will be returned.

membersAmount

Getter output type: number

Description

Gives access to a number that represents the amount of users in the event.
If the client did not enter any event, 0 will be returned.

isEventSyncing

Getter output type: boolean

Description

This value give you information if some of the data are incorrect in the state, and we are fixing it. The state might be inaccurate at the moment. It happens after connecting or reloading. When fetching event state will be interrupted by a websocket packet. If it is true you can show in UI a status that says that state is syncing or do nothing.
If the client did not enter any event, false will be returned.

Events

The module provides the following ListenerCreator:

onUserKicked

ListenerCreator output type

{ userId: string, eventId: string, reason: string}

Description

The method sets up a function that will be called whenever any user from the event (including you) is kicked from the event.