12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235 |
- 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: getBaseOption(BaseOption.ENV) == 'production' ? 'https://pbx.fuxicarbon.com/fs_api/' : baseUrl,
- url,
- data
- });
- console.log(getBaseOption(BaseOption.ENV), 90000000);
- 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: 'wss://pbx.fuxicarbon.com/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 };
|