Skip to content

API

Omega Methods

watch(function: callback)

Watch the broadcast messages within the app-wide scope.

omega.watch((msg) => console.log(msg));

connect(): Session

Open the WebSocket connection.

const session = await omega.connect();

createChannel(object: { string: name }): Channel

Create and join a new channel.

const ch = await omega.createChannel({
  name: 'channel',
});

joinChannel(object: { string: channelId, string: ownerKey, string: participatorKey }): Channel

Join an existing channel with an owner key or a participator key.

const ch = await omega.createChannel({
  channelId: 'CHANNEL_ID',
  ownerKey: 'OWNER_KEY',
  participatorKey: 'PARTICIPATOR_KEY',
});

playbackChannel(object: { string: channelId, number: endedAt = 0, bool: inverse = false, number: volume = 0 }): ChannelPlayer

Playback channel messages in a target channel.

const player = await omega.playbackChannel({
  channelId: 'CHANNEL_ID',
  endedAt: 1625068800,
  inverse: false,
  volume: 0,
});
await player.next();
await player.next();
await player.next();
// ...

createVote(object: { string: name, array: voteOptions, number: idleTimeout = 300, object: options = {} }): Vote

Create and join a new vote.

const vote = await omega.createVote({
  name: 'vote',
  voteOptions: [
    { name: 'opt 1' },
    { name: 'opt 2' },
  ],
});

joinVote(object: { string: voteId, string: voteKey }): Vote

Join an existing vote with or without a vote key.

const vote = await omega.joinVote({
  voteId: 'VOTE_ID',
  voteKey: 'VOTE_KEY',
});

ping(): Pong

Ping service to check connection status.

const msg = await omega.ping();

broadcast(string: message): Broadcast

Broadcast message to app-wide scope.

const msg = await omega.broadcast('hello');

hello(): Hello

Say hello to server, service will return current session ID.

const msg = await omega.hello();

time(): ServerTime

Get current server time.

const msg = await omega.time();

disconnect()

Close the WebSocket connection.

await omega.disconnect();

ChannelPlayer Methods

next(): PlaybackChannelMessage

Playback next channel messages for the player. If next returns null, subsequent calls will also return null.

await player.next();

Session Methods

watch(function: callback)

Watch the broadcast messages within the session scope.

session.watch((msg) => console.log(msg));

getMeta(): GetSessionMeta

Get metadata of current session.

const msg = await session.getMeta();

setMeta(string: name, object: data): SetSessionMeta

Set metadata for current session.

const msg = await session.setSessionMeta('anonymous', { foo: 'bar' });

sendMessage(string: toSessionId, string: message): SessionMessage

Send a message to target session.

const msg = await session.sendMessage('TO_SESSION_ID', 'hello');

Channel Methods

watch(function: callback)

Watching the broadcast messages within the channel scope.

ch.watch((msg) => console.log(msg));

getMeta(): GetChannelMeta

Get metadata of a channel.

const msg = await ch.getMeta();

setMeta(object: data): SetChannelMeta

Set metadata for channel, only owner can.

const msg = await ch.setMeta({ foo: 'bar' });

leave(): LeaveChannel

Leave a channel.

const msg = await ch.leave();

close(): CloseChannel

Close a channel, only owner can.

const msg = await ch.close();

sendMessage(string: message, object: metadata): ChannelMessage | ChannelOwnerMessage

Send a message to channel.

const msg = await ch.sendMessage('hello', { foo: 'bar' });

getCount(): ChannelCount

Get session count of target channel.

const msg = await ch.getCount();

replay(): ReplayChannelMessage

Replay channel messages in an active channel. If next returns null, subsequent calls will also return null.

const opts = {
  inverse: true,
  volume: 0,
};
await ch.replay(opts);
await ch.replay(opts);
await ch.replay(opts);
// ...

Vote Methods

watch(function: callback)

Watching the broadcast messages within the vote scope.

vote.watch((msg) => console.log(msg));

getMeta(): GetVoteMeta

Get metadata of a vote.

const msg = await vote.getMeta();

setMeta(object: data): SetVoteMeta

Set metadata for vote, only owner can.

const msg = await vote.setMeta({ foo: 'bar' });

leave(): LeaveVote

Leave a vote.

const msg = await vote.leave();

close(): CloseVote

Close a vote, only owner can.

const msg = await vote.close();

sendMessage(string: message, object: metadata): VoteMessage | VoteOwnerMessage

Send a message to vote.

const msg = await vote.sendMessage('hello', { foo: 'bar' });

selectOption(string: voteOptionId): VoteSelect

Select a option of vote.

const msg = await vote.selectOption('VOTE_OPTION_ID');

getCount(string: voteKey = ''): VoteCount

Get count of each vote option.

const msg = await vote.getCount();

Get count and subject list of each vote option.

const msg = await vote.getCount('VOTE_KEY');

setStatus(number: status): VoteStatus

Set vote status to allow (1) or deny (0), only owner can.

const msg = await vote.setStatus(0);