blob: 8b352cea3c0bb8c488c9dc81bb0bcb7bd2317555 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
import * as websocket from 'websocket';
import Xev from 'xev';
import read from '../common/read-messaging-message';
import { ParsedUrlQuery } from 'querystring';
export default function(request: websocket.request, connection: websocket.connection, subscriber: Xev, user: any): void {
const q = request.resourceURL.query as ParsedUrlQuery;
const otherparty = q.otherparty as string;
// Subscribe messaging stream
subscriber.on(`messaging-stream:${user._id}-${otherparty}`, data => {
connection.send(JSON.stringify(data));
});
connection.on('message', async (data) => {
const msg = JSON.parse(data.utf8Data);
switch (msg.type) {
case 'read':
if (!msg.id) return;
read(user._id, otherparty, msg.id);
break;
}
});
}
|