Home Reference Source

src/meetings/Meeting.ts

import {Set} from 'immutable';

import {MeetingParticipant} from './MeetingParticipant';

export interface MeetingParameters {
	id: string;
	name: string;
	creator: string;
	participants: Iterable<MeetingParticipant>;
	language: string;
	validSince: number;
	validUntil: number;
	url: string;
	phone: string;
	isPasswordProtected: boolean;
}

/**
 * Represents a meeting. This class is immutable.
 * All the properties are readonly and must never be changed.
 * Instances of this class are usually obtained using {@link MeetingManager}
 */
export class Meeting {
	readonly id: string;
	readonly name: string;
	readonly creator: string;
	readonly participants: Set<MeetingParticipant>;
	readonly language: string;
	readonly validSince: number;
	readonly validUntil: number;
	readonly url: string;
	readonly phone: string;
	readonly isPasswordProtected: boolean;

	/** @ignore */
	constructor(data: MeetingParameters) {
		/**
		 * The ID of the meeting
		 * @type {string}
		 */
		this.id = data.id;
		/**
		 * The name for the meeting
		 * @type {string}
		 */
		this.name = data.name;
		/**
		 * The address of the meeting creator
		 * @type {string}
		 */
		this.creator = data.creator;
		/**
		 * The people participating in the meeting
		 * @type {ImmutableSet<string>}
		 */
		this.participants = Set(data.participants);
		/**
		 * The language for the meeting
		 * @type {string}
		 */
		this.language = data.language;
		/**
		 * The starting time for the meeting
		 * @type {number}
		 */
		this.validSince = data.validSince;
		/**
		 * The ending time for the meeting
		 * @type {number}
		 */
		this.validUntil = data.validUntil;
		/**
		 * The link to access to the meeting
		 * @type {string}
		 */
		this.url = data.url;
		/**
		 * Who will be called to access to the meeting
		 * @type {string}
		 */
		this.phone = data.phone;

		/**
		 * Is this meeting password protected
		 * @type {boolean}
		 */
		this.isPasswordProtected = data.isPasswordProtected;
	}

	/**
	 * Check if the participant in a meeting is online
	 * @return {boolean}
	 */
	isOnline(): boolean {
		return this.phone !== '';
	}

	/**
	 * Returns a new meeting with the provided values changed
	 * @param {object} [options={}]
	 * @param {string} [options.name]
	 * @param {Iterable<MeetingParticipant>} [options.participants]
	 * @param {string} [options.language]
	 * @param {number} [options.validSince]
	 * @param {number} [options.validUntil]
	 * @param {string} [options.url]
	 * @param {string} [options.phone]
	 * @return {Meeting}
	 */
	with({
		name = this.name,
		participants = this.participants,
		language = this.language,
		validSince = this.validSince,
		validUntil = this.validUntil,
		url = this.url,
		phone = this.phone,
		isPasswordProtected = this.isPasswordProtected,
	}: Partial<Omit<MeetingParameters, 'creator' | 'id'>> = {}): Meeting {
		return new Meeting({
			id: this.id,
			creator: this.creator,
			name,
			participants,
			language,
			validSince,
			validUntil,
			url,
			phone,
			isPasswordProtected,
		});
	}
}