Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] Video Conference Model / Collection #25458

Merged
merged 8 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions apps/meteor/app/api/server/v1/videoConference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,21 @@ API.v1.addRoute(

API.v1.addRoute(
'video-conference.start',
{ authRequired: true },
{ authRequired: true, validateParams: isVideoConfStartProps },
{
async post() {
if (!isVideoConfStartProps(this.bodyParams)) {
return API.v1.failure('invalid-params', isVideoConfStartProps.errors?.map((e) => e.message).join('\n '));
}
const { roomId } = this.bodyParams;

// #ToDo: Validate if there is an active provider

const { userId } = this;

if (!userId || !(await canAccessRoomIdAsync(this.bodyParams.roomId, userId))) {
if (!userId || !(await canAccessRoomIdAsync(roomId, userId))) {
return API.v1.failure('invalid-params');
}

return API.v1.success({
data: await startVideoConference(userId, this.bodyParams.roomId),
data: await startVideoConference(userId, roomId),
});
},
},
Expand Down
9 changes: 9 additions & 0 deletions apps/meteor/app/models/server/raw/VideoConference.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { IVideoConference } from '@rocket.chat/core-typings';

import { BaseRaw, IndexSpecification } from './BaseRaw';

export class VideoConferenceRaw extends BaseRaw<IVideoConference> {
protected modelIndexes(): IndexSpecification[] {
return [{ key: { rid: 1, status: 1, createdAt: 1 }, unique: false }];
}
}
2 changes: 2 additions & 0 deletions apps/meteor/app/models/server/raw/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import SubscriptionsModel from '../models/Subscriptions';
import UsersModel from '../models/Users';
import { PbxEventsRaw } from './PbxEvents';
import { isRunningMs } from '../../../../server/lib/isRunningMs';
import { VideoConferenceRaw } from './VideoConference';

const trashCollection = trash.rawCollection();

Expand Down Expand Up @@ -144,6 +145,7 @@ export const WebdavAccounts = new WebdavAccountsRaw(db.collection(`${prefix}webd
export const VoipRoom = new VoipRoomsRaw(db.collection(`${prefix}room`), trashCollection);
export const PbxEvent = new PbxEventsRaw(db.collection('pbx_events'), trashCollection);
export const LivechatAgentActivity = new LivechatAgentActivityRaw(db.collection(`${prefix}livechat_agent_activity`), trashCollection);
export const VideoConference = new VideoConferenceRaw(db.collection(`${prefix}video_conference`), trashCollection);

const map = {
[Messages.col.collectionName]: MessagesModel,
Expand Down
29 changes: 26 additions & 3 deletions packages/core-typings/src/IVideoConference.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { IRocketChatRecord } from './IRocketChatRecord';
import type { IUser } from './IUser';
import type { IMessage } from './IMessage';

export type DirectCallInstructions = {
type: 'direct';
Expand All @@ -13,14 +14,36 @@ export type ConferenceInstructions = {
};

export type VideoConferenceType = DirectCallInstructions['type'] | ConferenceInstructions['type'];
export interface IVideoConferenceUser extends Required<Pick<IUser, '_id' | 'username' | 'name'>> {
ts: Date;
}

export enum VideoConferenceStatus {
CALLING = 0,
STARTED = 1,
ENDED = 2,
}

export interface IVideoConference extends IRocketChatRecord {
type: VideoConferenceType;
users: Pick<IUser, '_id' | 'username' | 'name'>[];
users: IVideoConferenceUser[];
rid: string;
anonymousUsers: number;
title: string;
messages: {
calling?: IMessage['_id'];
missed?: IMessage['_id'];
started?: IMessage['_id'];
ended?: IMessage['_id'];
};
status: VideoConferenceStatus;
url?: string;

createdBy: Required<Pick<IUser, '_id' | 'username' | 'name'>>;
createdAt: Date;

_createdBy: Pick<IUser, '_id' | 'username' | 'name'>;
_createdAt: Date;
endedBy?: Required<Pick<IUser, '_id' | 'username' | 'name'>>;
endedAt?: Date;
}

export type VideoConferenceInstructions = DirectCallInstructions | ConferenceInstructions;