0.10.2 • Published 4 months ago
megaphone-client v0.10.2
Megaphone Client
Typescript and Javascript library to subscribe to Megaphone channels.
Usage
Example usage:
import { MegaphonePoller } from 'megaphone-client';
import { firstValueFrom } from 'rxjs';
const poller = new MegaphonePoller('http://localhost:3000');
const o = await poller.newUnboundedStream<{ message: string, sender: string }>(async channel => {
let res = await fetch('http://localhost:3040/room/test', {
method: 'POST',
headers: {
...(channel ? { 'use-channel': channel } : {}),
},
}).then(res => res.json());
return {
channelId: res.channelUuid,
streamIds: ['new-message'],
}
});
const chunk = await firstValueFrom(o);
console.log(chunk.body.message);
See Megaphone demo for more complete examples.