2020-04-26 11:36:41 +02:00
|
|
|
import axios from '@nextcloud/axios';
|
|
|
|
|
2020-06-04 18:56:55 +02:00
|
|
|
export enum Access {
|
|
|
|
Public = 'public',
|
|
|
|
Password = 'password',
|
|
|
|
WaitingRoom = 'waiting_room',
|
|
|
|
Internal = 'internal',
|
|
|
|
InternalRestricted = 'internal_restricted',
|
|
|
|
}
|
|
|
|
|
2020-04-26 11:36:41 +02:00
|
|
|
export interface Room {
|
2020-04-26 22:41:06 +02:00
|
|
|
id: number;
|
|
|
|
uid: string;
|
|
|
|
name: string;
|
|
|
|
welcome: string;
|
|
|
|
maxParticipants: number;
|
|
|
|
record: boolean;
|
2020-06-04 18:56:55 +02:00
|
|
|
access: Access;
|
|
|
|
password?: string;
|
2020-04-26 11:36:41 +02:00
|
|
|
}
|
|
|
|
|
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-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-05-17 16:51:26 +02:00
|
|
|
public getRoomUrl(room: Room) {
|
|
|
|
return window.location.origin + api.getUrl(`b/${room.uid}`);
|
|
|
|
}
|
|
|
|
|
2020-04-26 11:36:41 +02:00
|
|
|
public async getRooms(): Promise<Room[]> {
|
|
|
|
const response = await axios.get(this.getUrl('rooms'));
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async createRoom(name: string) {
|
|
|
|
const response = await axios.post(this.getUrl('rooms'), {
|
|
|
|
name,
|
|
|
|
welcome: '',
|
|
|
|
maxParticipants: 0,
|
|
|
|
record: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
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) {
|
|
|
|
const response = await axios.delete( this.getUrl(`rooms/${id}`));
|
|
|
|
|
|
|
|
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`;
|
|
|
|
const url = `/remote.php/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`;
|
|
|
|
const url = `/remote.php/dav/files/${OC.currentUser}${path}/${filename}`;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
public async checkServer(url: string, secret: string): Promise<'success'|'invalid-url'|'invalid:secret'> {
|
|
|
|
const response = await axios.post(this.getUrl('server/check'), {
|
|
|
|
url,
|
|
|
|
secret,
|
|
|
|
});
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
}
|
2020-04-26 11:36:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export const api = new Api();
|