Home Reference Source

src/index.d.ts

/* eslint-disable @typescript-eslint/camelcase */
/* eslint-disable @typescript-eslint/explicit-member-accessibility */

import * as Immutable from 'immutable';
import {EventEmitter2} from 'eventemitter2';
import {Observable} from 'rxjs';

import {MediaTypes} from './types';
import {ManagedStream} from './media/ManagedStream';
import {LocalMediaHandler} from './media/LocalMediaHandler';
import {ConferenceInvite} from './conferences/ConferenceInvite';
import {SupportService} from './support/SupportService';

export * from './types';
export * from './media/ManagedStream';
export * from './media/LocalMediaHandler';

export interface CallRemoteRecorder {
	/**
	 * Retrieve info about recordings.
	 */
	getRecordings(): Promise<any[]>;

	pause();

	/**
	 * Start a recording of a call and save it in a file called "filename".
	 */
	start(filename: string): Promise<void>;

	/**
	 * Stop a recording of a call.
	 */
	stop(): Promise<void>;
}

export enum CallDirection {
	INCOMING,
	OUTGOING,
}

export enum CallEndReason {
	UNSPECIFIED,
	NORMAL_CLEARING,
	BROWSER_CLOSED,
	BAD_REQUEST,
	ORIGINATOR_CANCEL,
	NOT_FOUND,
	USER_BUSY,
	NO_ANSWER,
	MEDIA_ACCESS_ERROR,
	SERVER_ERROR,
}

export enum CallStatus {
	UNCONNECTED,
	TRYING,
	QUEUED,
	CONNECTING,
	CONNECTED,
	HOLD,
	REMOTE_HOLD,
	RECONNECTING,
	DISCONNECTED,
}

export interface Call {
	emitter: EventEmitter2;

	/**
	 * Attempts to reach the call recipient and establish a connection.
	 */
	connect(): Promise<Call>;

	/**
	 * Create an object to manage the remote recording.
	 */
	createCallRecorder(type: string): CallRemoteRecorder;

	/**
	 * Disconnects or rejects the call.
	 */
	disconnect(): Promise<Call>;

	/**
	 * Returns actual call context.
	 */
	getContext(): object;

	/**
	 * Returns the direction of the call.
	 */
	getDirection(): CallDirection;

	/**
	 * Returns the end reason of the call.
	 */
	getEndReason(): CallEndReason;

	getId(): string;

	/**
	 * Returns a set containing the local only streams.
	 */
	getLocalOnlyStreams(): Immutable.Set<ManagedStream>;

	/**
	 * Return the media constraints configured for the call.
	 */
	getMediaConstraints(): MediaStreamConstraints;

	/**
	 * Returns a the remote gateway user.
	 */
	getRemoteGatewayUser(): string;

	/**
	 * Returns a set containing the remote streams.
	 */
	getRemoteStreams(): Immutable.Set<ManagedStream>;

	/**
	 * Returns a user object representing the remote user if exists.
	 */
	getRemoteUser(): User;

	/**
	 * Returns the current status of the call.
	 */
	getStatus(): CallStatus;

	/**
	 * Returns a boolean value indicating if the call has a local only video
	 * track.
	 */
	hasLocalOnlyVideo(): boolean;

	/**
	 * Returns a boolean value indicating if the call has a remote audio track.
	 */
	hasRemoteAudio(): boolean;

	/**
	 * Returns a boolean value indicating if the call has a remote video track.
	 */
	hasRemoteVideo(): boolean;

	/**
	 * Returns true if Call is in any of the specified status.
	 */
	hasStatus(...args: CallStatus[]): boolean;

	/**
	 * Holds this call.
	 */
	hold(): Promise<void>;

	/**
	 * Returns true if the Call is polling.
	 */
	isPolling(): boolean;

	/**
	 * Resumes this call.
	 */
	resume(): Promise<void>;

	/**
	 * Send a DTMF tone.
	 */
	sendDtmf(key: string): void;

	/**
	 * Set some optional data that will be sent when creating the call.
	 */
	setContext(context: object): Call;

	transfer(to: string): Promise<boolean>;

	/**
	 * Allows access to local streams and actions related to changing which local media is shared
	 */
	getLocalMediaHandler(): LocalMediaHandler;

	/**
	 * Returns a promise that is resolved when the call changes to the requested
	 * status.
	 */
	waitForStatus(...statusList: CallStatus[]): Promise<CallStatus>;
}

export enum DataPipeStatus {
	UNCONNECTED,
	CONNECTING,
	CONNECTED,
	REJECTED,
	DISCONNECTED,
}

export enum DataPipeType {
	INCOMING,
	OUTGOING,
}

export interface DataPipe {
	/**
	 * Gets a unique identifier for the pipe
	 */
	id: string;

	/**
	 * Return label associated with this DataPipe.
	 */
	label: string;

	/**
	 * Gets the identities of the peers attached to this pipe
	 */
	participants: string[];

	/**
	 * Gets the identities of the remote peers attached to this pipe
	 */
	remoteParticipants: string[];

	/**
	 * Retrieves the current status of this pipe.
	 */
	status: symbol;

	/**
	 * Gets pipe type
	 */
	type: symbol;

	/**
	 * Adds a participant to this pipe.
	 */
	addParticipant(identity: string): Promise<DataPipe>;

	/**
	 * Attempts to reach the pipe recipient and establish a connection.
	 */
	connect(): Promise<DataPipe>;

	/**
	 * Ends an active pipe.
	 */
	disconnect(): Promise<DataPipe>;

	/**
	 * Called when a user does not wish to accept an incoming pipe.
	 */
	reject(): Promise<DataPipe>;

	/**
	 * Removes a participant from this pipe.
	 */
	removeParticipant(identity: string): Promise<DataPipe>;

	/**
	 * Sends data to the DataPipe recipients
	 */
	send(data: string): Promise<DataPipe>;

	/**
	 * Returns a Promise resolved when pipe reaches provided state
	 */
	when(status: symbol): Promise<DataPipe>;

	/**
	 * Attach events to callback functions.
	 */
	on(event: string, callback: (param: any) => void): void;
}

export enum StreamRecorderStatus {
	INACTIVE,
	RECORDING,
	PAUSED,
}

export class StreamRecorder {
	constructor(mediaStream: MediaStream);
	emitter: EventEmitter2;

	/**
	 * Indicates if the audio of the call must be recorded
	 */
	isAudioRecordingEnabled: boolean;

	/**
	 * Indicates if the video of the call must be recorded
	 */
	isVideoRecordingEnabled: boolean;

	/**
	 * Pauses the recording
	 */
	pause(): void;

	/**
	 * Resumes the recording
	 */
	resume(): void;

	/**
	 * Starts the recording
	 */
	start(): void;

	/**
	 * Stops the recording
	 */
	stop(): void;
}

/**
 * This class provides access to every conference related feature This class
 * must never be directly instantiated, instances of this class can be obtained
 * using Session#getConferenceManager.
 */
export class ConferenceManager {
	emitter: EventEmitter2;
	static newInstance(wacProxy, userManager): ConferenceManager
	createConference(): Promise<Conference>;
	getConferenceLog(): ConferenceLog;
	getDefaultMediaConstraints(): MediaStreamConstraints;
	setDefaultMediaConstraints(defaultMediaConstraints: MediaStreamConstraints): void;
	requestConferenceInvitation(participant: string, mediaConstraints?: MediaStreamConstraints): Promise<CallRequest>;
	getCurrentInvitations(): Promise<Conference[]>;
	getConferenceByUri(uri: string): Promise<Conference>;
}

export class Conference {
	emitter: EventEmitter2;

	/**
	 * Use to keep the number of invitations sent in this conference.
	 */
	invitationCount: number;

	/**
	 * Check if conference is on hold state.
	 */
	isOnHold: boolean;

	/**
	 * Allows access to local streams and actions related to changing what local media is shared
	 */
	getLocalMediaHandler(): LocalMediaHandler;

	/**
	 * Indicates if participants can be invited to this conference or not.
	 */
	canManage(): boolean;

	/**
	 * Expels a participant from this conference.
	 */
	expelParticipant(participant: string, session?: string): Promise<any>;

	/**
	 * Expels a list of participants from this conference.
	 */
	expelParticipants(participants: string[]): Promise<any>;

	/**
	 * Returns the current participant count.
	 */
	getCurrentParticipants(): number;

	/**
	 * Returns the ID of the conference.
	 */
	getId(): string;

	/**
	 * Returns the invitation to the conference if the participant was invited.
	 */
	getInvite(): ConferenceInvite;

	/**
	 * Returns a set of outgoing invitations.
	 */
	getOutgoingInvitations(): Immutable.Set<object>;

	/**
	 * Returns the username of the conference's owner.
	 */
	getOwner(): User;

	/**
	 * Returns a set of strings containing the gateway username of every remote
	 * participant.
	 */
	getRemoteGatewayUsernames(): Immutable.Set<string>;

	/**
	 * Returns a Map containing a list of ManagedStreams per participant
	 * (gateway user name).
	 */
	getRemoteStreams(): Immutable.Map<string, ManagedStream[]>;

	getRemoteParticipants(): Immutable.Map<string, 'IN_CALL'|'HOLD'>;

	/**
	 * Returns a Set of strings containing the address of remote participants
	 * (gateway user names) that are also wac users.
	 */
	getRemoteWacAddresses(): Immutable.Set<string>;

	/**
	 * Returns the current status of the conference.
	 */
	getStatus(): ConferenceStatus;
	getStatus$(): Observable<ConferenceStatus>;

	/**
	 * Returns a boolean value indicating if at least one of the remote
	 * conference participants has a video track.
	 */
	hasRemoteVideo(): boolean;

	/**
	 * Enable/disable local hold Local hold mutes conference audio streams
	 * (local and remote) and stops receiving/sending video (if any).
	 */
	hold(): Promise<any>;

	/**
	 * Republishes all previously published media, subscribes to previously subscribed media and
	 * notifies new status to other participants
	 */
	unhold(): Promise<void>;

	/**
	 * Invites a new participant to this conference.
	 */
	inviteParticipant(
		participant: string,
		session?: string,
		mediaTypes?: MediaTypes,
		autoAccepted?: boolean,
		requestId?: string,
		resolve?: boolean,
		agentInfo?: ContextInfo): Promise<object>;

	/**
	 * Invites a list of new participant to this conference.
	 */
	inviteParticipants(participants: string[]): Promise<any>;

	/**
	 * Check if a conference is being transfering.
	 */
	isBeingTransfered(): boolean;

	isRecovered(): boolean;

	/**
	 * Connects to the conference.
	 */
	join(): Promise<any>;

	/**
	 * Leaves the conference.
	 */
	leave(errorCode?: number): any;

	/**
	 * Create an unattendedCallTransfer towards a user in the system.
	 */
	unattendedCallTransfer(participant: string, mediaConstraints: MediaStreamConstraints): Promise<any>;

	cancelInvitation(invitation: Invitation, session?: string): void;
}

export interface ContextInfo {
	[index: string]: string;
}

export enum ConferenceStatus {
	DESTROYED,
	DISCONNECTED,
	CONNECTING,
	CONNECTED,
	DISCONNECTING,
}

export interface Invitation {
	getToUser(): any;
	getTo(): string;
	getMediaTypes(): any;
	isAutoAccepted(): boolean;
	getResponseCode(): number;
	hasStreams(): boolean;
	isCanceled(): boolean;
	isActive(): boolean;
	getTimestamp(): number;
}

export interface ConferenceLog {
	fetch(limit: any, lastEntryStartTimestamp: any): any;
}

export interface Participant {
	id: string;
	username: string;
	domain: string;
	email: string;
	capabilities: string[];
	gatewayUsername: string;
	mobilePhone: string[];
	landLineNumber: string;
}

/**
 * CallRequest Object
 */
export interface CallRequest {
	remoteUser: User;
	to: string;
	type: 'outgoing';
	Type: object;
	hasLocalVideo(): boolean;
	on(event: string, callback: (param: any) => void): void;
	off(event: string, callback: (param: any) => void): void;
	_disconnect(): void;
	_connect(): Promise<{code: number}>;
}

/**
 * Manages the contacts and groups which they belongs to CallLogManager
 * instance is obtained by calling the {Session#getCallLogManager} method.
 */
export interface CallLog {
	emitter: EventEmitter2;
	lastRecoveredTimestamp: any;

	/**
	 * Fetch more callLog entries.
	 */
	fetch(limit: number): Promise<void>;

	/**
	 * Retrieves a CallLog by given its ID.
	 */
	getById(id: string): CallLog;

	/**
	 * Obtains the list with the available CallLog items.
	 */
	getEntries(): CallLog[];
}

export interface RemoteCall {
	/**
	 * Returns identifier associated with this call.
	 */
	id: string;

	/**
	 * List of participants associated with this call.
	 */
	participants: string[];

	/**
	 * Session where this call exists.
	 */
	session: RemoteSession;
}

/**
 * This class provides access to every call related feature This class must
 * never be directly instantiated, instances of this class can be obtained
 * using Session#getCallManager.
 */
export interface CallManager {
	emitter: EventEmitter2;

	/**
	 * Creates a new call instance for communication with the specified recipient.
	 */
	createCall(to: string): Promise<Call>;

	getCallLog(): Promise<CallLog>;

	getDefaultMediaConstraints(): MediaStreamConstraints;

	/**
	 * Get a list of remote calls where user is currently participating.
	 */
	getRemoteCalls(): Promise<RemoteCall[]>;

	/**
	 * Pulls remote call from remote session.
	 */
	pull(remoteCall: RemoteCall): Promise<Call>;

	setDefaultMediaConstraints(defaultMediaConstraints: MediaStreamConstraints);
}

export enum ChatMessageDirection {
	INCOMING,
	OUTGOING,
}

export enum ChatMessageStatus {
	ERROR,
	SENDING,
	SENT,
	RECEIVED,
	DISPLAYED,
	ACKNOWLEDGED,
}

export enum ChatMessageType {
	FILE,
	TEXT,
}

export enum ChatParticipantRole {
	MEMBER,
	ADMIN,
}

export enum ChatParticipantState {
	ACTIVE,
	INACTIVE,
	GONE,
	COMPOSING,
	PAUSED,
}

export enum ChatType {
	INDIVIDUAL,
	GROUP,
}

/**
 * Provides access to methods for managing a chat room.
 */
export interface Chat {
	emitter: EventEmitter2;
	addParticipant(participant: string): Promise<void>;
	archive(): Promise<void>;
	cancelPendingMessage(message: ChatMessage): Promise<void>;
	delete(): Promise<void>;
	expelParticipant(participant: string): Promise<void>;
	fetch(minimum?: number): Promise<void>;
	getFileMessages(): Immutable.List<ChatMessage>;
	readonly firstUnreadMessage: ChatMessage;
	getFirstUnreadMessage(): ChatMessage;
	getFirstUnreadMessage$(): Observable<ChatMessage>;
	getId(): string;
	readonly messages: Immutable.List<ChatMessage>;
	getMessages(): Immutable.List<ChatMessage>;
	getMessages$(): Observable<Immutable.List<ChatMessage>>;
	getName(): string;
	getParticipants(): Immutable.Map<string, ChatParticipantRole>;
	getPendingMessages(): Immutable.List<ChatMessage>;
	getRemoteParticipants(): Immutable.Map<string, ChatParticipantState>;
	getRole(): ChatParticipantRole;
	getSubject(): string;
	getType(): ChatType;
	getUnreadMessageCount$(): Observable<number>;
	getUnreadMessageCount(): number;
	leave(): Promise<void>;
	resetUnreadMessageCount(): Promise<void>;
	sendFile(file: File): Promise<void>;
	sendText(text: string): Promise<void>;
	setParticipantRole(participant: string, role: ChatParticipantRole): Promise<void>;
	setState(state: ChatParticipantState): Promise<void>;
	setSubject(subject: string): Promise<void>;
	sync(): Promise<void>;
}

/**
 * Provides access to methods for using chat.
 */
export interface ChatManager {
	emitter: EventEmitter2;
	createChat(name?: string, subject?: string): Promise<Chat>;
	disablePushNotifications(): Promise<void>;
	enablePushNotifications(): Promise<void>;
	getChats(): Immutable.List<Chat>;
	getConferenceChats(): Immutable.List<Chat>;
	getGroupChat(): Chat;
	getIndividualChat(participant: string): Chat;
	setPushConfig(config: PushConfig): void;
	sync(): Promise<void>;
	createSupportChat(contextInfo?: ContextInfo): Promise<Chat>;
}

export interface PushConfig {
	jid: string;
	type: 'fcm' | 'apns';
	token: string;
}

/**
 * Represents a message of the chat.
 */
export interface ChatMessage {
	getComposer(): string;
	getData(): string | ChatMessageFile;
	getDirection(): ChatMessageDirection;
	getId(): string;
	getProgress(): number;
	getStatus(): ChatMessageStatus;
	getTimestamp(): number;
	getType(): ChatMessageType;
	hasStatus(status: ChatMessageStatus): boolean;
}

/**
 * Represents a file in a chat message
 */
export interface ChatMessageFile {
	getName(): string;
	getType(): Promise<string>;
	getUrl(): string;
}

/**
 * This class must not be instantiated. OwnPresence object can be accessed
 * using ContactManager#OwnPresence
 */
export interface OwnPresence extends Presence {
	activity: any;
	avatar: string;
	displayName: string;
	setDisplayName(displayName: string): Promise<void>;
	mood: any;
	note: string;
	online: boolean;
	scaleImg(url: string, width: number, height: number): Promise<string>;
}

export interface Contact extends EventEmitter2 {
	avatar: string;
	contactDeviceId: string;
	deviceId: string;
	email: string;
	emails: Array<{type: string; email: string}>;
	favorite: boolean;
	id: string;
	isEditable: boolean;
	isWacUser: boolean;
	name: string;
	phone: string;
	phones: Array<{name: string; address: string}>;
	presence: Presence;
	source: string;
	unnormalizedPhones: Record<string, any>;
	getWacUserAddress(): string;
	remove(): Promise<void>;
}

export enum PresenceActivity {
	unknown = 'unknown',
	appointment = 'appointment',
	away = 'away',
	breakfast = 'breakfast',
	busy = 'busy',
	dinner = 'dinner',
	holiday = 'holiday',
	inTransit = 'inTransit',
	lookingForWork = 'lookingForWork',
	lunch = 'lunch',
	meal = 'meal',
	meeting = 'meeting',
	onThePhone = 'onThePhone',
	other = 'other',
	performance = 'performance',
	permanentAbsence = 'permanentAbsence',
	playing = 'playing',
	presentation = 'presentation',
	shopping = 'shopping',
	sleeping = 'sleeping',
	spectator = 'spectator',
	steering = 'steering',
	travel = 'travel',
	tv = 'tv',
	vacation = 'vacation',
	working = 'working',
	worship = 'worship',
}

export enum PresenceMood {
	unknown = 'unknown',
	afraid = 'afraid',
	amazed = 'amazed',
	angry = 'angry',
	annoyed = 'annoyed',
	anxious = 'anxious',
	ashamed = 'ashamed',
	bored = 'bored',
	brave = 'brave',
	calm = 'calm',
	cold = 'cold',
	confused = 'confused',
	contented = 'contented',
	cranky = 'cranky',
	curious = 'curious',
	depressed = 'depressed',
	disappointed = 'disappointed',
	disgusted = 'disgusted',
	distracted = 'distracted',
	embarrassed = 'embarrassed',
	excited = 'excited',
	flirtatious = 'flirtatious',
	frustrated = 'frustrated',
	grumpy = 'grumpy',
	guilty = 'guilty',
	happy = 'happy',
	hot = 'hot',
	humbled = 'humbled',
	humiliated = 'humiliated',
	hungry = 'hungry',
	hurt = 'hurt',
	impressed = 'impressed',
	in_awe = 'in_awe',
	in_love = 'in_love',
	indignant = 'indignant',
	interested = 'interested',
	invincible = 'invincible',
	jealous = 'jealous',
	lonely = 'lonely',
	mean = 'mean',
	moody = 'moody',
	nervous = 'nervous',
	neutral = 'neutral',
	offended = 'offended',
	other = 'other',
	playful = 'playful',
	proud = 'proud',
	relieved = 'relieved',
	remorseful = 'remorseful',
	restless = 'restless',
	sad = 'sad',
	sarcastic = 'sarcastic',
	serious = 'serious',
	shocked = 'shocked',
	shy = 'shy',
	sick = 'sick',
	sleepy = 'sleepy',
	stressed = 'stressed',
	surprised = 'surprised',
	thirsty = 'thirsty',
	worried = 'worried',
}

export interface Presence extends EventEmitter2 {
	/**
	 * Represents the different status of an user.
	 */
	ACTIVITY: any;

	/**
	 * Represents the different emotional states of an user.
	 */
	MOOD: any;

	/**
	 * User activity.
	 */
	activity: PresenceActivity;

	/**
	 * Address associated with this presence.
	 */
	address: string;

	/**
	 * Avatar location.
	 */
	avatar: string;

	/**
	 * Display name.
	 */
	displayName: string;

	/**
	 * User emotional state.
	 */
	mood: PresenceMood;

	/**
	 * Short message defined by user.
	 */
	note: string;

	/**
	 * User is online.
	 */
	online: boolean;

	waitUntilSynced(): Promise<void>;
}

/**
 * ContactManager instance is obtained by calling the Session#getContactManager
 * method of Session and must not be directly instantiated. Once the
 * ContactManager instance is obtained ContactManager#init method must be
 * called to initialize it.
 */
export interface ContactManager extends EventEmitter2 {

	/**
	 * Allows to change the presence of this session.
	 */
	ownPresence: OwnPresence;

	prototypes: {Contact: any; GroupContact: any; Presence: any; OwnPresence: any};

	/**
	 * Call stack.addContact once the manager is initialized and return a promise.
	 */
	createContact(displayName: string, phones: string | Array<{name: string; address: string}>, emails: Array<{email: string}>): any;

	/**
	 * Retrieves a contact given an address
	 */
	getContactByAddress(address: string, sync: boolean): Contact;

	/**
	 * Retrieves a contact given an email
	 */
	getContactByEmail(email: string): Contact;

	/**
	 * Retrieves a contact given a WAC id
	 */
	getContactByWacId(wacId: any): Contact;

	/**
	 * Retrieves a list with the available contacts
	 */
	getContacts(): Contact[];

	getFakeContact(opts: {
		id: string;
		name: string;
		presence?: Presence;
		avatar?: string;
		phone?: string;
		email?: string;
	}): Contact;

	/**
	 * Retrieves the presence of a user given an address
	 */
	getPresenceByAddress(address: any): Promise<Presence>;

	/**
	 * Retrieves the presence of a user given its WAC id
	 */
	getPresenceByWacId(wacId: any): Contact;

	/**
	 * Initializes the contact manager
	 */
	init(): Promise<ContactManager>;

	/**
	 * Launch the sinchronizing to check if a change has occured
	 */
	launchSynchronize(): Promise<any>;

	/**
	 * Internal callback for Synchronizer event.
	 */
	onUpdateAvatarsContacts(avatarContacts: any): any;

	/**
	 * Clears all user contacts data and invalidates the cache from the persistent storage
	 */
	clearContactsDataFromPersistentStorage(): void;

	/**
	 * Internal callback for Synchronizer event
	 */
	onUpdateListContacts(contacts: Contact[]): any;

	/**
	 * Uninitializes the contact manager
	 */
	uninit(): Promise<void>;
}

/**
 * Represents a user. This class must not be directly instantiated. Instead,
 * instances of this class are obtained by calling to session#getUser.
 */
export interface User {
	/**
	 * User's alias.
	 */
	alias: string;

	/**
	 * User's capabilities.
	 */
	capabilities: any;

	/**
	 * When the user was created (milliseconds).
	 */
	created: number;

	/**
	 * User domain.
	 */
	domain: string;

	/**
	 * User's email
	 */
	email: string;

	/**
	 * User unique identifier.
	 */
	id: string;

	/**
	 * User's landLineNumber.
	 */
	landLineNumber: string;

	/**
	 * User's lastLogin.
	 */
	lastLogin: number;

	/**
	 * User's mobile phone.
	 */
	mobilePhone: any;

	/**
	 * User's role
	 */
	role: string;

	/**
	 * ser's username.
	 */
	username: string;
	getAddress(): string;

	/**
	 * Get the user who is authenticated.
	 */
	init(): Promise<User>;

	/**
	 * Returns a JS object with the JSON serialization representation of this
	 * object.
	 */
	toJSON(): object;

	/**
	 * Update an user.
	 */
	update(objToUpdate: object): Promise<User>;

	/**
	 * Check if a code is right to update a phone.
	 */
	validatePhone(code: string, phone: string): Promise<User>;
}

/**
 * Element that enables user resolution. Previously resolved users are stored
 * in a local collection that is updated when some of the requested addresses
 * change.
 */
export interface UserManager {
	/**
	 * Get the address associated with given user Id.
	 */
	getAddress(userId: string): string;

	/**
	 * Returns the gateway username associated with an user username.
	 */
	getGatewayUsername(username: string, ignoreErrors: boolean): Promise<string>;

	/**
	 * Returns the gateway usernames associated with an user username.
	 */
	getGatewayUsernames(usernames: any, ignoreErrors: boolean): any;

	/**
	 * Obtains own user WAC address
	 */
	getOwnAddress(): string;

	/**
	 * Get the userId associated with given user address.
	 */
	getUserId(address: string): string;

	/**
	 * Returns an user username given a gateway username.
	 */
	getUsername(gatewayUsername: string, ignoreErrors: boolean): Promise<string>;

	/**
	 * Initialize UsersManager.
	 */
	init(stack: any): Promise<any>;

	/**
	 * Checks if given address is a WAC user address
	 */
	isAddress(address: string): boolean;

	/**
	 * Checks if given address is own WAC user address
	 */
	isOwnAddress(address: string): boolean;

	/**
	 * Request an address resolution.
	 */
	resolveUser(address: string): Promise<User | undefined>;

	/**
	 * Deinitialize UsersManager.
	 */
	uninit(): void;
}

export interface Group {
	getId(): string;
	getName(): string;
	getParticipants(): Immutable.Set<string>;
	getPhonebook(): Array<{name: string; address: string}>;
	with({name, participants}: {name: string; participants: Iterable<string>}): Group;
	plusParticipants(participants: Iterable<string>): Group;
	minusParticipants(participants: Iterable<string>): Group;
}

export interface GroupManager {
	emitter: EventEmitter2;
	getGroups(): Immutable.List<Group>;
	createGroup(name: string, participants: Iterable<string>): Promise<Group>;
	saveGroup(group: Group): Promise<void>;
	deleteGroup(group: Group): Promise<void>;
	/** @deprecated */
	getPhonebook(group: Group): Array<{subscribers: string[]; name: string; id: string; contacts: Array<{name: string; address: string}>}>;
}

export enum FileUploadStatus {
	LOADING,
	SENDING,
	COMPLETED,
	ERROR,
	ABORTED,
}

/**
 * Provides access to methods for uploading a file. A file transfer object is
 * obtained by calling the FileSharingManager#createFileTransfer method.
 */
export interface FileUpload {
	getBytesSent(): number;
	getId(): string;
	getName(): string;
	getProgress(): number;
	getSize(): number;
	getStatus(): FileUploadStatus;
	getType(): string;
	getUrl(): string;
	hasStatus(statuses: FileUploadStatus): boolean;
}

export interface FileUploadManager {

	emitter: EventEmitter2;
	/**
	 * Aborts a currently in progress file upload.
	 */
	abort(fileUpload: FileUpload): Promise<void>;

	/**
	 * Starts uploading a new file.
	 */
	create(file: File): Promise<string>;

	/**
	 * Returns an immutable map with file uploads.
	 */
	getFileUploads(): Map<string, FileUpload>;

	/**
	 * Removes a file upload from the list.
	 */
	remove(fileUpload: FileUpload): void;

	waitForEnd(id: any): any;
}

export interface FileManager {
	getFileUploadManager(): Promise<FileUploadManager>;
}

export interface InstantMessage {
	/**
	 * Get the message.
	 */
	getMessage(): string;

	/**
	 * Get the message' receiver.
	 */
	getReceiver(): string;

	/**
	 * Get the message's composer.
	 */
	getSender(): string;

	/**
	 * Sends the message.
	 */
	send(): Promise<any>;
}

/**
 * Provides access to methods for creating whiteboards. This class must not be
 * directly instantiated. It can be obtained using session#createWhiteboard or
 * listening to session#incommingWhiteBoard event.
 */
export interface Whiteboard extends EventEmitter2 {
	/**
	 * Aspect ratio of the whiteboard.
	 */
	aspectRatio: number;

	/**
	 * Current background image shown.
	 */
	backgroundImage: string | Blob;

	/**
	 * Current background video shown.
	 */
	backgroundVideo: string;

	/**
	 * Color used for the shapes.
	 */
	color: string;

	/**
	 * Current height of the whiteboard.
	 */
	height: number;

	lineWidth: any;

	/**
	 * Gets the identities of the remote peers attached to this Whiteboard.
	 */
	remoteParticipants: string[];

	/**
	 * Current tool to use on user interaction.
	 */
	tool: string;

	/**
	 * Returns the current width of the whiteboard.
	 */
	width: number;

	/**
	 * Check if last undo call can be reverted.
	 */
	canRedo(): boolean;

	/**
	 * Check if last action can be reverted.
	 */
	canUndo(): boolean;

	/**
	 * Removes every shape from the whiteboard.
	 */
	clear(): undefined;

	/**
	 * Closes this whiteboard session.
	 */
	close(): Whiteboard;

	/**
	 * Revert last undo call.
	 */
	redo();

	/**
	 * Allows to set the area that will be used as the canvas for the whiteboard.
	 */
	setArea(selector: string | HTMLElement | null): Whiteboard;

	/**
	 * Revert last change.
	 */
	undo();
}

/**
 * Used to define a remote session where user has created a session.
 */
export interface RemoteSession {
	id: string;
	name: string;
}

/**
 * Session objects manage communications for a given user identity. They are
 * obtained by calling the createSession method of the Sippo object.
 */
export interface Session extends EventEmitter2 {
	/**
	 * Return stack-reported network connectivity tests results.
	 */
	checkConnection(proto: string): any;

	/**
	 * Activates the communications session with a gateway server.
	 */
	connect(): Promise<Session>;

	/**
	 * Creates a new data pipe instance for data exchange with the specified
	 * recipient.
	 */
	createDataPipe(participants: string[], label?: string): DataPipe;

	/**
	 * Create a standalone message to the given recipient.
	 */
	createInstantMessage(to: string, text: string): InstantMessage;

	/**
	 * Creates a new instance of a Selfie.
	 */
	createSelfie(to: string): Promise<any>;

	/***
	 * Creates a new instance of a Whiteboard.
	 */
	createWhiteboard(participants: string[]): Promise<Whiteboard>;

	/**
	 * Destroy every existent token for the deviceId of this session.
	 */
	destroyPushToken(): any;

	/**
	 * Ends a connected session.
	 */
	disconnect(): Promise<any>;

	/**
	 * Get user's alias.
	 */
	getAlias(): string;

	/**
	 * Retrieves a call manager instance.
	 */
	getCallManager(): CallManager;

	/**
	 * Retrieves an array with the underlying capabilities.
	 */
	getCapabilities(): Immutable.Set<string>;

	/**
	 * Retrieves the chat manager.
	 */
	getChatManager(): Promise<ChatManager>;

	/**
	 * Retrieves a conference manager instance.
	 */
	getConferenceManager(): ConferenceManager;

	/**
	 * Retrieve the contact manager.
	 */
	getContactManager(): ContactManager;

	/**
	 * Retrieves the file manager.
	 */
	getFileManager(): Promise<FileManager>;

	/**
	 * Returns the username in the gateway of the user owning this session.
	 */
	getGatewayUsername(): string;

	/**
	 * Retrieves the group manager.
	 */
	getGroupManager(): GroupManager;

	/**
	 * Retrieves a Support Service instance
	 */
	getSupportService(): SupportService;

	/**
	 * Retrieves a {Logger} instance to log events in the WAC.
	 */
	getLogger(name: string): any;

	/**
	 * Retrieves a meetingList object with the existing meeting session for this
	 * user.
	 * @deprecated
	 */
	getMeetingList(): any;

	/**
	 * Retrieves a meetingManager object with the existing meeting session for this
	 * user.
	 */
	getMeetingManager(): any;

	/**
	 * Get a list of remote sessions where user is currently logged in.
	 */
	getRemoteSessions(): Promise<RemoteSession[]>;

	/**
	 * Get session token.
	 */
	getSessionToken(): string;

	/**
	 * Retrieves the current status of this session.
	 */
	getStatus(): SessionStatus;

	/**
	 * Retrieve the User.
	 */
	getUser(): User;

	/**
	 * Retrieve a UserManager object.
	 */
	getUserManager(): UserManager;

	/**
	 * Returns the username of the user owning this session.
	 */
	getUsername(): string;

	/**
	 * Retrieves and array with version information.
	 */
	getVersion(): object[];

	/**
	 * Notifies a push token to the WAC.
	 */
	notifyPushToken(tokenType: string, token: string): any;

	onConnectionLost(): void;

	onSessionReconnected(): void;

	onSessionReconnecting(): void;

	onTransportClose(): void;

	onUnknownClose(): void;

	/**
	 * Resume current session, restoring WAC communication.
	 */
	resume(): any;

	/**
	 * @param {String} key Key to modified
	 * @param {String} value New value
	 * @return {Session}
	 */
	setSetting(key: string, value: string): Session;

	/**
	 * Retrieves a promise which is resolved with the settings array.
	 */
	settings(): Promise<any>;

	/**
	 * Suspend current session: WAC will not send or receive any message.
	 */
	suspend(): Promise<any>;

}

export interface SessionConfig {
	wacUri: string;
	applicationToken?: string;
	deviceId?: string;
}

export interface AuthProvider {
	authorization_endpoint: string;
	displayName: string;
	grant_type: string;
	id: string;
	revocation_endpoint: string;
	scope: string;
	signout_endpoint?: string;
	token_endpoint?: string;
	tokenInfo: string;
	uid: string;
	uidType: string;
}

/** Factory method for session creation */
export function createSession(issuer: string, token: string, sessionConfig: SessionConfig): Promise<Session>;

/** Factory method for session recovery */
export function recoverSession(sessionToken: string, sessionConfig: SessionConfig): Promise<Session>;

/** Get authProviders for authentication */
export function getAuthProviders(wacUri: string): Promise<AuthProvider[]>;

export enum SessionStatus {
	UNCONNECTED,
	CONNECTED,
	CONNECTING,
	SUSPENDED,
	DISCONNECTED,
}

export {SupportService} from './support/SupportService';