-
Notifications
You must be signed in to change notification settings - Fork 532
Expand file tree
/
Copy pathbreakoutRoomsService.js
More file actions
178 lines (166 loc) · 5.6 KB
/
breakoutRoomsService.js
File metadata and controls
178 lines (166 loc) · 5.6 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/**
* @copyright Copyright (c) 2022 Marco Ambrosini <marcoambrosini@pm.me>
*
* @author Marco Ambrosini <marcoambrosini@pm.me>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'
/**
* Create breakout rooms for a given conversation
*
* @param {string} token The conversation token
* @param {string} mode Either manual, auto, or free, see constants file
* @param {number} amount The amount of breakout rooms to be created
* @param {string} attendeeMap A json encoded Map of attendeeId => room number (0 based)
* (Only considered when the mode is "manual")
* @return {Promise<import('axios').AxiosResponse<any>>}
*/
const configureBreakoutRooms = async function(token, mode, amount, attendeeMap) {
return await axios.post(generateOcsUrl('/apps/spreed/api/v1/breakout-rooms/{token}', { token }), {
mode,
amount,
attendeeMap,
})
}
/**
* Resets the request assistance
*
* @param {string} token the breakout room token
* @param {string} attendeeMap A json encoded Map of attendeeId => room number (0 based)
* @return {Promise<import('axios').AxiosResponse<any>>} The array of conversations
*/
const reorganizeAttendees = async function(token, attendeeMap) {
return await axios.post(generateOcsUrl('/apps/spreed/api/v1/breakout-rooms/{token}/attendees', {
token,
}), {
attendeeMap,
}
)
}
/**
* Deletes all breakout rooms for a given conversation
*
* @param {string} token The conversation token
* @return {Promise<import('axios').AxiosResponse<any>>}
*/
const deleteBreakoutRooms = async function(token) {
return await axios.delete(generateOcsUrl('/apps/spreed/api/v1/breakout-rooms/{token}', { token }))
}
/**
* Fetches the breakout rooms for given conversation
*
* @param {string} token The conversation token
* @return {Promise<import('axios').AxiosResponse<any>>} The array of conversations
*/
const getBreakoutRooms = async function(token) {
return await axios.get(generateOcsUrl('/apps/spreed/api/v4/room/{token}/breakout-rooms', { token }))
}
/**
*
* @param {string} token The conversation token
* @return {Promise<import('axios').AxiosResponse<any>>} The array of conversations
*/
const startBreakoutRooms = async function(token) {
return await axios.post(generateOcsUrl('/apps/spreed/api/v1/breakout-rooms/{token}/rooms', { token }))
}
/**
* Stops the breakout rooms
*
* @param {string} token The conversation token
* @return {Promise<import('axios').AxiosResponse<any>>} The array of conversations
*/
const stopBreakoutRooms = async function(token) {
return await axios.delete(generateOcsUrl('/apps/spreed/api/v1/breakout-rooms/{token}/rooms', { token }))
}
/**
* @param {string} token the conversation token
* @param {string} message The message to be posted
* @return {Promise<import('axios').AxiosResponse<any>>} The array of conversations
*/
const broadcastMessageToBreakoutRooms = async function(token, message) {
return await axios.post(generateOcsUrl('/apps/spreed/api/v1/breakout-rooms/{token}/broadcast', {
token,
}), {
message,
token,
})
}
/**
*
* @param {string} token the conversation token
* @return {Promise<import('axios').AxiosResponse<any>>} The array of conversations
*/
const fetchBreakoutRoomsParticipants = async function(token) {
return await axios.get(generateOcsUrl('/apps/spreed/api/v4/room/{token}/breakout-rooms/participants', {
token,
}))
}
/**
* Requests assistance from a moderator
*
* @param {string} token the breakout room token
* @return {Promise<import('axios').AxiosResponse<any>>} The array of conversations
*/
const requestAssistance = async function(token) {
return await axios.post(generateOcsUrl('/apps/spreed/api/v1/breakout-rooms/{token}/request-assistance', {
token,
})
)
}
/**
* Resets the request assistance
*
* @param {string} token the breakout room token
* @return {Promise<import('axios').AxiosResponse<any>>} The array of conversations
*/
const dismissRequestAssistance = async function(token) {
return await axios.delete(generateOcsUrl('/apps/spreed/api/v1/breakout-rooms/{token}/request-assistance', {
token,
})
)
}
/**
* This endpoint allows participants to switch between breakout rooms when they are allowed to choose the breakout room
* and not are automatically or manually assigned by the moderator.
*
* @param {string} token Conversation token of the parent room hosting the breakout rooms
* @param {string} target Conversation token of the target breakout room
* @return {Promise<import('axios').AxiosResponse<any>>} The target breakout room
*/
const switchToBreakoutRoom = async function(token, target) {
return await axios.post(generateOcsUrl('/apps/spreed/api/v1/breakout-rooms/{token}/switch', {
token,
}), {
target,
}
)
}
export {
configureBreakoutRooms,
reorganizeAttendees,
deleteBreakoutRooms,
getBreakoutRooms,
startBreakoutRooms,
stopBreakoutRooms,
broadcastMessageToBreakoutRooms,
fetchBreakoutRoomsParticipants,
requestAssistance,
dismissRequestAssistance,
switchToBreakoutRoom,
}