Home Reference Source

src/calls/CallLogEntry.js

import {CallDirection} from './CallDirection';
import {CallEndReason} from './CallEndReason';
import {CallStatus} from './CallStatus';

export class CallLogEntry {
	/**
	 * @private
	 */
	constructor(id, callee, caller, target, from, to, status, endReason, direction, origin = {}, data = '') {
		/** @private */
		this.id = id;

		/** @private */
		this.callee = callee;

		/** @private */
		this.caller = caller;

		/** @private */
		this.target = target;

		/** @private */
		this.from = from;

		/** @private */
		this.to = to;

		/** @private */
		this.status = status;

		/** @private */
		this.endReason = endReason;

		/** @private */
		this.direction = direction;

		/** @private */
		this.origin = origin;

		/** @private */
		this.data = data;
	}

	/**
	 * @return {string}
	 */
	getId() {
		return this.id;
	}

	/**
	 * Initial callee, before any redirection.
	 * @return {CallDirection}
	 */
	getCallee() {
		return this.callee;
	}

	/**
	 * @return {String}
	 */
	getCaller() {
		return this.caller;
	}

	/**
	 * @return {String}
	 */
	getTarget() {
		return this.target;
	}

	/**
	 * Timestamp of call creation.
	 * @return {Date}
	 */
	getFrom() {
		return this.from;
	}

	/**
	 * Timestamp of call finalization.
	 * @return {Date}
	 */
	getTo() {
		return this.to;
	}

	/**
	 * @return {CallStatus}
	 */
	getStatus() {
		return this.status;
	}

	/**
	 * @type {CallEndReason}
	 */
	getEndReason() {
		return this.endReason;
	}

	/**
	 * @return {CallDirection}
	 */
	getDirection() {
		return this.direction;
	}

	/**
	 * @return {String}
	 */
	getOrigin() {
		return this.origin;
	}

	/**
	 * Origin caller information with next fields:
	 * - useragent: caller's browser useragent
	 * - language: caller's browser language
	 * - location: URL loaded by caller
	 * - ip: caller IP address
	 * @return {Object}
	 */
	getData() {
		return this.data;
	}

	/**
	 * Get call duration in ms
	 * @return {number} Call duration.
	 */
	getDuration() {
		if (this.status === CallStatus.CONNECTED) {
			return Date.now() - this.from;
		}
		return this.to - this.from;
	}

	/**
	 * Gets the address of the remote participant. It can be a wac address if
	 * it is from a wac user or not if it is from an external user
	 * @returns {String}
	 */
	getRemoteAddress() {
		return this.direction === CallDirection.INCOMING ? this.caller : this.callee;
	}

	isEnded() {
		return this.status === CallStatus.FINISHED;
	}

	isIncoming() {
		return this.direction === CallDirection.INCOMING;
	}

	isOutgoing() {
		return this.direction === CallDirection.OUTGOING;
	}

	isMissed() {
		return this.isIncoming() && (this.endReason === CallEndReason.NO_ANSWER ||
			this.endReason === CallEndReason.ORIGINATOR_CANCEL);
	}
}