megaphone-client
v0.10.3
Published
Client library to subscribe megaphone channels
Downloads
17
Readme
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', 100);
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 {
channelAddress: { consumer: res.channelUuid, producer: '' },
streamIds: ['new-message'],
}
});
const chunk = await firstValueFrom(o);
console.log(chunk.body.message);See Megaphone demo for more complete examples.
