src/conferences/ConferenceLogEntry.ts
import {ConferenceLogEntryDto} from '../wac-proxy/wac-stack/conference-log/types';
interface Candidate {
/** Identifier of the user that received the invite */
readonly address: string;
/** A code that indicates if the candidates accepted or rejected the invite and his reason */
readonly endReason: 200|404|408|487|603;
}
interface MediaType {
/** Indicate if the creator of the invite wants to use audio in the conference */
readonly audio: boolean;
/** Indicate if the creator of the invite wants to use video in the conference */
readonly video: boolean;
}
interface Invite {
/** who sent the invite */
readonly from: string;
/** who received the invite */
readonly to: string;
/** specify what happened with the invite */
readonly state: 'ACCEPTED' | 'DECLINED_BY_CREATOR' | 'DECLINED_BY_TIMEOUT' | 'DECLINED';
/** List of candidates that received the invite */
readonly candidates: readonly Candidate[];
/** Set to true when the invite is sent to a group */
readonly group: boolean;
/** Set to true when the invite is related with an invitation request */
readonly inviteRequest: boolean;
/** Indicates the media used in the conference */
readonly mediatypes: MediaType;
/** Code error when an invite is declined */
readonly error: 200|404|408|487|603;
/** @deprecated Use candidates instead */
getCandidates(): Array<{
address: string;
state: 'accepted' | 'missed' | 'rejected' | undefined;
direction: 'incoming';
type: 'invite';
group: boolean;
}>;
}
interface Transfer {
/** Who creates the call-transfer */
from: string;
/** Who has to receive the call transferred */
to: string;
/** State of the call transfer */
state: 'DECLINED' | 'INVITED';
/** Identifier of the room */
roomId: string;
/** Identifier of the invite related with the transfer */
idInvite: string;
/** @deprecated Use participants instead*/
getParticipants(): [{
address: string;
state: 'accepted' | 'missed' | 'rejected' | undefined;
direction: 'incoming'|'outgoing';
}, {
address: string;
state: 'accepted' | 'missed' | 'rejected' | undefined;
direction: 'incoming'|'outgoing';
}];
}
interface Participant {
/** Identifier of the user that entried in the room */
address: string;
/** Timestamp of when user inserted in the room */
createdAt: number;
/** Timestamp of when user left the room */
finishedAt: number;
}
const getState = (
state: 'ACCEPTED' | 'DECLINED_BY_CREATOR' | 'DECLINED_BY_TIMEOUT' | 'DECLINED' | 'INVITED' | 200 | 404 | 408 | 487 | 603,
direction: 'incoming' | 'outgoing',
): 'accepted' | 'missed' | 'rejected' | undefined => {
switch (state) {
case 'ACCEPTED':
case 200:
return 'accepted';
case 'DECLINED':
case 603:
return 'rejected';
case 'DECLINED_BY_CREATOR':
return direction === 'outgoing' ? 'rejected' : 'missed';
case 'DECLINED_BY_TIMEOUT':
case 408:
return 'missed';
}
};
/**
* This class allows access to the details of each entry of the conference log
* @link {ConferenceLog#.getEntries()} method should be used to obtain the list
* of instances of this class.
*/
export class ConferenceLogEntry {
/** The unique id that identifies the conference log entry */
readonly id: string;
/** The time the conference started */
readonly startTimestamp: number;
/** The time the conference ended */
readonly endTimestamp: number;
/** The list of users that have been inside the room */
readonly participants: readonly Participant[];
/** The list of all the invites that have been sent in the room */
readonly invites: readonly Invite[];
/** The list of all the transfers that have been performed in the room */
readonly transfers: readonly Transfer[];
static of(data: ConferenceLogEntryDto): ConferenceLogEntry {
return new ConferenceLogEntry(data);
}
private constructor(data: ConferenceLogEntryDto) {
this.id = data.id;
this.startTimestamp = data.createdAt;
this.endTimestamp = data.finishedAt;
this.participants = data.participants;
this.invites = (data.invites || []).map(invite => ({
...invite,
getCandidates() {
return invite.candidates.map(candidate => ({
address: candidate.address,
state: getState(invite.group ? candidate.endReason : invite.state, 'incoming'),
direction: 'incoming',
type: 'invite',
group: invite.group,
}));
},
}));
this.transfers = (data.transfers || []).map(transfer => ({
...transfer,
getParticipants() {
return [{
address: transfer.from,
state: getState(transfer.state, 'outgoing'),
direction: 'outgoing',
}, {
address: transfer.to,
state: getState(transfer.state, 'incoming'),
direction: 'incoming',
}];
},
}));
}
/** @deprecated Use id property */
getId(): string {
return this.id;
}
/**
* Conference length in ms
* @deprecated Use startTimestamp and endTimestamp properties
*/
getDuration(): number {
return this.endTimestamp - this.startTimestamp;
}
/** @deprecated Use startTimestamp property */
getStartTimestamp(): number {
return this.startTimestamp;
}
/** @deprecated Use startTimestamp property */
getStartDateTime(): Date {
return new Date(this.startTimestamp);
}
/** @deprecated Use endTimestamp property */
getEndDateTime(): Date {
return new Date(this.endTimestamp);
}
/** @deprecated Use participants property */
getParticipants(): readonly Participant[] {
return this.participants;
}
/** @deprecated Use invites property */
getInvites(): readonly Invite[] {
return this.invites;
}
/** @deprecated Use transfers property */
getTransfers(): readonly Transfer[] {
return this.transfers;
}
}