import BrowserSession from './BrowserSession' ; import { SubscribeParams , BroadcastParams } from './util/interfaces' ; import { IVertoCallOptions } from './webrtc/interfaces' ; import { Login } from './messages/Verto' ; import Call from './webrtc/Call' ; import { SESSION_ID } from './util/constants' ; import { sessionStorage } from './util/storage' ; import VertoHandler from './webrtc/VertoHandler' ; import { isValidOptions } from './util/helpers' ; export const VERTO_PROTOCOL = 'verto-protocol' ; export default class Verto extends BrowserSession { public relayProtocol : string = VERTO_PROTOCOL ; public timeoutErrorCode = - 329990 ; validateOptions ( ) { return isValidOptions ( this . options ) ; } newCall ( options ) { if ( ! options || ! options . destinationNumber ) { throw new Error ( 'Verto.newCall() error: destinationNumber is required.' ) ; } const call = new Call ( this , options ) ; call . invite ( ) ; return call ; } broadcast ( params ) { return this . vertoBroadcast ( params ) ; } subscribe ( params ) { return this . vertoSubscribe ( params ) ; } unsubscribe ( params ) { return this . vertoUnsubscribe ( params ) ; } protected async _onSocketOpen ( ) { this . _idle = false ; const { login , password , passwd , login_token , userVariables , autoReconnect = true , } = this . options ; const msg = new Login ( login , password || passwd , login_token , this . sessionid , userVariables ) ; const response = await this . execute ( msg ) . catch ( this . _handleLoginError ) ; if ( response ) { this . _autoReconnect = autoReconnect ; this . sessionid = response . sessid ; sessionStorage . setItem ( SESSION_ID , this . sessionid ) ; } } protected _onSocketMessage ( msg ) { const handler = new VertoHandler ( this ) ; handler . handleMessage ( msg ) ; } }