/
events.ts
35 lines (30 loc) · 987 Bytes
/
events.ts
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
26
27
28
29
30
31
32
33
34
35
import { Match, check } from 'meteor/check';
import { VoipClientEvents } from '@rocket.chat/core-typings';
import { VoipRoom } from '@rocket.chat/models';
import { LivechatVoip } from '@rocket.chat/core-services';
import { API } from '../../api';
import { canAccessRoom } from '../../../../authorization/server';
API.v1.addRoute(
'voip/events',
{ authRequired: true, permissionsRequired: ['view-l-room'] },
{
async post() {
check(this.requestParams(), {
event: Match.Where((v: string) => {
return Object.values<string>(VoipClientEvents).includes(v);
}),
rid: String,
comment: Match.Maybe(String),
});
const { rid, event, comment } = this.requestParams();
const room = await VoipRoom.findOneVoipRoomById(rid);
if (!room) {
return API.v1.notFound();
}
if (!canAccessRoom(room, this.user)) {
return API.v1.unauthorized();
}
return API.v1.success(await LivechatVoip.handleEvent(event, room, this.user, comment));
},
},
);