UNPKG

json-crdt-server

Version:

JSON CRDT server and syncing local-first browser client

29 lines (28 loc) 1.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.listen = void 0; const rxjs_1 = require("rxjs"); const listen = ({ t, services }) => (r) => { const Request = t.Object(t.prop('room', t.str).options({ title: 'Room ID', description: 'The ID of the room to subscribe to.', })); const Response = t.Object(t.prop('entries', t.Array(t.Ref('PresenceEntry'))), t.prop('time', t.num).options({ title: 'Current time', description: 'The current server time in milliseconds since the UNIX epoch.', })); const Func = t.Function$(Request, Response).options({ title: 'Subscribe to a room.', intro: 'Subscribes to presence updates in a room.', description: 'This method subscribes to presence updates in a room. ' + 'It returns an array of all current presence entries in the room, and then emits an update whenever ' + 'a presence entry is updated or deleted. ', }); return r.prop('presence.listen', Func, (req$) => { return req$.pipe((0, rxjs_1.switchMap)((req) => services.presence.listen$(req.room)), (0, rxjs_1.map)((entries) => ({ entries, time: Date.now(), }))); }); }; exports.listen = listen;