Skip to content

Instantly share code, notes, and snippets.

@simontabor
Last active October 17, 2019 20:27
Show Gist options
  • Save simontabor/6911ac30a6f214c2250fdc268973c10b to your computer and use it in GitHub Desktop.
Save simontabor/6911ac30a6f214c2250fdc268973c10b to your computer and use it in GitHub Desktop.
interface MessageAction {
action: 'subscribe' | 'unsubscribe';
message: {
// Which room to subscribe to or unsubscribe from
room: string;
// Whether to "dump" existing messages for this room
dump: boolean;
};
}
const wsMessage: MessageAction[] = [
{
action: 'subscribe',
message: {
room: 'testing',
dump: true,
},
},
];
const ws = new WebSocket(`wss://${PUBBY_HOST}`);
ws.on('open', () => {
// Subscribe to the "testing" room and request a dump of existing data
ws.send(JSON.stringify(wsMessage));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment