2020-04-26 11:36:41 +02:00
|
|
|
import axios from '@nextcloud/axios';
|
|
|
|
|
2020-08-29 13:20:28 +02:00
|
|
|
export enum ShareType {
|
2020-10-22 11:00:15 +02:00
|
|
|
User = 0, // OC.Share.SHARE_TYPE_USER
|
|
|
|
Group = 1, // OC.Share.SHARE_TYPE_GROUP
|
|
|
|
Circle = 7, // OC.Share.SHARE_TYPE_CIRCLE
|
2020-09-01 09:48:24 +02:00
|
|
|
}
|
2020-06-15 17:23:53 +02:00
|
|
|
|
2020-09-01 09:48:24 +02:00
|
|
|
export enum Permission { Admin, Moderator, User }
|
2020-06-15 17:23:53 +02:00
|
|
|
|
2020-06-04 18:56:55 +02:00
|
|
|
export enum Access {
|
|
|
|
Public = 'public',
|
|
|
|
Password = 'password',
|
|
|
|
WaitingRoom = 'waiting_room',
|
2022-03-08 15:09:18 +01:00
|
|
|
WaitingRoomAll = 'waiting_room_all',
|
2020-06-04 18:56:55 +02:00
|
|
|
Internal = 'internal',
|
|
|
|
InternalRestricted = 'internal_restricted',
|
|
|
|
}
|
|
|
|
|
2020-08-27 17:21:34 +02:00
|
|
|
export interface Restriction {
|
|
|
|
id: number;
|
|
|
|
groupId: string;
|
|
|
|
maxRooms: number;
|
|
|
|
roomTypes: string[];
|
|
|
|
maxParticipants: number;
|
|
|
|
allowRecording: boolean;
|
2022-03-16 18:43:44 +01:00
|
|
|
allowLogoutURL: boolean;
|
2020-08-27 17:21:34 +02:00
|
|
|
}
|
|
|
|
|
2020-04-26 11:36:41 +02:00
|
|
|
export interface Room {
|
2020-04-26 22:41:06 +02:00
|
|
|
id: number;
|
|
|
|
uid: string;
|
2020-06-17 10:56:28 +02:00
|
|
|
userId: string;
|
2020-04-26 22:41:06 +02:00
|
|
|
name: string;
|
|
|
|
welcome: string;
|
|
|
|
maxParticipants: number;
|
|
|
|
record: boolean;
|
2020-06-04 18:56:55 +02:00
|
|
|
access: Access;
|
|
|
|
password?: string;
|
2020-06-17 08:19:54 +02:00
|
|
|
everyoneIsModerator: boolean;
|
2020-08-29 14:37:50 +02:00
|
|
|
requireModerator: boolean;
|
2020-09-08 17:01:50 +02:00
|
|
|
shared: boolean;
|
2021-01-22 19:12:55 +01:00
|
|
|
moderatorToken: string;
|
2021-04-19 14:47:15 +02:00
|
|
|
listenOnly: boolean,
|
|
|
|
mediaCheck: boolean,
|
|
|
|
cleanLayout: boolean,
|
2021-07-30 12:12:42 +02:00
|
|
|
joinMuted: boolean,
|
2022-03-16 18:43:44 +01:00
|
|
|
logoutURL: string,
|
2020-04-26 11:36:41 +02:00
|
|
|
}
|
|
|
|
|
2020-06-15 17:23:53 +02:00
|
|
|
export interface RoomShare {
|
|
|
|
id: number;
|
|
|
|
roomId: number;
|
|
|
|
shareType: ShareType;
|
|
|
|
shareWith: string;
|
|
|
|
shareWithDisplayName?: string;
|
|
|
|
permission: Permission;
|
|
|
|
}
|
|
|
|
|
2020-05-17 11:09:16 +02:00
|
|
|
export type Recording = {
|
|
|
|
id: string;
|
|
|
|
name: string;
|
|
|
|
published: boolean;
|
|
|
|
state: 'processing' | 'processed' | 'published' | 'unpublished' | 'deleted';
|
|
|
|
startTime: number;
|
|
|
|
participants: number;
|
|
|
|
type: string;
|
|
|
|
length: number;
|
|
|
|
url: string;
|
|
|
|
meta: any;
|
|
|
|
}
|
|
|
|
|
2020-08-25 15:18:10 +02:00
|
|
|
export interface ShareWithOption {
|
|
|
|
label: string;
|
|
|
|
value: {
|
|
|
|
shareType: ShareType;
|
|
|
|
shareWith: string;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-06-15 17:23:53 +02:00
|
|
|
export interface ShareWith {
|
2020-08-25 15:18:10 +02:00
|
|
|
users: ShareWithOption[];
|
|
|
|
groups: ShareWithOption[];
|
2020-08-29 13:20:28 +02:00
|
|
|
circles: ShareWithOption[];
|
2021-01-25 18:39:35 +01:00
|
|
|
exact: {
|
|
|
|
users: ShareWithOption[];
|
|
|
|
groups: ShareWithOption[];
|
|
|
|
circles: ShareWithOption[];
|
|
|
|
}
|
2020-06-15 17:23:53 +02:00
|
|
|
}
|
|
|
|
|
2020-04-26 11:36:41 +02:00
|
|
|
class Api {
|
|
|
|
public getUrl(endpoint: string): string {
|
2020-04-26 13:26:34 +02:00
|
|
|
return OC.generateUrl(`apps/bbb/${endpoint}`);
|
2020-04-26 11:36:41 +02:00
|
|
|
}
|
|
|
|
|
2020-08-27 17:21:34 +02:00
|
|
|
public async getRestriction(): Promise<Restriction> {
|
|
|
|
const response = await axios.get(this.getUrl('restrictions/user'));
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async getRestrictions(): Promise<Restriction[]> {
|
|
|
|
const response = await axios.get(this.getUrl('restrictions'));
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async createRestriction(groupId: string) {
|
|
|
|
const response = await axios.post(this.getUrl('restrictions'), {
|
|
|
|
groupId,
|
|
|
|
});
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async updateRestriction(restriction: Restriction) {
|
|
|
|
if (!restriction.id) {
|
|
|
|
const newRestriction = await this.createRestriction(
|
|
|
|
restriction.groupId
|
|
|
|
);
|
|
|
|
|
|
|
|
restriction.id = newRestriction.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
const response = await axios.put(this.getUrl(`restrictions/${restriction.id}`), restriction);
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async deleteRestriction(id: number) {
|
|
|
|
const response = await axios.delete(this.getUrl(`restrictions/${id}`));
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
}
|
|
|
|
|
2021-01-22 19:12:55 +01:00
|
|
|
public getRoomUrl(room: Room, forModerator = false) {
|
2020-09-23 09:13:26 +02:00
|
|
|
const shortener = document.getElementById('bbb-root')?.getAttribute('data-shortener') || '';
|
2021-01-22 19:12:55 +01:00
|
|
|
const token = (forModerator && room.moderatorToken) ? `${room.uid}/${room.moderatorToken}` : room.uid;
|
2020-09-23 09:13:26 +02:00
|
|
|
|
|
|
|
if (shortener) {
|
2021-01-22 19:12:55 +01:00
|
|
|
return shortener
|
|
|
|
.replace(/\{user\}/g, room.userId)
|
|
|
|
.replace(/\{token\}/g, token);
|
2020-09-23 09:13:26 +02:00
|
|
|
}
|
|
|
|
|
2021-01-22 19:12:55 +01:00
|
|
|
return window.location.origin + api.getUrl(`b/${token}`);
|
2020-05-17 16:51:26 +02:00
|
|
|
}
|
|
|
|
|
2020-04-26 11:36:41 +02:00
|
|
|
public async getRooms(): Promise<Room[]> {
|
|
|
|
const response = await axios.get(this.getUrl('rooms'));
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
}
|
|
|
|
|
2020-08-27 17:21:34 +02:00
|
|
|
public async createRoom(name: string, access: Access = Access.Public, maxParticipants = 0) {
|
2020-04-26 11:36:41 +02:00
|
|
|
const response = await axios.post(this.getUrl('rooms'), {
|
|
|
|
name,
|
|
|
|
welcome: '',
|
2020-08-27 17:21:34 +02:00
|
|
|
maxParticipants,
|
2020-04-26 11:36:41 +02:00
|
|
|
record: false,
|
2020-08-27 17:21:34 +02:00
|
|
|
access,
|
2020-04-26 11:36:41 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async updateRoom(room: Room) {
|
|
|
|
const response = await axios.put(this.getUrl(`rooms/${room.id}`), room);
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async deleteRoom(id: number) {
|
2020-06-15 17:23:53 +02:00
|
|
|
const response = await axios.delete(this.getUrl(`rooms/${id}`));
|
2020-04-26 11:36:41 +02:00
|
|
|
|
|
|
|
return response.data;
|
|
|
|
}
|
2020-05-17 11:09:16 +02:00
|
|
|
|
|
|
|
public async getRecordings(uid: string) {
|
|
|
|
const response = await axios.get(this.getUrl(`server/${uid}/records`));
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async deleteRecording(id: string) {
|
|
|
|
const response = await axios.delete(this.getUrl(`server/record/${id}`));
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async storeRecording(recording: Recording, path: string) {
|
|
|
|
const startDate = new Date(recording.startTime);
|
2020-05-17 16:51:26 +02:00
|
|
|
const filename = `${encodeURIComponent(recording.name + ' ' + startDate.toISOString())}.url`;
|
2020-11-19 16:21:55 +01:00
|
|
|
const url = OC.linkToRemote(`dav/files/${OC.currentUser}${path}/${filename}`);
|
2020-05-17 11:09:16 +02:00
|
|
|
|
2020-05-17 16:51:26 +02:00
|
|
|
await axios.put(url, `[InternetShortcut]\nURL=${recording.url}`);
|
|
|
|
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async storeRoom(room: Room, path: string) {
|
|
|
|
const filename = `${encodeURIComponent(room.name)}.url`;
|
2020-11-19 16:21:55 +01:00
|
|
|
const url = OC.linkToRemote(`dav/files/${OC.currentUser}${path}/${filename}`);
|
2020-05-17 16:51:26 +02:00
|
|
|
|
|
|
|
await axios.put(url, `[InternetShortcut]\nURL=${this.getRoomUrl(room)}`);
|
|
|
|
|
|
|
|
return filename;
|
2020-05-17 11:09:16 +02:00
|
|
|
}
|
2020-05-17 13:39:01 +02:00
|
|
|
|
2020-06-15 17:23:53 +02:00
|
|
|
public async checkServer(url: string, secret: string): Promise<'success' | 'invalid-url' | 'invalid:secret'> {
|
2020-05-17 13:39:01 +02:00
|
|
|
const response = await axios.post(this.getUrl('server/check'), {
|
|
|
|
url,
|
|
|
|
secret,
|
|
|
|
});
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
}
|
2020-06-15 17:23:53 +02:00
|
|
|
|
|
|
|
public async getRoomShares(roomId: number): Promise<RoomShare[]> {
|
|
|
|
const response = await axios.get(this.getUrl('roomShares'), {
|
|
|
|
params: {
|
|
|
|
id: roomId,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async createRoomShare(roomId: number, shareType: ShareType, shareWith: string, permission: Permission): Promise<RoomShare> {
|
|
|
|
const response = await axios.post(this.getUrl('roomShares'), {
|
|
|
|
roomId,
|
|
|
|
shareType,
|
|
|
|
shareWith,
|
|
|
|
permission,
|
|
|
|
});
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async deleteRoomShare(id: number) {
|
|
|
|
const response = await axios.delete(this.getUrl(`roomShares/${id}`));
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
}
|
|
|
|
|
2020-08-27 17:21:34 +02:00
|
|
|
public async getRecommendedShareWith(shareType: ShareType[] = [OC.Share.SHARE_TYPE_USER, OC.Share.SHARE_TYPE_GROUP]): Promise<ShareWith> {
|
2020-06-15 17:23:53 +02:00
|
|
|
const url = OC.linkToOCS('apps/files_sharing/api/v1', 1) + 'sharees_recommended';
|
|
|
|
const response = await axios.get(url, {
|
|
|
|
params: {
|
2020-08-27 17:21:34 +02:00
|
|
|
shareType,
|
2020-06-15 17:23:53 +02:00
|
|
|
itemType: 'room',
|
|
|
|
format: 'json',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
2021-01-25 18:39:35 +01:00
|
|
|
users: [],
|
|
|
|
groups: [],
|
|
|
|
circles: [],
|
|
|
|
exact: {
|
|
|
|
users: response.data.ocs.data.exact.users,
|
|
|
|
groups: response.data.ocs.data.exact.groups,
|
|
|
|
circles: response.data.ocs.data.exact.circles || [],
|
|
|
|
},
|
2020-06-15 17:23:53 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-08-27 17:21:34 +02:00
|
|
|
public async searchShareWith(search = '', shareType: ShareType[] = [OC.Share.SHARE_TYPE_USER, OC.Share.SHARE_TYPE_GROUP]): Promise<ShareWith> {
|
2020-06-15 17:23:53 +02:00
|
|
|
const url = OC.linkToOCS('apps/files_sharing/api/v1', 1) + 'sharees';
|
|
|
|
const response = await axios.get(url, {
|
|
|
|
params: {
|
|
|
|
search,
|
2020-08-27 17:21:34 +02:00
|
|
|
shareType,
|
2020-06-15 17:23:53 +02:00
|
|
|
itemType: 'room',
|
|
|
|
format: 'json',
|
|
|
|
lookup: false,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-08-26 15:54:55 +02:00
|
|
|
const data = response.data.ocs.data;
|
|
|
|
|
2020-06-15 17:23:53 +02:00
|
|
|
return {
|
2021-01-25 18:39:35 +01:00
|
|
|
users: data.users,
|
|
|
|
groups: data.groups,
|
|
|
|
circles: data.circles || [],
|
|
|
|
exact: {
|
|
|
|
users: data.exact.users,
|
|
|
|
groups: data.exact.groups,
|
|
|
|
circles: data.exact.circles || [],
|
|
|
|
},
|
2020-06-15 17:23:53 +02:00
|
|
|
};
|
|
|
|
}
|
2020-04-26 11:36:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export const api = new Api();
|