1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234 |
- import { Web, UserAgent, UserAgentState, Registerer, RegistererState, Inviter, Invitation, Session, Messager, RequestPendingError, SessionState } from 'sip.js';
- import io from 'socket.io-client';
- function __decorate(decorators, target, key, desc) {
- var c = arguments.length,
- r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
- d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- }
- function __awaiter(thisArg, _arguments, P, generator) {
- function adopt(value) {
- return value instanceof P ? value : new P(function (resolve) {
- resolve(value);
- });
- }
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) {
- try {
- step(generator.next(value));
- } catch (e) {
- reject(e);
- }
- }
- function rejected(value) {
- try {
- step(generator["throw"](value));
- } catch (e) {
- reject(e);
- }
- }
- function step(result) {
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
- }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- }
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
- var e = new Error(message);
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
- };
- class SessionManagerPlus {
-
- constructor(server, options = {}) {
-
- Object.defineProperty(this, "delegate", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
-
- Object.defineProperty(this, "managedSessions", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: []
- });
-
- Object.defineProperty(this, "userAgent", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "logger", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "options", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "optionsPingFailure", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: false
- });
- Object.defineProperty(this, "optionsPingRequest", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "optionsPingRunning", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: false
- });
- Object.defineProperty(this, "optionsPingTimeout", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "registrationAttemptTimeout", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "registerer", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "registererOptions", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "registererRegisterOptions", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "shouldBeConnected", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: false
- });
- Object.defineProperty(this, "shouldBeRegistered", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: false
- });
- Object.defineProperty(this, "attemptingReconnection", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: false
- });
-
- this.delegate = options.delegate;
-
- this.options = Object.assign({
- aor: '',
- autoStop: true,
- delegate: {},
- iceStopWaitingOnServerReflexive: false,
- managedSessionFactory: this.managedSessionFactory,
- maxSimultaneousSessions: 2,
- media: {},
- optionsPingInterval: -1,
- optionsPingRequestURI: '',
- reconnectionAttempts: 3,
- reconnectionDelay: 3,
- registrationRetry: false,
- registrationRetryInterval: 3,
- registerGuard: null,
- registererOptions: {},
- registererRegisterOptions: {},
- sendDTMFUsingSessionDescriptionHandler: false,
- userAgentOptions: {}
- }, SessionManagerPlus.stripUndefinedProperties(options));
-
- const userAgentOptions = Object.assign({}, options.userAgentOptions);
-
- if (!userAgentOptions.transportConstructor) {
- userAgentOptions.transportConstructor = Web.Transport;
- }
-
- if (!userAgentOptions.transportOptions) {
- userAgentOptions.transportOptions = {
- server
- };
- }
-
- if (!userAgentOptions.uri) {
-
- if (options.aor) {
- const uri = UserAgent.makeURI(options.aor);
- if (!uri) {
- throw new Error(`Failed to create valid URI from ${options.aor}`);
- }
- userAgentOptions.uri = uri;
- }
- }
-
- this.userAgent = new UserAgent(userAgentOptions);
-
- this.userAgent.delegate = {
-
- onConnect: () => {
- this.logger.log(`Connected`);
- if (this.delegate && this.delegate.onServerConnect) {
- this.delegate.onServerConnect();
- }
-
- if (this.shouldBeRegistered) {
- this.register();
- }
-
- if (this.options.optionsPingInterval > 0) {
- this.optionsPingStart();
- }
- },
-
- onDisconnect: error => __awaiter(this, void 0, void 0, function* () {
- var _a, _b, _c, _d;
- this.logger.log(`Disconnected`);
-
- let optionsPingFailure = false;
- if (this.options.optionsPingInterval > 0) {
- optionsPingFailure = this.optionsPingFailure;
- this.optionsPingFailure = false;
- this.optionsPingStop();
- }
-
-
-
- if (error || optionsPingFailure) {
-
-
-
- if (this.registerer) {
- this.logger.log(`Disposing of registerer...`);
- this.registerer.dispose().catch(e => {
- this.logger.debug(`Error occurred disposing of registerer after connection with server was lost.`);
- this.logger.debug(e.toString());
- });
- this.registerer = undefined;
- }
- this.managedSessions.slice().map(el => el.session).forEach(session => __awaiter(this, void 0, void 0, function* () {
- this.logger.log(`Disposing of session...`);
- session.dispose().catch(e => {
- this.logger.debug(`Error occurred disposing of a session after connection with server was lost.`);
- this.logger.debug(e.toString());
- });
- }));
-
- if (this.shouldBeConnected) {
- (_b = (_a = this.delegate) === null || _a === void 0 ? void 0 : _a.onReconnectStart) === null || _b === void 0 ? void 0 : _b.call(_a);
- this.attemptReconnection();
- }
- } else {
-
- (_d = (_c = this.delegate) === null || _c === void 0 ? void 0 : _c.onServerDisconnect) === null || _d === void 0 ? void 0 : _d.call(_c, error);
- }
- }),
-
- onInvite: invitation => {
- this.logger.log(`[${invitation.id}] Received INVITE`);
-
-
-
- const maxSessions = this.options.maxSimultaneousSessions;
- if (maxSessions !== 0 && this.managedSessions.length > maxSessions) {
- this.logger.warn(`[${invitation.id}] Session already in progress, rejecting INVITE...`);
- invitation.reject().then(() => {
- this.logger.log(`[${invitation.id}] Rejected INVITE`);
- }).catch(error => {
- this.logger.error(`[${invitation.id}] Failed to reject INVITE`);
- this.logger.error(error.toString());
- });
- return;
- }
-
- const referralInviterOptions = {
- sessionDescriptionHandlerOptions: {
- constraints: this.constraints
- }
- };
-
- this.initSession(invitation, referralInviterOptions);
-
- if (this.delegate && this.delegate.onCallReceived) {
- this.delegate.onCallReceived(invitation);
- } else {
- this.logger.warn(`[${invitation.id}] No handler available, rejecting INVITE...`);
- invitation.reject().then(() => {
- this.logger.log(`[${invitation.id}] Rejected INVITE`);
- }).catch(error => {
- this.logger.error(`[${invitation.id}] Failed to reject INVITE`);
- this.logger.error(error.toString());
- });
- }
- },
-
- onMessage: message => {
- message.accept().then(() => {
- if (this.delegate && this.delegate.onMessageReceived) {
- this.delegate.onMessageReceived(message);
- }
- });
- },
-
- onNotify: notification => {
- notification.accept().then(() => {
- if (this.delegate && this.delegate.onNotificationReceived) {
- this.delegate.onNotificationReceived(notification);
- }
- });
- }
- };
-
- this.registererOptions = Object.assign({}, options.registererOptions);
-
- this.registererRegisterOptions = Object.assign({}, options.registererRegisterOptions);
-
- if (this.options.registrationRetry) {
-
- this.registererRegisterOptions.requestDelegate = this.registererRegisterOptions.requestDelegate || {};
- const existingOnReject = this.registererRegisterOptions.requestDelegate.onReject;
- this.registererRegisterOptions.requestDelegate.onReject = response => {
- existingOnReject && existingOnReject(response);
-
- this.attemptRegistration();
- };
- }
-
- this.logger = this.userAgent.getLogger('sip.SessionManager');
-
- window.addEventListener('online', () => {
- this.logger.log(`Online`);
- if (this.shouldBeConnected) {
- this.connect();
- }
- });
-
-
-
-
-
-
-
- if (this.options.autoStop) {
-
-
-
-
- window.addEventListener('beforeunload', () => __awaiter(this, void 0, void 0, function* () {
- this.shouldBeConnected = false;
- this.shouldBeRegistered = false;
- if (this.userAgent.state !== UserAgentState.Stopped) {
-
- yield this.userAgent.stop();
- }
- }));
- }
- }
-
- static stripUndefinedProperties(options) {
- return Object.keys(options).reduce((object, key) => {
-
- if (options[key] !== undefined) {
- object[key] = options[key];
- }
- return object;
- }, {});
- }
-
- getLocalMediaStream(session) {
- const hsh = session.sessionDescriptionHandler;
- if (!hsh) {
- return undefined;
- }
- if (!(hsh instanceof Web.SessionDescriptionHandler)) {
- throw new Error('Session description handler not instance of web SessionDescriptionHandler');
- }
- return hsh.localMediaStream;
- }
-
- getRemoteMediaStream(session) {
- const hsh = session.sessionDescriptionHandler;
- if (!hsh) {
- return undefined;
- }
- if (!(hsh instanceof Web.SessionDescriptionHandler)) {
- throw new Error('Session description handler not instance of web SessionDescriptionHandler');
- }
- return hsh.remoteMediaStream;
- }
-
- getLocalAudioTrack(session) {
- var _a;
- return (_a = this.getLocalMediaStream(session)) === null || _a === void 0 ? void 0 : _a.getTracks().find(track => track.kind === 'audio');
- }
-
- getLocalVideoTrack(session) {
- var _a;
- return (_a = this.getLocalMediaStream(session)) === null || _a === void 0 ? void 0 : _a.getTracks().find(track => track.kind === 'video');
- }
-
- getRemoteAudioTrack(session) {
- var _a;
- return (_a = this.getRemoteMediaStream(session)) === null || _a === void 0 ? void 0 : _a.getTracks().find(track => track.kind === 'audio');
- }
-
- getRemoteVideoTrack(session) {
- var _a;
- return (_a = this.getRemoteMediaStream(session)) === null || _a === void 0 ? void 0 : _a.getTracks().find(track => track.kind === 'video');
- }
-
- connect() {
- return __awaiter(this, void 0, void 0, function* () {
- this.logger.log(`Connecting UserAgent...`);
- this.shouldBeConnected = true;
- if (this.userAgent.state !== UserAgentState.Started) {
- return this.userAgent.start();
- }
- return this.userAgent.reconnect();
- });
- }
-
- disconnect() {
- return __awaiter(this, void 0, void 0, function* () {
- this.logger.log(`Disconnecting UserAgent...`);
- if (this.userAgent.state === UserAgentState.Stopped) {
- return Promise.resolve();
- }
- this.shouldBeConnected = false;
- this.shouldBeRegistered = false;
- this.registerer = undefined;
- return this.userAgent.stop();
- });
- }
-
- isConnected() {
- return this.userAgent.isConnected();
- }
-
- register(registererRegisterOptions) {
- return __awaiter(this, void 0, void 0, function* () {
- this.logger.log(`Registering UserAgent...`);
- this.shouldBeRegistered = true;
- if (registererRegisterOptions !== undefined) {
- this.registererRegisterOptions = Object.assign({}, registererRegisterOptions);
- }
- if (!this.registerer) {
- this.registerer = new Registerer(this.userAgent, this.registererOptions);
- this.registerer.stateChange.addListener(state => {
- switch (state) {
- case RegistererState.Initial:
- break;
- case RegistererState.Registered:
- if (this.delegate && this.delegate.onRegistered) {
- this.delegate.onRegistered();
- }
- break;
- case RegistererState.Unregistered:
- if (this.delegate && this.delegate.onUnregistered) {
- this.delegate.onUnregistered();
- }
-
- if (this.shouldBeRegistered) {
- this.attemptRegistration();
- }
- break;
- case RegistererState.Terminated:
- break;
- default:
- throw new Error('Unknown registerer state.');
- }
- });
- }
- return this.attemptRegistration(true);
- });
- }
-
- unregister(registererUnregisterOptions) {
- return __awaiter(this, void 0, void 0, function* () {
- this.logger.log(`Unregistering UserAgent...`);
- this.shouldBeRegistered = false;
- if (!this.registerer) {
- this.logger.warn(`No registerer to unregister.`);
- return Promise.resolve();
- }
- return this.registerer.unregister(registererUnregisterOptions).then(() => {
- return;
- });
- });
- }
-
- call(destination, inviterOptions, inviterInviteOptions) {
- return __awaiter(this, void 0, void 0, function* () {
- this.logger.log(`Beginning Session...`);
-
-
-
- const maxSessions = this.options.maxSimultaneousSessions;
- if (maxSessions !== 0 && this.managedSessions.length > maxSessions) {
- return Promise.reject(new Error('Maximum number of sessions already exists.'));
- }
- const target = UserAgent.makeURI(destination);
- if (!target) {
- return Promise.reject(new Error(`Failed to create a valid URI from "${destination}"`));
- }
-
- if (!inviterOptions) {
- inviterOptions = {};
- }
- if (!inviterOptions.sessionDescriptionHandlerOptions) {
- inviterOptions.sessionDescriptionHandlerOptions = {};
- }
- if (!inviterOptions.sessionDescriptionHandlerOptions.constraints) {
- inviterOptions.sessionDescriptionHandlerOptions.constraints = this.constraints;
- }
-
-
- if (inviterOptions.earlyMedia) {
- inviterInviteOptions = inviterInviteOptions || {};
- inviterInviteOptions.requestDelegate = inviterInviteOptions.requestDelegate || {};
- const existingOnProgress = inviterInviteOptions.requestDelegate.onProgress;
- inviterInviteOptions.requestDelegate.onProgress = response => {
- if (response.message.statusCode === 183) {
- this.setupRemoteMedia(inviter);
- }
- existingOnProgress && existingOnProgress(response);
- };
- }
-
-
-
-
- if (this.options.iceStopWaitingOnServerReflexive) {
- inviterOptions.delegate = inviterOptions.delegate || {};
- inviterOptions.delegate.onSessionDescriptionHandler = sessionDescriptionHandler => {
- if (!(sessionDescriptionHandler instanceof Web.SessionDescriptionHandler)) {
- throw new Error('Session description handler not instance of SessionDescriptionHandler');
- }
- sessionDescriptionHandler.peerConnectionDelegate = {
- onicecandidate: event => {
- var _a;
- if (((_a = event.candidate) === null || _a === void 0 ? void 0 : _a.type) === 'srflx') {
- this.logger.log(`[${inviter.id}] Found srflx ICE candidate, stop waiting...`);
-
- const hsh = sessionDescriptionHandler;
- hsh.iceGatheringComplete();
- }
- }
- };
- };
- }
-
- const inviter = new Inviter(this.userAgent, target, inviterOptions);
-
- return this.sendInvite(inviter, inviterOptions, inviterInviteOptions).then(() => {
- return inviter;
- });
- });
- }
-
- hangup(session) {
- return __awaiter(this, void 0, void 0, function* () {
- this.logger.log(`[${session.id}] Hangup...`);
- if (!this.sessionExists(session)) {
- return Promise.reject(new Error('Session does not exist.'));
- }
- return this.terminate(session);
- });
- }
-
- answer(session, invitationAcceptOptions) {
- return __awaiter(this, void 0, void 0, function* () {
- this.logger.log(`[${session.id}] Accepting Invitation...`);
- if (!this.sessionExists(session)) {
- return Promise.reject(new Error('Session does not exist.'));
- }
- if (!(session instanceof Invitation)) {
- return Promise.reject(new Error('Session not instance of Invitation.'));
- }
-
- if (!invitationAcceptOptions) {
- invitationAcceptOptions = {};
- }
- if (!invitationAcceptOptions.sessionDescriptionHandlerOptions) {
- invitationAcceptOptions.sessionDescriptionHandlerOptions = {};
- }
- if (!invitationAcceptOptions.sessionDescriptionHandlerOptions.constraints) {
- invitationAcceptOptions.sessionDescriptionHandlerOptions.constraints = this.constraints;
- }
- return session.accept(invitationAcceptOptions);
- });
- }
-
- decline(session) {
- return __awaiter(this, void 0, void 0, function* () {
- this.logger.log(`[${session.id}] Rejecting Invitation...`);
- if (!this.sessionExists(session)) {
- return Promise.reject(new Error('Session does not exist.'));
- }
- if (!(session instanceof Invitation)) {
- return Promise.reject(new Error('Session not instance of Invitation.'));
- }
- return session.reject();
- });
- }
-
- hold(session) {
- return __awaiter(this, void 0, void 0, function* () {
- this.logger.log(`[${session.id}] Holding session...`);
- return this.setHold(session, true);
- });
- }
-
- unhold(session) {
- return __awaiter(this, void 0, void 0, function* () {
- this.logger.log(`[${session.id}] Unholding session...`);
- return this.setHold(session, false);
- });
- }
-
- isHeld(session) {
- const managedSession = this.sessionManaged(session);
- return managedSession ? managedSession.held : false;
- }
-
- mute(session) {
- this.logger.log(`[${session.id}] Disabling media tracks...`);
- this.setMute(session, true);
- }
-
- unmute(session) {
- this.logger.log(`[${session.id}] Enabling media tracks...`);
- this.setMute(session, false);
- }
-
- isMuted(session) {
- const managedSession = this.sessionManaged(session);
- return managedSession ? managedSession.muted : false;
- }
-
- sendDTMF(session, tone) {
- return __awaiter(this, void 0, void 0, function* () {
- this.logger.log(`[${session.id}] Sending DTMF...`);
-
- if (!/^[0-9A-D#*,]$/.exec(tone)) {
- return Promise.reject(new Error('Invalid DTMF tone.'));
- }
- if (!this.sessionExists(session)) {
- return Promise.reject(new Error('Session does not exist.'));
- }
- this.logger.log(`[${session.id}] Sending DTMF tone: ${tone}`);
- if (this.options.sendDTMFUsingSessionDescriptionHandler) {
- if (!session.sessionDescriptionHandler) {
- return Promise.reject(new Error('Session desciption handler undefined.'));
- }
- if (!session.sessionDescriptionHandler.sendDtmf(tone)) {
- return Promise.reject(new Error('Failed to send DTMF'));
- }
- return Promise.resolve();
- } else {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- const dtmf = tone;
- const duration = 2000;
- const body = {
- contentDisposition: 'render',
- contentType: 'application/dtmf-relay',
- content: 'Signal=' + dtmf + '\r\nDuration=' + duration
- };
- const requestOptions = {
- body
- };
- return session.info({
- requestOptions
- }).then(() => {
- return;
- });
- }
- });
- }
-
- transfer(session, target, options) {
- return __awaiter(this, void 0, void 0, function* () {
- this.logger.log(`[${session.id}] Referring session...`);
- if (target instanceof Session) {
- return session.refer(target, options).then(() => {
- return;
- });
- }
- const uri = UserAgent.makeURI(target);
- if (!uri) {
- return Promise.reject(new Error(`Failed to create a valid URI from "${target}"`));
- }
- return session.refer(uri, options).then(() => {
- return;
- });
- });
- }
-
- message(destination, message) {
- return __awaiter(this, void 0, void 0, function* () {
- this.logger.log(`Sending message...`);
- const target = UserAgent.makeURI(destination);
- if (!target) {
- return Promise.reject(new Error(`Failed to create a valid URI from "${destination}"`));
- }
- return new Messager(this.userAgent, target, message).message();
- });
- }
-
- get constraints() {
- let constraints = {
- audio: true,
- video: false
- };
- if (this.options.media.constraints) {
- constraints = Object.assign({}, this.options.media.constraints);
- }
- return constraints;
- }
-
- attemptReconnection(reconnectionAttempt = 1) {
- var _a, _b;
- const reconnectionAttempts = this.options.reconnectionAttempts;
- const reconnectionDelay = this.options.reconnectionDelay;
- if (!this.shouldBeConnected) {
- this.logger.log(`Should not be connected currently`);
- return;
- }
- if (this.attemptingReconnection) {
- this.logger.log(`Reconnection attempt already in progress`);
- }
- if (reconnectionAttempt > reconnectionAttempts) {
- this.logger.log(`Reconnection maximum attempts reached`);
- (_b = (_a = this.delegate) === null || _a === void 0 ? void 0 : _a.onReconnectFailed) === null || _b === void 0 ? void 0 : _b.call(_a);
- return;
- }
- if (reconnectionAttempt === 1) {
- this.logger.log(`Reconnection attempt ${reconnectionAttempt} of ${reconnectionAttempts} - trying`);
- } else {
- this.logger.log(`Reconnection attempt ${reconnectionAttempt} of ${reconnectionAttempts} - trying in ${reconnectionDelay} seconds`);
- }
- this.attemptingReconnection = true;
- setTimeout(() => {
- if (!this.shouldBeConnected) {
- this.logger.log(`Reconnection attempt ${reconnectionAttempt} of ${reconnectionAttempts} - aborted`);
- this.attemptingReconnection = false;
- return;
- }
- this.userAgent.reconnect().then(() => {
- this.logger.log(`Reconnection attempt ${reconnectionAttempt} of ${reconnectionAttempts} - succeeded`);
- this.attemptingReconnection = false;
- }).catch(error => {
- this.logger.log(`Reconnection attempt ${reconnectionAttempt} of ${reconnectionAttempts} - failed`);
- this.logger.error(error.message);
- this.attemptingReconnection = false;
- this.attemptReconnection(++reconnectionAttempt);
- });
- }, reconnectionAttempt === 1 ? 0 : reconnectionDelay * 1000);
- }
-
- attemptRegistration(withoutDelay = false) {
- this.logger.log(`Registration attempt ${withoutDelay ? 'without delay' : ''}`);
- if (!this.shouldBeRegistered) {
- this.logger.log(`Should not be registered currently`);
- return Promise.resolve();
- }
-
-
- if (this.registrationAttemptTimeout !== undefined) {
- this.logger.log(`Registration attempt already in progress`);
- return Promise.resolve();
- }
-
- const _register = () => {
-
- if (!this.registerer) {
- this.logger.log(`Registerer undefined`);
- return Promise.resolve();
- }
-
-
- if (!this.isConnected()) {
- this.logger.log(`User agent not connected`);
- return Promise.resolve();
- }
-
-
- if (this.userAgent.state === UserAgentState.Stopped) {
- this.logger.log(`User agent stopped`);
- return Promise.resolve();
- }
-
- if (!this.options.registerGuard) {
- return this.registerer.register(this.registererRegisterOptions).then(() => {
- return;
- });
- }
-
- return this.options.registerGuard().catch(error => {
- this.logger.log(`Register guard rejected will making registration attempt`);
- throw error;
- }).then(halt => {
- if (halt || !this.registerer) {
- return Promise.resolve();
- }
- return this.registerer.register(this.registererRegisterOptions).then(() => {
- return;
- });
- });
- };
-
-
-
-
-
- const computeRegistrationTimeout = lowerBound => {
- const upperBound = lowerBound * 2;
- return 1000 * (Math.random() * (upperBound - lowerBound) + lowerBound);
- };
-
- return new Promise((resolve, reject) => {
- this.registrationAttemptTimeout = setTimeout(() => {
- _register().then(() => {
- this.registrationAttemptTimeout = undefined;
- resolve();
- }).catch(error => {
- this.registrationAttemptTimeout = undefined;
- if (error instanceof RequestPendingError) {
- resolve();
- } else {
- reject(error);
- }
- });
- }, withoutDelay ? 0 : computeRegistrationTimeout(this.options.registrationRetryInterval));
- });
- }
-
- cleanupMedia(session) {
- const managedSession = this.sessionManaged(session);
- if (!managedSession) {
- throw new Error('Managed session does not exist.');
- }
- if (managedSession.mediaLocal) {
- if (managedSession.mediaLocal.video) {
- managedSession.mediaLocal.video.srcObject = null;
- managedSession.mediaLocal.video.pause();
- }
- }
- if (managedSession.mediaRemote) {
- if (managedSession.mediaRemote.audio) {
- managedSession.mediaRemote.audio.srcObject = null;
- managedSession.mediaRemote.audio.pause();
- }
- if (managedSession.mediaRemote.video) {
- managedSession.mediaRemote.video.srcObject = null;
- managedSession.mediaRemote.video.pause();
- }
- }
- }
-
- enableReceiverTracks(session, enable) {
- if (!this.sessionExists(session)) {
- throw new Error('Session does not exist.');
- }
- const sessionDescriptionHandler = session.sessionDescriptionHandler;
- if (!(sessionDescriptionHandler instanceof Web.SessionDescriptionHandler)) {
- throw new Error("Session's session description handler not instance of SessionDescriptionHandler.");
- }
- sessionDescriptionHandler.enableReceiverTracks(enable);
- }
-
- enableSenderTracks(session, enable) {
- if (!this.sessionExists(session)) {
- throw new Error('Session does not exist.');
- }
- const sessionDescriptionHandler = session.sessionDescriptionHandler;
- if (!(sessionDescriptionHandler instanceof Web.SessionDescriptionHandler)) {
- throw new Error("Session's session description handler not instance of SessionDescriptionHandler.");
- }
- sessionDescriptionHandler.enableSenderTracks(enable);
- }
-
- initSession(session, referralInviterOptions) {
-
- this.sessionAdd(session);
-
- if (this.delegate && this.delegate.onCallCreated) {
- this.delegate.onCallCreated(session);
- }
-
- session.stateChange.addListener(state => {
- this.logger.log(`[${session.id}] Session state changed to ${state}`);
- switch (state) {
- case SessionState.Initial:
- break;
- case SessionState.Establishing:
- break;
- case SessionState.Established:
- this.setupLocalMedia(session);
- this.setupRemoteMedia(session);
- if (this.delegate && this.delegate.onCallAnswered) {
- this.delegate.onCallAnswered(session);
- }
- break;
- case SessionState.Terminating:
-
- case SessionState.Terminated:
-
-
-
- if (this.sessionExists(session)) {
- this.cleanupMedia(session);
- this.sessionRemove(session);
- if (this.delegate && this.delegate.onCallHangup) {
- this.delegate.onCallHangup(session);
- }
- }
- break;
- default:
- throw new Error('Unknown session state.');
- }
- });
-
-
- session.delegate = session.delegate || {};
- session.delegate.onInfo = info => {
-
-
-
-
-
-
-
-
-
- var _a;
-
-
-
-
-
-
-
-
-
- if (((_a = this.delegate) === null || _a === void 0 ? void 0 : _a.onCallDTMFReceived) === undefined) {
- info.reject();
- return;
- }
-
- const contentType = info.request.getHeader('content-type');
- if (!contentType || !/^application\/dtmf-relay/i.exec(contentType)) {
- info.reject();
- return;
- }
-
- const body = info.request.body.split('\r\n', 2);
- if (body.length !== 2) {
- info.reject();
- return;
- }
-
- let tone;
- const toneRegExp = /^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/;
- if (body[0] !== undefined && toneRegExp.test(body[0])) {
- tone = body[0].replace(toneRegExp, '$2');
- }
- if (!tone) {
- info.reject();
- return;
- }
-
- let duration;
- const durationRegExp = /^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;
- if (body[1] !== undefined && durationRegExp.test(body[1])) {
- duration = parseInt(body[1].replace(durationRegExp, '$2'), 10);
- }
- if (!duration) {
- info.reject();
- return;
- }
- info.accept().then(() => {
- if (this.delegate && this.delegate.onCallDTMFReceived) {
- if (!tone || !duration) {
- throw new Error('Tone or duration undefined.');
- }
- this.delegate.onCallDTMFReceived(session, tone, duration);
- }
- }).catch(error => {
- this.logger.error(error.message);
- });
- };
- session.delegate.onRefer = referral => {
- referral.accept().then(() => this.sendInvite(referral.makeInviter(referralInviterOptions), referralInviterOptions)).catch(error => {
- this.logger.error(error.message);
- });
- };
- }
-
- optionsPingRun(requestURI, fromURI, toURI) {
-
- if (this.options.optionsPingInterval < 1) {
- throw new Error('Invalid options ping interval.');
- }
-
- if (this.optionsPingRunning) {
- return;
- }
- this.optionsPingRunning = true;
-
- this.optionsPingTimeout = setTimeout(() => {
- this.optionsPingTimeout = undefined;
-
- const onPingSuccess = () => {
-
- this.optionsPingFailure = false;
-
- if (this.optionsPingRunning) {
- this.optionsPingRunning = false;
- this.optionsPingRun(requestURI, fromURI, toURI);
- }
- };
-
- const onPingFailure = () => {
- this.logger.error('OPTIONS ping failed');
-
- this.optionsPingFailure = true;
-
- this.optionsPingRunning = false;
-
- this.userAgent.transport.disconnect().catch(error => this.logger.error(error));
- };
-
- const core = this.userAgent.userAgentCore;
- const message = core.makeOutgoingRequestMessage('OPTIONS', requestURI, fromURI, toURI, {});
-
- this.optionsPingRequest = core.request(message, {
- onAccept: () => {
- this.optionsPingRequest = undefined;
- onPingSuccess();
- },
- onReject: response => {
- this.optionsPingRequest = undefined;
-
-
-
- if (response.message.statusCode === 408 || response.message.statusCode === 503) {
- onPingFailure();
- } else {
- onPingSuccess();
- }
- }
- });
- }, this.options.optionsPingInterval * 1000);
- }
-
- optionsPingStart() {
- this.logger.log(`OPTIONS pings started`);
-
- let requestURI, fromURI, toURI;
- if (this.options.optionsPingRequestURI) {
-
- requestURI = UserAgent.makeURI(this.options.optionsPingRequestURI);
- if (!requestURI) {
- throw new Error('Failed to create Request URI.');
- }
-
- fromURI = this.userAgent.contact.uri.clone();
- toURI = this.userAgent.contact.uri.clone();
- } else if (this.options.aor) {
-
- const uri = UserAgent.makeURI(this.options.aor);
- if (!uri) {
- throw new Error('Failed to create URI.');
- }
- requestURI = uri.clone();
- requestURI.user = undefined;
- fromURI = uri.clone();
- toURI = uri.clone();
- } else {
- this.logger.error('You have enabled sending OPTIONS pings and as such you must provide either ' + 'a) an AOR to register, or b) an RURI to use for the target of the OPTIONS ping requests. ');
- return;
- }
-
- this.optionsPingRun(requestURI, fromURI, toURI);
- }
-
- optionsPingStop() {
- this.logger.log(`OPTIONS pings stopped`);
- this.optionsPingRunning = false;
- this.optionsPingFailure = false;
- if (this.optionsPingRequest) {
- this.optionsPingRequest.dispose();
- this.optionsPingRequest = undefined;
- }
- if (this.optionsPingTimeout) {
- clearTimeout(this.optionsPingTimeout);
- this.optionsPingTimeout = undefined;
- }
- }
-
- sendInvite(inviter, inviterOptions, inviterInviteOptions) {
- return __awaiter(this, void 0, void 0, function* () {
-
- this.initSession(inviter, inviterOptions);
-
- return inviter.invite(inviterInviteOptions).then(() => {
- this.logger.log(`[${inviter.id}] Sent INVITE`);
- });
- });
- }
- managedSessionFactory(_sessionManagerPlus, session) {
- return {
- session,
- held: false,
- muted: false
- };
- }
-
- sessionAdd(session) {
- const managedSession = this.managedSessionFactory(this, session);
- this.managedSessions.push(managedSession);
- }
-
- sessionExists(session) {
- return this.sessionManaged(session) !== undefined;
- }
-
- sessionManaged(session) {
- return this.managedSessions.find(el => el.session.id === session.id);
- }
-
- sessionRemove(session) {
- this.managedSessions = this.managedSessions.filter(el => el.session.id !== session.id);
- }
-
- setHold(session, hold) {
- return __awaiter(this, void 0, void 0, function* () {
- if (!this.sessionExists(session)) {
- return Promise.reject(new Error('Session does not exist.'));
- }
-
- if (this.isHeld(session) === hold) {
- return Promise.resolve();
- }
- const sessionDescriptionHandler = session.sessionDescriptionHandler;
- if (!(sessionDescriptionHandler instanceof Web.SessionDescriptionHandler)) {
- throw new Error("Session's session description handler not instance of SessionDescriptionHandler.");
- }
- const options = {
- requestDelegate: {
- onAccept: () => {
- const managedSession = this.sessionManaged(session);
- if (managedSession !== undefined) {
- managedSession.held = hold;
- this.enableReceiverTracks(session, !managedSession.held);
- this.enableSenderTracks(session, !managedSession.held && !managedSession.muted);
- if (this.delegate && this.delegate.onCallHold) {
- this.delegate.onCallHold(session, managedSession.held);
- }
- }
- },
- onReject: () => {
- this.logger.warn(`[${session.id}] Re-invite request was rejected`);
- const managedSession = this.sessionManaged(session);
- if (managedSession !== undefined) {
- managedSession.held = !hold;
- this.enableReceiverTracks(session, !managedSession.held);
- this.enableSenderTracks(session, !managedSession.held && !managedSession.muted);
- if (this.delegate && this.delegate.onCallHold) {
- this.delegate.onCallHold(session, managedSession.held);
- }
- }
- }
- }
- };
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- const sessionDescriptionHandlerOptions = session.sessionDescriptionHandlerOptionsReInvite;
- sessionDescriptionHandlerOptions.hold = hold;
- session.sessionDescriptionHandlerOptionsReInvite = sessionDescriptionHandlerOptions;
-
- const managedSession = this.sessionManaged(session);
- if (!managedSession) {
- throw new Error('Managed session is undefiend.');
- }
- managedSession.held = hold;
-
- return session.invite(options).then(() => {
-
- const managedSession = this.sessionManaged(session);
- if (managedSession !== undefined) {
- this.enableReceiverTracks(session, !managedSession.held);
- this.enableSenderTracks(session, !managedSession.held && !managedSession.muted);
- }
- }).catch(error => {
- managedSession.held = !hold;
- if (error instanceof RequestPendingError) {
- this.logger.error(`[${session.id}] A hold request is already in progress.`);
- }
- throw error;
- });
- });
- }
-
- setMute(session, mute) {
- if (!this.sessionExists(session)) {
- this.logger.warn(`[${session.id}] A session is required to enabled/disable media tracks`);
- return;
- }
- if (session.state !== SessionState.Established) {
- this.logger.warn(`[${session.id}] An established session is required to enable/disable media tracks`);
- return;
- }
- const managedSession = this.sessionManaged(session);
- if (managedSession !== undefined) {
- managedSession.muted = mute;
- this.enableSenderTracks(session, !managedSession.held && !managedSession.muted);
- }
- }
-
- setupLocalMedia(session) {
- const managedSession = this.sessionManaged(session);
- if (!managedSession) {
- throw new Error('Managed session does not exist.');
- }
-
-
- const mediaLocal = typeof this.options.media.local === 'function' ? this.options.media.local(session) : this.options.media.local;
- managedSession.mediaLocal = mediaLocal;
- const mediaElement = mediaLocal === null || mediaLocal === void 0 ? void 0 : mediaLocal.video;
- if (mediaElement) {
- const localStream = this.getLocalMediaStream(session);
- if (!localStream) {
- throw new Error('Local media stream undefiend.');
- }
- mediaElement.srcObject = localStream;
- mediaElement.volume = 0;
- mediaElement.play().catch(error => {
- this.logger.error(`[${session.id}] Failed to play local media`);
- this.logger.error(error.message);
- });
- }
- }
-
- setupRemoteMedia(session) {
- const managedSession = this.sessionManaged(session);
- if (!managedSession) {
- throw new Error('Managed session does not exist.');
- }
-
-
- const mediaRemote = typeof this.options.media.remote === 'function' ? this.options.media.remote(session) : this.options.media.remote;
- managedSession.mediaRemote = mediaRemote;
- const mediaElement = (mediaRemote === null || mediaRemote === void 0 ? void 0 : mediaRemote.video) || (mediaRemote === null || mediaRemote === void 0 ? void 0 : mediaRemote.audio);
- if (mediaElement) {
- const remoteStream = this.getRemoteMediaStream(session);
- if (!remoteStream) {
- throw new Error('Remote media stream undefiend.');
- }
- mediaElement.autoplay = true;
- mediaElement.srcObject = remoteStream;
- mediaElement.play().catch(error => {
- this.logger.error(`[${session.id}] Failed to play remote media`);
- this.logger.error(error.message);
- });
- remoteStream.onaddtrack = () => {
- this.logger.log(`Remote media onaddtrack`);
- mediaElement.load();
- mediaElement.play().catch(error => {
- this.logger.error(`[${session.id}] Failed to play remote media`);
- this.logger.error(error.message);
- });
- };
- }
- }
-
- terminate(session) {
- return __awaiter(this, void 0, void 0, function* () {
- this.logger.log(`[${session.id}] Terminating...`);
- switch (session.state) {
- case SessionState.Initial:
- if (session instanceof Inviter) {
- return session.cancel().then(() => {
- this.logger.log(`[${session.id}] Inviter never sent INVITE (canceled)`);
- });
- } else if (session instanceof Invitation) {
- return session.reject().then(() => {
- this.logger.log(`[${session.id}] Invitation rejected (sent 480)`);
- });
- } else {
- throw new Error('Unknown session type.');
- }
- case SessionState.Establishing:
- if (session instanceof Inviter) {
- return session.cancel().then(() => {
- this.logger.log(`[${session.id}] Inviter canceled (sent CANCEL)`);
- });
- } else if (session instanceof Invitation) {
- return session.reject().then(() => {
- this.logger.log(`[${session.id}] Invitation rejected (sent 480)`);
- });
- } else {
- throw new Error('Unknown session type.');
- }
- case SessionState.Established:
- return session.bye().then(() => {
- this.logger.log(`[${session.id}] Session ended (sent BYE)`);
- });
- case SessionState.Terminating:
- break;
- case SessionState.Terminated:
- break;
- default:
- throw new Error('Unknown state');
- }
- this.logger.log(`[${session.id}] Terminating in state ${session.state}, no action taken`);
- return Promise.resolve();
- });
- }
- }
- class SimpleUserPlus {
-
- constructor(server, options = {}) {
-
- Object.defineProperty(this, "delegate", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "logger", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "options", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "session", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: undefined
- });
- Object.defineProperty(this, "sessionManager", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
-
- this.delegate = options.delegate;
-
- this.options = Object.assign({}, options);
-
- const sessionManagerOptions = {
- aor: this.options.aor,
- delegate: {
- onCallAnswered: () => {
- var _a, _b;
- return (_b = (_a = this.delegate) === null || _a === void 0 ? void 0 : _a.onCallAnswered) === null || _b === void 0 ? void 0 : _b.call(_a);
- },
- onCallCreated: session => {
- var _a, _b, _c, _d;
- this.session = session;
- (_b = (_a = this.delegate) === null || _a === void 0 ? void 0 : _a.onCallBegin) === null || _b === void 0 ? void 0 : _b.call(_a, session);
- (_d = (_c = this.delegate) === null || _c === void 0 ? void 0 : _c.onCallCreated) === null || _d === void 0 ? void 0 : _d.call(_c);
- },
- onCallReceived: session => {
- var _a, _b, _c, _d;
- (_b = (_a = this.delegate) === null || _a === void 0 ? void 0 : _a.onCallReceived) === null || _b === void 0 ? void 0 : _b.call(_a);
- (_d = (_c = this.delegate) === null || _c === void 0 ? void 0 : _c.onInvite) === null || _d === void 0 ? void 0 : _d.call(_c, session);
- },
- onCallHangup: () => {
- var _a, _b;
- this.session = undefined;
- ((_a = this.delegate) === null || _a === void 0 ? void 0 : _a.onCallHangup) && ((_b = this.delegate) === null || _b === void 0 ? void 0 : _b.onCallHangup());
- },
- onCallHold: (_s, held) => {
- var _a, _b;
- return (_b = (_a = this.delegate) === null || _a === void 0 ? void 0 : _a.onCallHold) === null || _b === void 0 ? void 0 : _b.call(_a, held);
- },
- onCallDTMFReceived: (_s, tone, dur) => {
- var _a, _b;
- return (_b = (_a = this.delegate) === null || _a === void 0 ? void 0 : _a.onCallDTMFReceived) === null || _b === void 0 ? void 0 : _b.call(_a, tone, dur);
- },
- onMessageReceived: message => {
- var _a, _b;
- return (_b = (_a = this.delegate) === null || _a === void 0 ? void 0 : _a.onMessageReceived) === null || _b === void 0 ? void 0 : _b.call(_a, message.request.body);
- },
- onRegistered: () => {
- var _a, _b;
- return (_b = (_a = this.delegate) === null || _a === void 0 ? void 0 : _a.onRegistered) === null || _b === void 0 ? void 0 : _b.call(_a);
- },
- onUnregistered: () => {
- var _a, _b;
- return (_b = (_a = this.delegate) === null || _a === void 0 ? void 0 : _a.onUnregistered) === null || _b === void 0 ? void 0 : _b.call(_a);
- },
- onServerConnect: () => {
- var _a, _b;
- return (_b = (_a = this.delegate) === null || _a === void 0 ? void 0 : _a.onServerConnect) === null || _b === void 0 ? void 0 : _b.call(_a);
- },
- onServerDisconnect: () => {
- var _a, _b;
- return (_b = (_a = this.delegate) === null || _a === void 0 ? void 0 : _a.onServerDisconnect) === null || _b === void 0 ? void 0 : _b.call(_a);
- },
- onReconnectFailed: () => {
- var _a, _b;
- return (_b = (_a = this.delegate) === null || _a === void 0 ? void 0 : _a.onReconnectFailed) === null || _b === void 0 ? void 0 : _b.call(_a);
- },
- onReconnectStart: () => {
- var _a, _b;
- return (_b = (_a = this.delegate) === null || _a === void 0 ? void 0 : _a.onReconnectStart) === null || _b === void 0 ? void 0 : _b.call(_a);
- }
- },
- maxSimultaneousSessions: 1,
- media: this.options.media,
- optionsPingInterval: this.options.optionsPingInterval,
- optionsPingRequestURI: this.options.aor,
- reconnectionAttempts: this.options.reconnectionAttempts,
- reconnectionDelay: this.options.reconnectionDelay,
- registererOptions: this.options.registererOptions,
- sendDTMFUsingSessionDescriptionHandler: this.options.sendDTMFUsingSessionDescriptionHandler,
- userAgentOptions: this.options.userAgentOptions
- };
- this.sessionManager = new SessionManagerPlus(server, sessionManagerOptions);
- this.sessionManager.userAgent.stateChange.addListener(state => {
- var _a, _b;
- (_b = (_a = this.delegate) === null || _a === void 0 ? void 0 : _a.onUserAgentStateChange) === null || _b === void 0 ? void 0 : _b.call(_a, state);
- });
-
- this.logger = this.sessionManager.userAgent.getLogger('sip.SimpleUser');
- }
-
- get id() {
- return this.options.userAgentOptions && this.options.userAgentOptions.displayName || 'Anonymous';
- }
-
- get localMediaStream() {
- return this.session && this.sessionManager.getLocalMediaStream(this.session);
- }
-
- get remoteMediaStream() {
- return this.session && this.sessionManager.getRemoteMediaStream(this.session);
- }
-
- get localAudioTrack() {
- return this.session && this.sessionManager.getLocalAudioTrack(this.session);
- }
-
- get localVideoTrack() {
- return this.session && this.sessionManager.getLocalVideoTrack(this.session);
- }
-
- get remoteAudioTrack() {
- return this.session && this.sessionManager.getRemoteAudioTrack(this.session);
- }
-
- get remoteVideoTrack() {
- return this.session && this.sessionManager.getRemoteVideoTrack(this.session);
- }
-
- connect() {
- this.logger.log(`[${this.id}] Connecting UserAgent...`);
- return this.sessionManager.connect();
- }
-
- disconnect() {
- this.logger.log(`[${this.id}] Disconnecting UserAgent...`);
- return this.sessionManager.disconnect();
- }
-
- isConnected() {
- return this.sessionManager.isConnected();
- }
-
- register(registererRegisterOptions) {
- this.logger.log(`[${this.id}] Registering UserAgent...`);
- return this.sessionManager.register(registererRegisterOptions);
- }
-
- unregister(registererUnregisterOptions) {
- this.logger.log(`[${this.id}] Unregistering UserAgent...`);
- return this.sessionManager.unregister(registererUnregisterOptions);
- }
-
- call(destination, inviterOptions, inviterInviteOptions) {
- this.logger.log(`[${this.id}] Beginning Session...`);
- if (this.session) {
- return Promise.reject(new Error('Session already exists.'));
- }
- return this.sessionManager.call(destination, inviterOptions, inviterInviteOptions).then(() => {
- return;
- });
- }
-
- hangup() {
- this.logger.log(`[${this.id}] Hangup...`);
- if (!this.session) {
- return Promise.reject(new Error('Session does not exist.'));
- }
- return this.sessionManager.hangup(this.session).then(() => {
- this.session = undefined;
- });
- }
-
- answer(invitationAcceptOptions) {
- this.logger.log(`[${this.id}] Accepting Invitation...`);
- if (!this.session) {
- return Promise.reject(new Error('Session does not exist.'));
- }
- return this.sessionManager.answer(this.session, invitationAcceptOptions);
- }
-
- decline() {
- this.logger.log(`[${this.id}] rejecting Invitation...`);
- if (!this.session) {
- return Promise.reject(new Error('Session does not exist.'));
- }
- return this.sessionManager.decline(this.session);
- }
-
- hold() {
- this.logger.log(`[${this.id}] holding session...`);
- if (!this.session) {
- return Promise.reject(new Error('Session does not exist.'));
- }
- return this.sessionManager.hold(this.session);
- }
-
- unhold() {
- this.logger.log(`[${this.id}] unholding session...`);
- if (!this.session) {
- return Promise.reject(new Error('Session does not exist.'));
- }
- return this.sessionManager.unhold(this.session);
- }
-
- isHeld() {
- return this.session ? this.sessionManager.isHeld(this.session) : false;
- }
-
- mute() {
- this.logger.log(`[${this.id}] disabling media tracks...`);
- return this.session && this.sessionManager.mute(this.session);
- }
-
- unmute() {
- this.logger.log(`[${this.id}] enabling media tracks...`);
- return this.session && this.sessionManager.unmute(this.session);
- }
-
- isMuted() {
- return this.session ? this.sessionManager.isMuted(this.session) : false;
- }
-
- sendDTMF(tone) {
- this.logger.log(`[${this.id}] sending DTMF...`);
- if (!this.session) {
- return Promise.reject(new Error('Session does not exist.'));
- }
- return this.sessionManager.sendDTMF(this.session, tone);
- }
-
- message(destination, message) {
- this.logger.log(`[${this.id}] sending message...`);
- return this.sessionManager.message(destination, message);
- }
- }
- let has = Object.prototype.hasOwnProperty,
- prefix = '~';
- function Events() {}
- if (Object.create) {
- Events.prototype = Object.create(null);
-
-
-
-
-
- if (!new Events().__proto__) prefix = false;
- }
- function EE(fn, context, once) {
- this.fn = fn;
- this.context = context;
- this.once = once || false;
- }
- function addListener(emitter, event, fn, context, once) {
- if (typeof fn !== 'function') {
- throw new TypeError('The listener must be a function');
- }
- const listener = new EE(fn, context || emitter, once),
- evt = prefix ? prefix + event : event;
- if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);else emitter._events[evt] = [emitter._events[evt], listener];
- return emitter;
- }
- function clearEvent(emitter, evt) {
- if (--emitter._eventsCount === 0) emitter._events = new Events();else delete emitter._events[evt];
- }
- function EventEmitter() {
- this._events = new Events();
- this._eventsCount = 0;
- }
- EventEmitter.prototype.eventNames = function eventNames() {
- let names = [],
- events,
- name;
- if (this._eventsCount === 0) return names;
- for (name in events = this._events) {
- if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
- }
- if (Object.getOwnPropertySymbols) {
- return names.concat(Object.getOwnPropertySymbols(events));
- }
- return names;
- };
- EventEmitter.prototype.listeners = function listeners(event) {
- const evt = prefix ? prefix + event : event,
- handlers = this._events[evt];
- if (!handlers) return [];
- if (handlers.fn) return [handlers.fn];
- for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
- ee[i] = handlers[i].fn;
- }
- return ee;
- };
- EventEmitter.prototype.listenerCount = function listenerCount(event) {
- const evt = prefix ? prefix + event : event,
- listeners = this._events[evt];
- if (!listeners) return 0;
- if (listeners.fn) return 1;
- return listeners.length;
- };
- EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
- const evt = prefix ? prefix + event : event;
- if (!this._events[evt]) return false;
- let listeners = this._events[evt],
- len = arguments.length,
- args,
- i;
- if (listeners.fn) {
- if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
- switch (len) {
- case 1:
- return listeners.fn.call(listeners.context), true;
- case 2:
- return listeners.fn.call(listeners.context, a1), true;
- case 3:
- return listeners.fn.call(listeners.context, a1, a2), true;
- case 4:
- return listeners.fn.call(listeners.context, a1, a2, a3), true;
- case 5:
- return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
- case 6:
- return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
- }
- for (i = 1, args = new Array(len - 1); i < len; i++) {
- args[i - 1] = arguments[i];
- }
- listeners.fn.apply(listeners.context, args);
- } else {
- let length = listeners.length,
- j;
- for (i = 0; i < length; i++) {
- if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
- switch (len) {
- case 1:
- listeners[i].fn.call(listeners[i].context);
- break;
- case 2:
- listeners[i].fn.call(listeners[i].context, a1);
- break;
- case 3:
- listeners[i].fn.call(listeners[i].context, a1, a2);
- break;
- case 4:
- listeners[i].fn.call(listeners[i].context, a1, a2, a3);
- break;
- default:
- if (!args) for (j = 1, args = new Array(len - 1); j < len; j++) {
- args[j - 1] = arguments[j];
- }
- listeners[i].fn.apply(listeners[i].context, args);
- }
- }
- }
- return true;
- };
- EventEmitter.prototype.on = function on(event, fn, context) {
- return addListener(this, event, fn, context, false);
- };
- EventEmitter.prototype.once = function once(event, fn, context) {
- return addListener(this, event, fn, context, true);
- };
- EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
- const evt = prefix ? prefix + event : event;
- if (!this._events[evt]) return this;
- if (!fn) {
- clearEvent(this, evt);
- return this;
- }
- const listeners = this._events[evt];
- if (listeners.fn) {
- if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) {
- clearEvent(this, evt);
- }
- } else {
- for (var i = 0, events = [], length = listeners.length; i < length; i++) {
- if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) {
- events.push(listeners[i]);
- }
- }
-
-
-
- if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;else clearEvent(this, evt);
- }
- return this;
- };
- EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
- let evt;
- if (event) {
- evt = prefix ? prefix + event : event;
- if (this._events[evt]) clearEvent(this, evt);
- } else {
- this._events = new Events();
- this._eventsCount = 0;
- }
- return this;
- };
- EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
- EventEmitter.prototype.addListener = EventEmitter.prototype.on;
- EventEmitter.prefixed = prefix;
- EventEmitter.EventEmitter = EventEmitter;
- if ('undefined' !== typeof module) {
- module.exports = EventEmitter;
- }
- function upperCamelToLowerSnake(s) {
- s = s.replace(/\s/g, '');
- s = s.replace(/([A-Z])/g, '_$1');
- s = s.toLowerCase();
- s = s.replace(/^_/, '');
- s = s.replace(/_$/, '');
- return s;
- }
- const getDateTime = () => {
- const timestamp = Date.now();
- const date = new Date(timestamp);
- const year = date.getFullYear();
- const month = String(date.getMonth() + 1).padStart(2, '0');
- const day = String(date.getDate()).padStart(2, '0');
- const hours = String(date.getHours()).padStart(2, '0');
- const minutes = String(date.getMinutes()).padStart(2, '0');
- const seconds = String(date.getSeconds()).padStart(2, '0');
- const milliseconds = String(date.getMilliseconds()).padStart(3, '0');
- const formattedDateTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}.${milliseconds}`;
- return formattedDateTime;
- };
- var LoggerLevels;
- (function (LoggerLevels) {
- LoggerLevels[LoggerLevels["error"] = 0] = "error";
- LoggerLevels[LoggerLevels["warn"] = 1] = "warn";
- LoggerLevels[LoggerLevels["log"] = 2] = "log";
- LoggerLevels[LoggerLevels["debug"] = 3] = "debug";
- })(LoggerLevels || (LoggerLevels = {}));
- class Logger {
- constructor(level, category, label) {
- Object.defineProperty(this, "_level", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "category", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "label", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- this._level = level;
- this.category = category;
- this.label = label;
- }
- error(content) {
- this.genericLog(LoggerLevels.error, content);
- }
- warn(content) {
- this.genericLog(LoggerLevels.warn, content);
- }
- log(content) {
- this.genericLog(LoggerLevels.log, content);
- }
- debug(content) {
- this.genericLog(LoggerLevels.debug, content);
- }
- genericLog(levelToLog, content) {
- if (this._level >= levelToLog) {
- this.print(levelToLog, this.category, this.label, content);
- }
- }
- print(levelToLog, category, label, content) {
- if (typeof content === 'string') {
- const prefix = [getDateTime()];
- if (label) {
- prefix.push(label);
- }
- content = prefix.concat(content).join(' | ');
- }
- switch (levelToLog) {
- case LoggerLevels.error:
- console.error(`%c${category}`, 'color: blue;', content);
- break;
- case LoggerLevels.warn:
- console.warn(`%c${category}`, 'color: blue;', content);
- break;
- case LoggerLevels.log:
- console.log(`%c${category}`, 'color: blue;', content);
- break;
- case LoggerLevels.debug:
- console.debug(`%c${category}`, 'color: blue;', content);
- break;
- }
- }
- get level() {
- return this._level;
- }
- set level(newLevel) {
- if (newLevel >= 0 && newLevel <= 3) {
- this._level = newLevel;
- } else if (newLevel > 3) {
- this._level = 3;
-
- } else if (LoggerLevels.hasOwnProperty(newLevel)) {
- this._level = newLevel;
- } else {
- this.error("invalid 'level' parameter value: " + JSON.stringify(newLevel));
- }
- }
- }
- var Scene;
- (function (Scene) {
- Scene["Manual"] = "manual";
- Scene["Robot"] = "robot";
- Scene["Monitor"] = "monitor";
- Scene["Predictive"] = "predictive";
- Scene["Wechat"] = "wechat";
- })(Scene || (Scene = {}));
- var MonitorScene;
- (function (MonitorScene) {
- MonitorScene["All"] = "all";
- MonitorScene["Manual"] = "manual";
- MonitorScene["Robot"] = "robot";
- MonitorScene["Predictive"] = "predictive";
- })(MonitorScene || (MonitorScene = {}));
- var SocketStatus;
- (function (SocketStatus) {
- SocketStatus["Initial"] = "Initial";
- SocketStatus["Connecting"] = "Connecting";
- SocketStatus["Connected"] = "Connected";
- SocketStatus["Ready"] = "Ready";
- SocketStatus["ReTry"] = "ReTry";
- SocketStatus["Terminated"] = "Terminated";
- })(SocketStatus || (SocketStatus = {}));
- var SIPStatus;
- (function (SIPStatus) {
- SIPStatus["Initial"] = "Initial";
- SIPStatus["Started"] = "Started";
- SIPStatus["Connecting"] = "Connecting";
- SIPStatus["Connected"] = "Connected";
- SIPStatus["Ready"] = "Ready";
- SIPStatus["ReTry"] = "ReTry";
- SIPStatus["Terminated"] = "Terminated";
- })(SIPStatus || (SIPStatus = {}));
- var CTIStatus;
- (function (CTIStatus) {
- CTIStatus["Initial"] = "Initial";
- CTIStatus["Ready"] = "Ready";
- CTIStatus["ReTry"] = "ReTry";
- CTIStatus["Terminated"] = "Terminated";
- })(CTIStatus || (CTIStatus = {}));
- var CallStatus;
- (function (CallStatus) {
- CallStatus["Started"] = "Started";
- CallStatus["Stopped"] = "Stopped";
- })(CallStatus || (CallStatus = {}));
- var SessionStatus;
- (function (SessionStatus) {
-
- SessionStatus["Initial"] = "Initial";
-
- SessionStatus["Establishing"] = "Establishing";
-
- SessionStatus["Established"] = "Established";
-
- SessionStatus["Terminating"] = "Terminating";
-
- SessionStatus["Terminated"] = "Terminated";
- })(SessionStatus || (SessionStatus = {}));
- var CTIErrorType;
- (function (CTIErrorType) {
- CTIErrorType["SdkTerminated"] = "SdkTerminated";
- CTIErrorType["SdkError"] = "SdkError";
- CTIErrorType["ServerTerminated"] = "ServerTerminated";
- CTIErrorType["ServerError"] = "ServerError";
- })(CTIErrorType || (CTIErrorType = {}));
- var HskTerminatedCode;
- (function (HskTerminatedCode) {
- HskTerminatedCode["CTITerminated"] = "100001";
- HskTerminatedCode["GetUserMedia"] = "100002";
- HskTerminatedCode["GetInitConfig"] = "100003";
- HskTerminatedCode["SocketOnError"] = "110001";
- HskTerminatedCode["SocketOnConnectError"] = "110002";
- HskTerminatedCode["SocketOnDisconnect"] = "110003";
- HskTerminatedCode["SocketRepeatLogin"] = "110004";
- HskTerminatedCode["SocketOnReconnectFailed"] = "110007";
- HskTerminatedCode["SIPInitUserAgent"] = "120001";
- HskTerminatedCode["SIPInitRegister"] = "120002";
- HskTerminatedCode["SIPUserAgentStateStopped"] = "120003";
- HskTerminatedCode["SIPTransportStateDisconnected"] = "120004";
- HskTerminatedCode["SIPRegistererStateTerminated"] = "120005";
- HskTerminatedCode["SIPOnDisconnect"] = "120006";
- HskTerminatedCode["SIPInitTransport"] = "120007";
- HskTerminatedCode["SipHeartBeatErr"] = "120008";
- HskTerminatedCode["SIPUnRegistered"] = "120009";
- })(HskTerminatedCode || (HskTerminatedCode = {}));
- var SdkErrorCode;
- (function (SdkErrorCode) {
- SdkErrorCode["Answer"] = "200001";
- SdkErrorCode["Bye"] = "200002";
- SdkErrorCode["InvitationCancel"] = "200003";
- SdkErrorCode["AssignStream"] = "200004";
- SdkErrorCode["FetchError"] = "200005";
- })(SdkErrorCode || (SdkErrorCode = {}));
- var CTIEvent;
- (function (CTIEvent) {
- CTIEvent["OnCtiError"] = "OnCtiError";
- CTIEvent["OnSessionStatusChange"] = "OnSessionStatusChange";
- CTIEvent["OnInitalSuccess"] = "OnInitalSuccess";
- CTIEvent["OnAgentWorkReport"] = "OnAgentWorkReport";
- CTIEvent["OnRingStart"] = "OnRingStart";
- CTIEvent["OnRingEnd"] = "OnRingEnd";
- CTIEvent["OnDetectedTone"] = "OnDetectedTone";
- CTIEvent["OnAgentReport"] = "OnAgentReport";
- CTIEvent["OnCallReportInfo"] = "OnCallReportInfo";
-
- CTIEvent["OnCallRing"] = "OnCallRing";
- CTIEvent["OnCallEnd"] = "OnCallEnd";
- CTIEvent["OnCallAnswer"] = "OnCallAnswer";
- CTIEvent["OnAgentGroupQuery"] = "OnAgentGroupQuery";
- CTIEvent["OnMethodResponseEvent"] = "OnMethodResponseEvent";
- CTIEvent["OnEventPrompt"] = "OnEventPrompt";
- CTIEvent["OnPrompt"] = "OnPrompt";
- })(CTIEvent || (CTIEvent = {}));
- var BaseOption;
- (function (BaseOption) {
- BaseOption["TrackParams"] = "trackParams";
- BaseOption["ENV"] = "env";
- BaseOption["LoggerLevel"] = "loggerLevel";
- })(BaseOption || (BaseOption = {}));
- const items = [[BaseOption.TrackParams, {}], [BaseOption.ENV, 'test'], [BaseOption.LoggerLevel, LoggerLevels.debug]];
- const baseOption = new Map();
- const resetBaseOption = () => {
- items.forEach((i, v) => baseOption.set(i, v));
- };
- resetBaseOption();
- const setBaseOption = (key, value, isInit = false) => {
- if (!isInit && typeof value === 'object') {
- baseOption.set(key, Object.assign(Object.assign({}, baseOption.get(key)), value));
- } else {
- baseOption.set(key, value);
- }
- };
- const getBaseOption = key => {
- return baseOption.get(key);
- };
- const generateUUID = () => {
- return 'xxxxxxxxxxxx4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
- const r = Math.random() * 16 | 0;
- const v = c === 'x' ? r : r & 0x3 | 0x8;
- return v.toString(16);
- }).replace(/-/g, '');
- };
- const getClientId = () => {
- if (!window.HS_CTI_CLIENT_ID) {
- window.HS_CTI_CLIENT_ID = generateUUID();
- }
- return window.HS_CTI_CLIENT_ID;
- };
- var AudioName;
- (function (AudioName) {
- AudioName["RingAudio"] = "_ringAudio";
- AudioName["WaitAudio"] = "_waitAudio";
- AudioName["ByeAudio"] = "_byeAudio";
- })(AudioName || (AudioName = {}));
- var TrackSource;
- (function (TrackSource) {
- TrackSource["FeSocket"] = "fe-socket";
- TrackSource["FeSIP"] = "fe-sip";
- TrackSource["FeMethod"] = "fe-method";
- TrackSource["FeAPI"] = "fe-api";
- TrackSource["FeAPIError"] = "fe-api-error";
- TrackSource["FeIMDown"] = "fe-im-down";
- TrackSource["FeIMCmd"] = "fe-im-cmd";
- TrackSource["FeMedia"] = "fe-media";
- TrackSource["FeStatus"] = "fe-status";
- TrackSource["FeEmit"] = "fe-emit";
- })(TrackSource || (TrackSource = {}));
- var SocketEvent;
- (function (SocketEvent) {
- SocketEvent["SetSocketStatus"] = "SetSocketStatus";
- SocketEvent["SocketDownEvent"] = "SocketDownEvent";
- })(SocketEvent || (SocketEvent = {}));
- var ExceptMessage;
- (function (ExceptMessage) {
- ExceptMessage["CommonNetworkErrorMsg"] = "\u5BF9\u4E0D\u8D77\uFF0C\u7F51\u7EDC\u72B6\u51B5\u6682\u65F6\u4E0D\u4F73\uFF0C\u8BF7\u5237\u65B0\u540E\u91CD\u8BD5\u3002";
- ExceptMessage["CustomNetworkErrorMsg"] = "\u5BF9\u4E0D\u8D77\uFF0C\u8FDE\u63A5\u5931\u8D25\uFF0C\u8BF7\u5237\u65B0\u540E\u91CD\u8BD5\u3002\u5982\u679C\u95EE\u9898\u6301\u7EED\u51FA\u73B0\uFF0C\u8BF7\u8054\u7CFB\u6211\u4EEC\u7684\u6280\u672F\u4EBA\u5458\u3002\u611F\u8C22\u60A8\u7684\u7406\u89E3\u548C\u652F\u6301\u3002";
- ExceptMessage["ManualCallAnswerErrorMsg"] = "\u5F53\u524D\u7535\u8BDD\u672A\u63A5\u901A\uFF0C\u901A\u8BDD\u5DF2\u7ED3\u675F\uFF0C\u8BF7\u91CD\u8BD5\u3002";
- ExceptMessage["RobotOrWeChatAnswerErrorMsg"] = "\u5BF9\u4E0D\u8D77\uFF0C\u7531\u4E8E\u7528\u6237\u6302\u673A\u7B49\u539F\u56E0\uFF0C\u5F53\u524D\u7535\u8BDD\u672A\u63A5\u901A\uFF0C\u8BF7\u7B49\u5F85\u4E0B\u4E00\u901A\u7535\u8BDD\u3002";
- ExceptMessage["SipByeErrorMsg"] = "\u8BF7\u7A0D\u7B49\uFF0C\u6B63\u5728\u6302\u65AD\u3002";
- ExceptMessage["CTIRepeatLoginMsg"] = "\u5F53\u524D\u5750\u5E2D\u5DF2\u88AB\u5176\u4ED6\u7EC8\u7AEF\u66FF\u4EE3\u3002";
- })(ExceptMessage || (ExceptMessage = {}));
- const methodExceptMsgMap = {
- checkIn: ExceptMessage.CommonNetworkErrorMsg,
- checkOut: ExceptMessage.CommonNetworkErrorMsg,
- setIdle: ExceptMessage.CustomNetworkErrorMsg,
- setBusy: ExceptMessage.CommonNetworkErrorMsg,
- makeCall: ExceptMessage.CommonNetworkErrorMsg,
- answer: ExceptMessage.CommonNetworkErrorMsg,
- bye: ExceptMessage.CommonNetworkErrorMsg,
- loadAgentGroupData: ExceptMessage.CommonNetworkErrorMsg,
- listen: ExceptMessage.CommonNetworkErrorMsg,
- setActiveService: ExceptMessage.CustomNetworkErrorMsg
- };
- const baseRequireParams = ['agent_id', 'saas_id',
- 'env', 'scene'];
- const monitorRequireParams = ['monitorScene'];
- const allRequiredParams = [...baseRequireParams, ...monitorRequireParams];
- class HsSocket extends EventEmitter {
- constructor(socketOptions) {
- super();
- Object.defineProperty(this, "logger", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "socket", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
-
- Object.defineProperty(this, "socketOptions", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
-
- Object.defineProperty(this, "heartBeatDelay", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
-
- Object.defineProperty(this, "closeHeartBeatDelay", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
-
- Object.defineProperty(this, "heartBeatTimer", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
-
- Object.defineProperty(this, "closeHeartBeatTimer", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
-
-
-
- Object.defineProperty(this, "imRetryCount", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
-
- Object.defineProperty(this, "sessionId", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
-
- window.addEventListener('onunload', this.closeSocket);
- this.logger = new Logger(socketOptions.loggerLevel, 'HsSocket');
- this.socket = undefined;
- this.heartBeatTimer = null;
- this.closeHeartBeatTimer = null;
-
- this.sessionId = '';
- this.socketOptions = socketOptions;
- this.heartBeatDelay = socketOptions.imHeartTime * 1000 || 3000;
- this.closeHeartBeatDelay = socketOptions.imHeartTime * 1000 || 3000;
- this.imRetryCount = socketOptions.imRetryCount || 10;
- }
-
- initSocket() {
-
- this.closeSocket();
-
- this.emit(SocketEvent.SetSocketStatus, {
- status: SocketStatus.Connecting
- });
-
- this.socket = io(this.socketOptions.imWsServer, {
- transports: ['websocket'],
- reconnectionAttempts: this.imRetryCount,
- reconnectionDelay: this.heartBeatDelay,
- reconnectionDelayMax: this.heartBeatDelay + 1000,
- timeout: this.heartBeatDelay,
- reconnection: true
- });
-
- this.socket.on('error', error => {
- this.logger.error(`socket_error | ${JSON.stringify(error)}`);
- });
-
- this.socket.on('connect_error', error => {
- const errorData = `socket_connect_error | ${JSON.stringify(error)}`;
- this.logger.warn(errorData);
- });
- this.socket.on('reconnecting', res => {
- this.logger.error(`socket_warn | socket_reconnecting | ${res}`);
- this.emit(SocketEvent.SetSocketStatus, {
- status: SocketStatus.ReTry
- });
- });
- this.socket.on('reconnect', res => {
- this.logger.error(`socket_warn | socket_reconnect | ${res}`);
- this.emit(SocketEvent.SetSocketStatus, {
- status: SocketStatus.Ready
- });
- });
- this.socket.on('reconnect_failed', error => {
- this.logger.error(`socket_warn | socket_reconnect_failed | ${error}`);
- this.emit(SocketEvent.SetSocketStatus, {
- status: SocketStatus.Terminated,
- code: HskTerminatedCode.SocketOnReconnectFailed,
- error: `${error}`
- });
- });
-
- this.socket.on('connect', () => {
- this.emit(SocketEvent.SetSocketStatus, {
- status: SocketStatus.Connected
- });
- this.socketLogin();
- });
-
- this.socket.on('disconnect', reason => {
- const errorMessage = `socket_disconnect | ${reason}`;
- this.logger.warn(errorMessage);
- });
-
- this.socket.on('common_down_data', e => {
-
- if (e && JSON.parse(e) && JSON.parse(e).data) {
- this.emit(SocketEvent.SocketDownEvent, {
- eventData: JSON.parse(JSON.parse(e).data)
- });
- }
- });
-
- this.socket.on('common_down_cmd', e => {
- const {
- clientSessionId
- } = JSON.parse(e);
-
- if (clientSessionId === this.sessionId) {
- this.logger.error(`socket status | ${SocketStatus.Terminated} | 坐席在其他页面重新初始化,本页面被踢出`);
- this.emit(SocketEvent.SetSocketStatus, {
- status: SocketStatus.Terminated,
- code: HskTerminatedCode.SocketRepeatLogin,
- error: '您已在其他页面签入,当前页面连接已断开'
- });
- }
- });
- }
-
- socketLogin() {
- const data = {
-
-
- userId: this.socketOptions.agent_id
- };
- this.socket && this.socket.emit('login', data, sessionId => {
-
- this.emit(SocketEvent.SetSocketStatus, {
- status: SocketStatus.Ready
- });
- setBaseOption(BaseOption.TrackParams, {
- socket_session_id: sessionId
- });
- this.sessionId = sessionId;
- this.startHeartbeat();
- });
- }
-
- closeSocket() {
- if (this.socket) {
- this.socket.io.opts.reconnection = false;
- this.socket.close();
-
- this.socket.removeAllListeners();
- }
- this.socket = undefined;
- this.sessionId = '';
- if (this.heartBeatTimer) {
- window.clearTimeout(this.heartBeatTimer);
- this.heartBeatTimer = null;
- }
- if (this.closeHeartBeatTimer) {
- window.clearTimeout(this.closeHeartBeatTimer);
- this.closeHeartBeatTimer = null;
- }
- }
-
- startHeartbeat() {
- if (this.heartBeatTimer) {
- window.clearTimeout(this.heartBeatTimer);
- this.heartBeatTimer = null;
- }
- if (this.closeHeartBeatTimer) {
- window.clearTimeout(this.closeHeartBeatTimer);
- this.closeHeartBeatTimer = null;
- }
- this.socket && this.heartbeatEvent();
- }
-
- heartbeatEvent() {
- this.heartBeatTimer = setTimeout(() => {
- this.socket && this.sendHeartbeat();
-
- this.closeHeartBeatTimer = setTimeout(() => {
- this.logger.warn('socket_heart_beat | 心跳超时,即将重新连接');
- this.initSocket();
- }, this.closeHeartBeatDelay);
- }, this.heartBeatDelay);
- }
-
- sendHeartbeat() {
- this.socket && this.socket.emit('heartbeat', JSON.stringify(Object.assign({}, this.socketOptions)), () => {
- this.startHeartbeat();
- });
- }
- }
- const apiLogger = new Logger(window.ctiLoggerLevel || getBaseOption(BaseOption.LoggerLevel), 'HsApi');
- const random16Hex = () => (0x10000 | Math.random() * 0x10000).toString(16).substr(1);
- const random64Hex = () => random16Hex() + random16Hex() + random16Hex() + random16Hex();
- function JPOST({
- baseUrl,
- url,
- data
- }) {
- return __awaiter(this, void 0, void 0, function* () {
- const id = random64Hex();
- const response = yield fetch(baseUrl + url, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'X-B3-TraceId': id,
- 'X-B3-SpanId': id
- },
- body: JSON.stringify(data)
- });
- if (!response.ok) {
- apiLogger.error(`api response | ${url} | Request failed with status ${response.status}`);
- }
- return response.json();
- });
- }
- const hsTrackJPOST = ({
- baseUrl,
- url = '',
- data
- }) => {
-
- return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
- try {
- const res = yield JPOST({
- baseUrl,
- url,
- data
- });
- const {
- code,
- msg
- } = res;
- console.log(msg);
- if (code === 0) {
- apiLogger.log(`api response | ${url} | ${JSON.stringify(res)}`);
- } else {
- apiLogger.error(`api response | ${url} | ${JSON.stringify(res)}`);
- }
- resolve(res);
- } catch (e) {
- apiLogger.error(`api response | ${url} | ${JSON.stringify(e)}`);
- reject(e);
- }
- }));
- };
- const baseUrl = 'http://pbx.fuxicarbon.com:8090';
- const getInitConf = data => {
- return hsTrackJPOST({
- baseUrl,
- url: '/open/agent/get-init-config',
- data
- });
- };
- const agentCheckIn = data => {
- return hsTrackJPOST({
- baseUrl,
- url: '/open/agent/check-in',
- data
- });
- };
- const agentCheckOut = data => {
- return hsTrackJPOST({
- baseUrl,
- url: '/open/agent/check-out',
- data
- });
- };
- const agentSetIdle = data => {
- return hsTrackJPOST({
- baseUrl,
- url: '/open/agent/idle',
- data
- });
- };
- const agentSetBusy = data => {
- return hsTrackJPOST({
- baseUrl,
- url: '/open/agent/busy',
- data
- });
- };
- const getAgentStatus = data => {
- return hsTrackJPOST({
- baseUrl,
- url: '/open/agent/agent-state',
- data
- });
- };
- const manualCall = data => {
- return hsTrackJPOST({
- baseUrl,
- url: '/open/agent/manual-call',
- data
- });
- };
- const manualHang = data => {
- return hsTrackJPOST({
- baseUrl,
- url: '/open/agent/manual-hang',
- data
- });
- };
- const listen = data => {
- return hsTrackJPOST({
- baseUrl,
- url: '/open/agent/listen',
- data
- });
- };
- const loadAgentGroupData = data => {
- return hsTrackJPOST({
- baseUrl,
- url: '/open/monitor/load-agent-group-data',
- data
- });
- };
- const setActiveServiceTask = data => {
- return hsTrackJPOST({
- baseUrl,
- url: '/open/human-service/member-active',
- data
- });
- };
- const getCtiFlowId = data => {
- return hsTrackJPOST({
- baseUrl,
- url: '/open/num/generate',
- data
- });
- };
- function getServerErrorType(code) {
- if (code >= 300001 && code <= 399999) return CTIErrorType.ServerTerminated;else return CTIErrorType.ServerError;
- }
- function getUserMedia() {
-
- return function (_target, _methodName, descriptor) {
- const originalMethod = descriptor.value;
- descriptor.value = function (...args) {
- if (navigator && navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
- navigator.mediaDevices.getUserMedia({
- audio: true,
- video: false
- }).then(() => {
- this.logger.debug('media | getUserMedia | 获取浏览器媒体权限成功');
- return originalMethod.apply(this, args);
- }).catch(error => {
- this.logger.error(`media | getUserMedia | ${error}`);
- this.eventEmitAndTrack(CTIEvent.OnCtiError, {
- type: CTIErrorType.SdkTerminated,
- code: HskTerminatedCode.GetUserMedia,
- msg: error.name === 'NotAllowedError' ? '用户拒绝了获取麦克风权限!' : '获取麦克风权限失败',
- method: 'getUserMedia'
- }, {
- source: TrackSource.FeMedia,
- event_name: 'get_user_media_error',
- error: error.name
- });
- });
- } else {
- this.logger.error('media | getUserMedia | 浏览器版本过低,不支持获取媒体权限');
- this.eventEmitAndTrack(CTIEvent.OnCtiError, {
- type: CTIErrorType.SdkTerminated,
- code: HskTerminatedCode.GetUserMedia,
- msg: '浏览器版本过低,不支持获取媒体权限',
- method: 'getUserMedia'
- }, {
- source: TrackSource.FeMedia,
- event_name: 'get_user_media_not_support'
- });
- }
- };
- return descriptor;
- };
- }
- function checkCTIStatus(msg) {
-
- return function (_target, methodName, descriptor) {
- const originalMethod = descriptor.value;
- descriptor.value = function (...args) {
-
- this.logger.log(`sdk method | ${methodName} | ${msg}`);
-
- if (this.getCTIStatus !== CTIStatus.Ready) {
- const errorData = {
- type: CTIErrorType.SdkTerminated,
- code: HskTerminatedCode.CTITerminated,
- msg: methodExceptMsgMap[methodName],
- method: methodName,
- terminated_source: this._terminatedStatusList
- };
- this.eventEmitAndTrack(CTIEvent.OnCtiError, errorData);
- return Promise.reject(errorData);
- }
- return originalMethod.apply(this, args);
- };
- return descriptor;
- };
- }
- function handleApiRes() {
-
- return function (_target, methodName, descriptor) {
- const originalMethod = descriptor.value;
- descriptor.value = function (...args) {
- return __awaiter(this, void 0, void 0, function* () {
- try {
- const res = yield originalMethod.apply(this, args);
- const {
- code,
- msg
- } = res;
- if (code !== 0) {
- const serverErrorType = getServerErrorType(code);
- const errorData = {
- type: serverErrorType,
- code,
- msg: msg,
- method: methodName
- };
- this.eventEmitAndTrack(CTIEvent.OnCtiError, errorData);
- if (serverErrorType === CTIErrorType.ServerTerminated) {
- this.setCTIStatus(CTIStatus.Terminated);
- }
- return Promise.reject(errorData);
- } else {
- return Promise.resolve(res);
- }
- } catch (error) {
- const errorData = {
- type: 'fetch_error',
- code: SdkErrorCode.FetchError,
- msg: JSON.stringify(error),
- method: methodName
- };
- this.eventEmitAndTrack(CTIEvent.OnCtiError, errorData);
- return Promise.reject(errorData);
- }
- });
- };
- return descriptor;
- };
- }
- function validateParams() {
-
- return function (_target, _methodName, descriptor) {
- const originalMethod = descriptor.value;
- descriptor.value = function (...args) {
-
- const currentParams = args[0];
- let requireList = [];
- if (currentParams.scene === Scene.Monitor) {
- requireList = allRequiredParams;
- } else {
- requireList = baseRequireParams;
- }
- requireList.forEach(param => {
- if (!currentParams[param]) {
- throw `参数[${param}]为必填参数`;
- }
- });
- return originalMethod.apply(this, args);
- };
- return descriptor;
- };
- }
- function generateUniqueId() {
- return 'id-' + Date.now() + '-' + Math.floor(Math.random() * 10000);
- }
- const audioList = {
- _ringAudio: 'http://static.fuxicarbon.com/hs-cti/ring.wav',
- _waitAudio: 'http://static.fuxicarbon.com/hs-cti/manual.wav',
- _byeAudio: 'http://static.fuxicarbon.com/hs-cti/bye.wav'
- };
- class HsCTI extends EventEmitter {
- constructor(hsCTIInitOptions) {
- const {
- saas_id,
- agent_id,
- scene,
- env,
- loggerLevel
- } = hsCTIInitOptions;
- super();
- Object.defineProperty(this, "logger", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "loggerLevel", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "scene", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "agent_id", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "saas_id", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
-
- Object.defineProperty(this, "_initOptions", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
-
- Object.defineProperty(this, "_socket", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
-
- Object.defineProperty(this, "_sipUserAgent", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "_callId", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "_ctiFlowIdList", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
-
- Object.defineProperty(this, "_baseParams", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
-
- Object.defineProperty(this, "_waitAudio", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
-
- Object.defineProperty(this, "_ringAudio", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
-
- Object.defineProperty(this, "_byeAudio", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
-
- Object.defineProperty(this, "_remoteAudio", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
-
- Object.defineProperty(this, "_ctiStatus", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "_ctiStatusList", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
-
- Object.defineProperty(this, "_sipStatus", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "_sipStatusList", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
-
- Object.defineProperty(this, "_socketStatus", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "_socketStatusList", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "_callStatus", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- Object.defineProperty(this, "_terminatedStatusList", {
- enumerable: true,
- configurable: true,
- writable: true,
- value: void 0
- });
- this.loggerLevel = window.ctiLoggerLevel || loggerLevel || LoggerLevels.log;
- this.logger = new Logger(this.loggerLevel, 'HsCTI');
- this._waitAudio = new Audio();
- this._ringAudio = new Audio();
- this._byeAudio = new Audio();
- this._remoteAudio = new Audio();
- this.saas_id = saas_id;
- this.agent_id = agent_id;
- this.scene = scene;
- this._callId = '';
- setBaseOption(BaseOption.ENV, env);
- setBaseOption(BaseOption.LoggerLevel, this.loggerLevel);
- this._baseParams = {
- agent_id,
- saas_id,
- scene
- };
- const baseTrackParams = {
- agent_id: agent_id,
- vcc_id: saas_id,
- scene
- };
- if (scene === Scene.Monitor) {
- const {
- monitorScene
- } = hsCTIInitOptions;
- this._baseParams = Object.assign(Object.assign({}, this._baseParams), {
- monitorScene
- });
- setBaseOption(BaseOption.TrackParams, Object.assign(Object.assign({}, baseTrackParams), {
- monitor_scene: monitorScene
- }), true);
- } else {
- setBaseOption(BaseOption.TrackParams, baseTrackParams, true);
- }
- this.initInstanceOptions();
- this.setCTIStatus(CTIStatus.Initial);
-
- this._callStatus = CallStatus.Stopped;
- this._terminatedStatusList = [];
- }
- get getCTIStatus() {
- return this._ctiStatus;
- }
- get getSocketStatus() {
- return this._socketStatus;
- }
- get getSIPStatus() {
- return this._sipStatus;
- }
- static getInstance(hsCTIInitOptions) {
- if (!HsCTI.instance) {
- HsCTI.instance = new HsCTI(hsCTIInitOptions);
- }
- setBaseOption(BaseOption.TrackParams, {
- clientId: getClientId()
- });
- return HsCTI.instance;
- }
-
- initInstanceOptions() {
- this._ctiFlowIdList = [];
- this._ctiStatusList = [];
- this._sipStatusList = [];
- this._socketStatusList = [];
- HsCTI.instance = undefined;
- this._initOptions = undefined;
- resetBaseOption();
- }
-
- clearSocketAndSip() {
- var _a, _b, _c;
- (_a = this._socket) === null || _a === void 0 ? void 0 : _a.closeSocket();
- (_b = this._sipUserAgent) === null || _b === void 0 ? void 0 : _b.unregister();
- (_c = this._sipUserAgent) === null || _c === void 0 ? void 0 : _c.disconnect();
- this._sipUserAgent = undefined;
- }
-
- setAudioSrc(audioName, loop) {
- this.logger.debug(`media | 设置等待音 src: ${audioList[audioName]}`);
- this[audioName].src = audioList[audioName];
- this[audioName].currentTime = 0;
- this[audioName].autoplay = false;
- this[audioName].loop = loop;
- }
- playAudio(audioName) {
- this.logger.debug(`media | 播放音频:${audioName}`);
- this[audioName].play();
- }
- stopLocalAudio() {
- switch (this.scene) {
- case Scene.Robot:
- case Scene.Monitor:
- this.stopAudio(AudioName.RingAudio, true);
- break;
- case Scene.Manual:
- this.stopAudio(AudioName.WaitAudio, true);
- break;
- }
- }
- stopAudio(audioName, loop) {
- this.logger.debug(`media | 停止音频播放:${audioName}`);
- this[audioName].src = '';
- setTimeout(() => {
- this.setAudioSrc(audioName, loop);
- }, 1000);
- }
- init() {
-
- const [lastStatus] = this._ctiStatusList.slice(-1);
- if (lastStatus !== CTIStatus.Initial) return;
- this.setAudioSrc(AudioName.ByeAudio, false);
- this.setAudioSrc(AudioName.RingAudio, true);
- this.setAudioSrc(AudioName.WaitAudio, true);
-
-
-
-
-
-
-
-
-
- this.getInitConfig();
- }
- getInitConfig() {
- return __awaiter(this, void 0, void 0, function* () {
- const res = yield getInitConf(this._baseParams);
- const {
- code,
- data,
- msg
- } = res;
- let initOptions = data;
-
- initOptions = Object.assign(Object.assign({}, initOptions), {
- imHeartTime: 3,
-
- imRetryCount: 3,
-
- fsHeartTime: 60,
-
- fsRetryCount: 3,
-
- fsRetryTime: 60,
-
- fsRegisterExpireTime: 84000,
-
- ctiSessionId: generateUniqueId(),
-
- imWsServer: 'ws://pbx.fuxicarbon.com:8091/ws/cs-im',
-
- imWsPath: 'ws/cs-im'
- });
- if (code === 0 && initOptions) {
- setBaseOption(BaseOption.TrackParams, {
- sip_server: initOptions.sipServer,
- cti_session_id: initOptions.ctiSessionId
- });
- this._initOptions = initOptions;
- this.initSocket(initOptions);
- this.initSip(initOptions);
- } else {
- this.eventEmitAndTrack(CTIEvent.OnCtiError, {
- type: CTIErrorType.ServerTerminated,
- code: HskTerminatedCode.GetInitConfig,
-
- msg: code === 0 && !initOptions ? '未查到坐席' : msg,
- method: 'getInitConfig',
- res_code: code
- });
- }
- });
- }
- initSocket(initOptions) {
- this.setSocketStatus({
- status: SocketStatus.Initial
- });
- this._socket = new HsSocket({
- agent_id: this.agent_id,
- saas_id: this.saas_id,
-
- imWsServer: initOptions.imWsServer,
- imWsPath: initOptions.imWsPath,
- imHeartTime: initOptions.imHeartTime,
- imRetryCount: initOptions.imRetryCount,
- ctiSessionId: initOptions.ctiSessionId,
- loggerLevel: this.loggerLevel
- });
- this._socket.on(SocketEvent.SocketDownEvent, ({
- eventData
- }) => {
- const {
- eventName,
- ext
- } = eventData;
- this.logger.log(`socket server down | ${eventName} | ${JSON.stringify(ext)}`);
- this.handleSocketDownEvent({
- eventName,
- ext
- });
- });
- this._socket.on(SocketEvent.SetSocketStatus, res => {
-
- this.setSocketStatus(res);
- });
- this._socket.initSocket();
- }
- handleSocketDownEvent({
- eventName,
- ext
- }) {
- const ctiFlowId = this._baseParams.ctiFlowId;
- const extCtiFlowId = ext.ctiFlowId;
- if ([Scene.Manual, Scene.Monitor].includes(this.scene) && ctiFlowId && extCtiFlowId && ctiFlowId !== extCtiFlowId) {
- this.logger.error(`cti_flow_id | 不一致! fe: ${ctiFlowId}, server: ${extCtiFlowId}, eventName: ${eventName}`);
- return;
- }
- this.serverEventEmit({
- eventName,
- ext
- });
- }
-
- serverEventEmit({
- eventName,
- ext
- }) {
- const NO_EMIT_EVENT_LIST = [CTIEvent.OnRingStart, CTIEvent.OnDetectedTone, CTIEvent.OnRingEnd];
- switch (eventName) {
- case CTIEvent.OnRingStart:
- this.stopLocalAudio();
- break;
- case CTIEvent.OnDetectedTone:
- this.stopLocalAudio();
- break;
- case CTIEvent.OnAgentWorkReport:
- break;
- case CTIEvent.OnCallEnd:
-
- this._callStatus = CallStatus.Stopped;
- setBaseOption(BaseOption.TrackParams, {
- call_id: ''
- });
-
- break;
- case CTIEvent.OnRingEnd:
-
- break;
-
- }
- if (!NO_EMIT_EVENT_LIST.includes(eventName)) {
- this.eventEmitAndTrack(eventName, ext);
- }
- }
- initSip(initOptions) {
- this.setSipStatus({
- status: SIPStatus.Initial
- });
- const server = initOptions.wss_server;
- const simpleUserPlusOptions = {
- aor: initOptions.sip_server,
- reconnectionAttempts: initOptions.fsRetryCount,
- reconnectionDelay: initOptions.fsRetryTime,
- optionsPingInterval: initOptions.fsHeartTime,
- media: {
- remote: {
- audio: this._remoteAudio
- }
- },
- userAgentOptions: {
- gracefulShutdown: true,
- authorizationPassword: initOptions.phone_pwd,
- sessionDescriptionHandlerFactoryOptions: {
- constraints: {
- audio: {
- echoCancellation: true,
- noiseSuppression: true,
- autoGainControl: true
- },
- video: false
- },
- peerConnectionConfiguration: {
-
- iceServers: [{
- urls: initOptions.ice_server
- }]
- }
- }
- }
- };
- simpleUserPlusOptions.delegate = this.sipDelegate();
- this._sipUserAgent = new SimpleUserPlus(server, simpleUserPlusOptions);
- this._sipUserAgent.connect().catch(error => {
- const err = `SIP UserAgent 启动失败:${JSON.stringify(error)}`;
- this.logger.error(err);
- this.setSipStatus({
- status: SIPStatus.Terminated,
- code: HskTerminatedCode.SIPInitUserAgent,
- error: err,
- method: 'initSIPJS'
- });
- });
- }
- sipDelegate() {
- return {
- onServerConnect: () => {
- this._sipUserAgent.register();
- },
- onServerDisconnect: () => {
-
- this.setSipStatus({
- status: SIPStatus.Terminated
- });
- },
- onReconnectStart: () => {
-
- this.setSipStatus({
- status: SIPStatus.ReTry
- });
- },
- onReconnectFailed: () => {
-
- this.setSipStatus({
- status: SIPStatus.Terminated,
- code: HskTerminatedCode.SIPOnDisconnect,
- error: `超过重连次数,终止重连`,
- method: 'onReconnectFailed'
- });
- this.setSipStatus({
- status: SIPStatus.Terminated
- });
- },
- onRegistered: () => {
- this.setSipStatus({
- status: SIPStatus.Ready
- });
- },
- onUserAgentStateChange: state => {
- switch (state) {
- case UserAgentState.Started:
- this.setSipStatus({
- status: SIPStatus.Started
- });
- break;
- case UserAgentState.Stopped:
- this.setSipStatus({
- status: SIPStatus.Terminated,
- code: this._sipStatusList.includes(SIPStatus.Started) ? HskTerminatedCode.SIPUserAgentStateStopped : HskTerminatedCode.SIPInitUserAgent,
- error: 'SIP UserAgentState 状态停止',
- method: 'onUserAgentStateChange'
- });
- break;
- }
- },
- onInvite: invitation => {
-
- const callId = invitation.request.getHeader('P-LIBRA-CallId') || invitation.request.getHeader('P-LIBRA-Callid') || '';
-
-
-
-
-
-
-
-
-
- this._callId = callId;
- setBaseOption(BaseOption.TrackParams, {
- call_id: callId
- });
- this.sessionStateChangeAndTrack(invitation.state);
- if ([Scene.Robot, Scene.Monitor].includes(this.scene)) {
- this.playAudio(AudioName.RingAudio);
- }
- if ([Scene.Manual].includes(this.scene)) {
- this.answer();
- }
- invitation.delegate = {
- onCancel: cancel => {
- const error = `sip_invitation_on_cancel | ${JSON.stringify(cancel)}`;
- this.logger.error(error);
- this.eventEmitAndTrack(CTIEvent.OnCtiError, {
- type: CTIErrorType.SdkError,
- code: SdkErrorCode.InvitationCancel,
- msg: '当前通话已结束',
- method: 'sipDelegate'
- }, error);
- }
- };
- invitation.stateChange.addListener(state => {
- this.sessionStateChangeAndTrack(state);
- switch (state) {
- case SessionState.Initial:
- case SessionState.Establishing:
- break;
- case SessionState.Established:
- if ([Scene.Robot, Scene.Monitor].includes(this.scene)) {
- this.stopLocalAudio();
- }
- break;
- case SessionState.Terminating:
- break;
- case SessionState.Terminated:
- this.playAudio(AudioName.ByeAudio);
- setTimeout(() => {
- this.stopAudio(AudioName.ByeAudio, false);
- }, 1000);
- this.stopLocalAudio();
-
- setBaseOption(BaseOption.TrackParams, {
- call_id: ''
- });
- if (this.scene == Scene.Manual) {
- this.scene = Scene.Robot;
- this._baseParams.scene = Scene.Robot;
- }
- break;
- }
- });
- }
- };
- }
- sessionStateChangeAndTrack(status) {
- this.eventEmitAndTrack(CTIEvent.OnSessionStatusChange, {
- status
- });
- const trackName = `sip_session_state_${upperCamelToLowerSnake(status)}`;
- this.logger.log(trackName);
- }
-
- setCTIStatus(ctiStatus) {
- if (ctiStatus === this.getCTIStatus) return;
- this._ctiStatus = ctiStatus;
- this._ctiStatusList.push(ctiStatus);
- const logInfo = `cti status | ${ctiStatus} | ${this._ctiStatusList}`;
- if (ctiStatus === CTIStatus.Terminated) {
- this.setSocketStatus({
- status: SocketStatus.Terminated
- });
- this.setSipStatus({
- status: SIPStatus.Terminated
- });
- this.stopLocalAudio();
- this.logger.warn(logInfo);
- } else {
- this.logger.debug(logInfo);
- }
- if (ctiStatus === CTIStatus.Ready) {
- this.setSocketStatus({
- status: SocketStatus.Ready
- });
- this.setSipStatus({
- status: SIPStatus.Ready
- });
- this._terminatedStatusList = [];
- if (!this._ctiStatusList.includes(CTIStatus.ReTry)) {
- this.checkIn();
- }
- }
- }
-
- setSocketStatus({
- status,
- code,
- error
- }) {
- if (status === this.getSocketStatus) return;
- this._socketStatus = status;
- this._socketStatusList.push(status);
- const logInfo = `socket status | ${status} | ${this._socketStatusList}`;
- status === SocketStatus.Terminated ? this.logger.warn(logInfo) : this.logger.debug(logInfo);
- this.socketOrSipStatusChange(status, this.getSIPStatus);
- if (error) {
- this._terminatedStatusList.push(code);
- this.eventEmitAndTrack(CTIEvent.OnCtiError, {
- type: CTIErrorType.SdkTerminated,
- code,
- msg: code === HskTerminatedCode.SocketRepeatLogin ? ExceptMessage.CTIRepeatLoginMsg : ExceptMessage.CommonNetworkErrorMsg,
- method: 'setSocketStatus'
- }, {
- error_msg: error,
- socket_status_list: this._socketStatusList,
- sip_status_list: this._sipStatusList,
- cti_status_list: this._ctiStatusList
- });
- this.clearSocketAndSip();
- }
- }
-
- setSipStatus({
- status,
- code,
- error,
- method
- }) {
- if (status === this.getSIPStatus) return;
- this._sipStatus = status;
- this._sipStatusList.push(status);
- const logInfo = `sip status | ${status} | ${this._sipStatusList}`;
- status === SIPStatus.Terminated ? this.logger.warn(logInfo) : this.logger.debug(logInfo);
- this.socketOrSipStatusChange(this.getSocketStatus, status);
- if (error) {
-
- this._terminatedStatusList.push(code);
- this.eventEmitAndTrack(CTIEvent.OnCtiError, {
- type: CTIErrorType.SdkTerminated,
- code,
- msg: ExceptMessage.CommonNetworkErrorMsg,
- method: method || 'setSipStatus'
- }, {
- error_msg: error,
- socket_status_list: this._socketStatusList,
- sip_status_list: this._sipStatusList,
- cti_status_list: this._ctiStatusList
- });
- this.clearSocketAndSip();
- }
- }
-
- socketOrSipStatusChange(socketStatus, sipStatus) {
- if (socketStatus === SocketStatus.Ready && sipStatus === SIPStatus.Ready) {
- this.setCTIStatus(CTIStatus.Ready);
- }
-
-
-
- if (socketStatus === SocketStatus.ReTry || sipStatus === SIPStatus.ReTry) {
- this.setCTIStatus(CTIStatus.ReTry);
- }
- if (socketStatus === SocketStatus.Terminated || sipStatus === SIPStatus.Terminated) {
- this.setCTIStatus(CTIStatus.Terminated);
- }
- }
-
- eventEmitAndTrack(eventName, ext, error) {
- this.logger.debug(`sdk emit | ${eventName} | ${JSON.stringify(ext)}`);
-
- if (eventName === CTIEvent.OnCtiError) {
- this._callStatus = CallStatus.Stopped;
- }
- try {
- this.emit(eventName, ext);
- console.log(error);
- } catch (error) {
- this.logger.error(`业务监听 ${eventName} 事件,处理回调时报错: ${error}`);
- }
- }
-
- checkIn() {
- return __awaiter(this, void 0, void 0, function* () {
- const res = yield agentCheckIn(this._baseParams);
- if (res.code === 0) {
- this.eventEmitAndTrack(CTIEvent.OnInitalSuccess, {
- saas_id: this.saas_id,
- agent_id: this.agent_id,
- scene: this.scene,
- phoneNum: this._initOptions.phone_num,
- sipServer: this._initOptions.sip_server
- });
- }
- return res;
- });
- }
-
- checkOut() {
- return __awaiter(this, void 0, void 0, function* () {
- return yield agentCheckOut(this._baseParams);
- });
- }
-
- getCtiFlowId() {
- return __awaiter(this, void 0, void 0, function* () {
- const res = yield getCtiFlowId(this._baseParams);
- const {
- code,
- data
- } = res;
- if (code === 0) {
- this._baseParams.ctiFlowId = data;
- this._ctiFlowIdList.push(data);
- setBaseOption(BaseOption.TrackParams, {
- cti_flow_id: data,
- cti_flow_id_list: JSON.stringify(this._ctiFlowIdList)
- });
- }
- return res;
- });
- }
-
- setIdle() {
- return __awaiter(this, void 0, void 0, function* () {
- this.scene = Scene.Robot;
- this._baseParams.scene = Scene.Robot;
- return yield agentSetIdle(this._baseParams);
- });
- }
-
- setBusy() {
- return __awaiter(this, void 0, void 0, function* () {
- return yield agentSetBusy(this._baseParams);
- });
- }
- makeCall(params) {
- return __awaiter(this, void 0, void 0, function* () {
- this.scene = Scene.Manual;
- this._baseParams.scene = Scene.Manual;
-
- if (this._callStatus === CallStatus.Started) {
- return;
- }
- this._callStatus = CallStatus.Started;
- yield this.getCtiFlowId();
- this.playAudio(AudioName.WaitAudio);
- return yield this.serverCall(params);
- });
- }
- serverCall({
- called,
- ext
- }) {
- return __awaiter(this, void 0, void 0, function* () {
- const params = Object.assign(Object.assign(Object.assign({}, this._baseParams), {
- called,
- caller: this.agent_id
- }), ext);
- const res = yield manualCall(params);
- const {
- code,
- data
- } = res;
- if (code === 0) {
- if (this._callId === '' && data) {
- this._callId = data;
- setBaseOption(BaseOption.TrackParams, {
- call_id: data
- });
- }
- } else {
-
- this._callStatus = CallStatus.Stopped;
- this.stopLocalAudio();
- }
- return res;
- });
- }
-
- answer() {
- return new Promise((resolve, reject) => {
- var _a;
- (_a = this._sipUserAgent) === null || _a === void 0 ? void 0 : _a.answer({
- sessionDescriptionHandlerOptions: {
- constraints: {
- audio: true,
- video: false
- }
- }
- }).then(() => {
- resolve({
- code: 0,
- data: 'answer',
- msg: 'SIP 接起电话成功'
- });
- this.logger.debug('sip_accept_success');
- }).catch(err => {
- const errorData = {
- type: CTIErrorType.SdkError,
- code: SdkErrorCode.Answer,
- msg: this.scene === Scene.Manual ? ExceptMessage.ManualCallAnswerErrorMsg : ExceptMessage.RobotOrWeChatAnswerErrorMsg,
- method: 'answer'
- };
- reject(errorData);
- this.eventEmitAndTrack(CTIEvent.OnCtiError, errorData, `${err}`);
- this.logger.error(`${CTIEvent.OnCtiError} | ${err}`);
- });
- });
- }
-
- bye() {
- return new Promise((resolve, reject) => {
- var _a;
- (_a = this._sipUserAgent) === null || _a === void 0 ? void 0 : _a.hangup().then(() => {
- resolve({
- code: 0,
- data: 'bye',
- msg: 'SIP 挂断电话成功'
- });
- this.logger.debug('sip_bye_success');
- }).catch(err => {
- const errorData = {
- type: CTIErrorType.SdkError,
- code: SdkErrorCode.Bye,
- msg: ExceptMessage.SipByeErrorMsg,
- method: 'bye'
- };
- reject(errorData);
- if (err.message !== 'Session does not exist.') {
- this.eventEmitAndTrack(CTIEvent.OnCtiError, errorData, `${err}`);
- }
- this.logger.error(`${CTIEvent.OnCtiError} | ${err}`);
- });
- });
- }
-
- serverBye() {
- return __awaiter(this, void 0, void 0, function* () {
- try {
- this.bye();
-
-
-
-
- const res = yield this.turnHang();
- return Promise.resolve(res);
- } catch (error) {
- return Promise.reject(error);
- }
- });
- }
-
- turnHang() {
- return __awaiter(this, void 0, void 0, function* () {
- const res = yield manualHang(Object.assign(Object.assign({}, this._baseParams), {
- call_id: this._callId
- }));
- this._callId = '';
- return res;
- });
- }
-
- getAgentStatus() {
- return __awaiter(this, void 0, void 0, function* () {
- return yield getAgentStatus(this._baseParams);
- });
- }
-
- loadAgentGroupData(monitorIds) {
- return __awaiter(this, void 0, void 0, function* () {
- return yield loadAgentGroupData(Object.assign(Object.assign({}, this._baseParams), {
- monitorIds
- }));
- });
- }
-
- listen(monitoredAgNo) {
- return __awaiter(this, void 0, void 0, function* () {
- const flowIdRes = yield this.getCtiFlowId();
- if (flowIdRes && flowIdRes.code !== 0) {
- return flowIdRes;
- }
- return yield listen(Object.assign(Object.assign({}, this._baseParams), {
- agent_id: monitoredAgNo,
- leaderAgentId: this.agent_id
- }));
- });
- }
-
- setActiveService(serviceId) {
- return __awaiter(this, void 0, void 0, function* () {
- return yield setActiveServiceTask(Object.assign(Object.assign({}, this._baseParams), {
- serviceId
- }));
- });
- }
-
- unInit() {
- return __awaiter(this, void 0, void 0, function* () {
- yield this.checkOut();
- this.setCTIStatus(CTIStatus.Terminated);
- this.initInstanceOptions();
- this.clearSocketAndSip();
- this._callId = '';
- });
- }
- }
- __decorate([getUserMedia()], HsCTI.prototype, "init", null);
- __decorate([checkCTIStatus('签入'), handleApiRes()], HsCTI.prototype, "checkIn", null);
- __decorate([checkCTIStatus('签出'), handleApiRes()], HsCTI.prototype, "checkOut", null);
- __decorate([handleApiRes()], HsCTI.prototype, "getCtiFlowId", null);
- __decorate([checkCTIStatus('置闲'), handleApiRes()], HsCTI.prototype, "setIdle", null);
- __decorate([checkCTIStatus('置忙'), handleApiRes()], HsCTI.prototype, "setBusy", null);
- __decorate([checkCTIStatus('人工外呼')], HsCTI.prototype, "makeCall", null);
- __decorate([handleApiRes()], HsCTI.prototype, "serverCall", null);
- __decorate([checkCTIStatus('接起')], HsCTI.prototype, "answer", null);
- __decorate([checkCTIStatus('挂断')], HsCTI.prototype, "bye", null);
- __decorate([handleApiRes()], HsCTI.prototype, "turnHang", null);
- __decorate([handleApiRes()], HsCTI.prototype, "getAgentStatus", null);
- __decorate([checkCTIStatus('获取监听组成员'), handleApiRes()], HsCTI.prototype, "loadAgentGroupData", null);
- __decorate([checkCTIStatus('坐席监听'), handleApiRes()], HsCTI.prototype, "listen", null);
- __decorate([checkCTIStatus('签入人工组'), handleApiRes()], HsCTI.prototype, "setActiveService", null);
- __decorate([validateParams()], HsCTI, "getInstance", null);
- const getInstance = HsCTIInitOptions => HsCTI.getInstance(HsCTIInitOptions);
- export { CTIErrorType, CTIEvent, CTIStatus, CallStatus, HskTerminatedCode, Logger, LoggerLevels, MonitorScene, SIPStatus, Scene, SdkErrorCode, SessionStatus, SocketStatus, getInstance };
|