1"use strict";(self.webpackChunkwebclient_webpack=self.webpackChunkwebclient_webpack||[]).push([[1786],{48714(Ie,G,s){s.r(G),s.d(G,{YealinkHidService:()=>ye});var N=s(89204),ee=s(84205),Z=s(137),A=s(18537),te=s(63617),h=s(59452),I=s(53081),R=s(36647),V=s(77919),ne=s(61318),le=s(21995),se=s(71870),oe=s(56042),y=s(59400),j=s(23513),w=s(50994),v=s(18288),$=s(70271),D=s(51567),ae=s(27176),re=s(91817),ie=s(89475),E=s(98764),ce=s(63037),ue=s(72354),J=s(64334),Q=s(55467),r=s(983);const O=65328;var u=function(e){return e[e.OnHook=0]="OnHook",e[e.OffHook=1]="OffHook",e[e.Mute=2]="Mute",e[e.Ring=4]="Ring",e[e.Hold=8]="Hold",e}(u||{}),m=function(e){return e[e.HookSwitch=32]="HookSwitch",e[e.Flash=33]="Flash",e[e.PhoneMute=47]="PhoneMute",e[e.LineBusy=151]="LineBusy",e[e.Reject=7]="Reject",e[e.RejectYL=65533]="RejectYL",e}(m||{}),d=function(e){return e[e.None=0]="None",e[e.Key0=1]="Key0",e[e.Key1=2]="Key1",e[e.Key2=3]="Key2",e[e.Key3=4]="Key3",e[e.Key4=5]="Key4",e[e.Key5=6]="Key5",e[e.Key6=7]="Key6",e[e.Key7=8]="Key7",e[e.Key8=9]="Key8",e[e.Key9=10]="Key9",e[e.KeyStar=11]="KeyStar",e[e.KeyPound=12]="KeyPound",e}(d||{});const S=[{vendorId:r.dW,usagePage:11,usage:5}],i="Yealink -";function K(){return(K=(0,N.A)(function*(e){const l=(yield navigator.hid.requestDevice(e))[0]??null;return(0,r.Vv)(i,"device requested:",l?.productName),l})).apply(this,arguments)}function F(){return(F=(0,N.A)(function*(e){return e.opened||(yield e.open()),(0,r.Vv)(i,"device opened:",e.productName),e})).apply(this,arguments)}function B(e){return U.apply(this,arguments)}function U(){return(U=(0,N.A)(function*(e){const t=yield navigator.hid.getDevices();return(0,r.Vv)(i,"available devices list:",t.map(l=>l.productName)),t.find(l=>H(l,e))??null})).apply(this,arguments)}function H(e,t){const l=t.some(a=>(void 0===a.vendorId||e.vendorId===a.vendorId)&&(void 0===a.productId||e.productId===a.productId)&&k(e));return"HID debug interface"!==e.productName&&l}function X(e){return e.collections.some(t=>t.usagePage===O)}function k(e){return e.collections.some(t=>11===t.usagePage)}function M(e,t){return e.collections.find(a=>a.usagePage===t)?.inputReports?.[0].reportId}function b(e){const t=M(e,O),l=M(e,11);return t??l??-1}var C=s(20412);class ye{skipConfirmation=0;requestedDevice$=new ee.B;callStateHelper=new C.o;device$;next=Promise.resolve();keypadDigitsPressed=[];digitButtonTypesMapper=new Map([[d.Key0,"0"],[d.Key1,"1"],[d.Key2,"2"],[d.Key3,"3"],[d.Key4,"4"],[d.Key5,"5"],[d.Key6,"6"],[d.Key7,"7"],[d.Key8,"8"],[d.Key9,"9"],[d.KeyStar,"*"],[d.KeyPound,"#"]]);diagnostics$;headsetEvents$;constructor(){const t=(0,Z.v)(()=>this.init()).pipe((0,$.T)(n=>({type:"init",device:n}))),l=this.requestedDevice$.pipe((0,D.p)(n=>!!n&&H(n,S)),(0,$.T)(n=>({type:"request",device:n}))),a=(0,A.R)(navigator.hid,"connect").pipe((0,$.T)(n=>({type:"connect",device:n.device}))),c=(0,A.R)(navigator.hid,"disconnect").pipe((0,D.p)(n=>!!n.device&&H(n.device,S)),(0,$.T)(n=>({type:"disconnect",device:n.device})));this.device$=(0,te.h)(t,l,a,c).pipe((0,ae.i)((n,o)=>"init"===o.type?((0,r.Vv)(i," device init:",o.device?.productName),(0,h.of)(o.device)):"request"===o.type?((0,r.Vv)(i,"device paired:",o.device?.productName),o.device?(0,h.of)(o.device):n?(0,h.of)(n):(0,I.H)(B(S))):"connect"!==o.type||n?"disconnect"===o.type&&o.device===n?((0,r.Vv)(i,"device disconnected:",o.device?.productName),(0,I.H)(B(S))):(0,h.of)(n):((0,r.Vv)(i,"device connected:",o.device?.productName),(0,h.of)(o.device)),null,1),(0,R.n)(n=>{if(n){if(!k(n)&&!X(n))return(0,V.$)(()=>new Error(`Device "${n.productName}" does not support neither Standard telephony page (11) nor Yealink telephony page (${O}).`));if(!H(n,S))return(0,V.$)(()=>new Error(`Device "${n.productName}" is not a a supported HID device.`));if(b(n)<0)return(0,V.$)(()=>new Error("Report id for communication could not be extracted"));if(!n.opened)return(0,I.H)(function Ce(e){return F.apply(this,arguments)}(n))}return(0,h.of)(n)}),(0,re.F)((n,o)=>n?.productId===o?.productId),(0,ne.W)(n=>{throw(0,r.Vg)(i,n),n}),(0,le.L)({delay:5e3}),(0,se.u)({connector:()=>new oe.m(1)})),this.headsetEvents$=this.device$.pipe((0,D.p)(n=>!!n),(0,R.n)(n=>{if(n){const o=function pe(e){const t={};(0,r.Vv)("Yealink Integration -","device collections: ",e.collections);for(const l of e.collections)if(l.inputReports){const a=l.usagePage;for(const c of l.inputReports){let n=1;c.reportId&&c.items&&(t[c.reportId]=c.items.reduce((o,g)=>{if(1===g.reportSize&&g.reportCount&&g.usages&&g.usages.length>0)for(const P of g.usages)o.push({mask:n,usagePage:a,usages:[P]}),n<<=1;return o},[]))}}return(0,r.Vv)(i," reports extracted:",t),t}(n),g=M(n,11),P=M(n,O);return(0,r.Vv)(i,`device supports ${X(n)?"Yealink":"Standard"} Telephony Interface on report id ${b(n)}`),(0,A.R)(n,"inputreport").pipe((0,R.n)(T=>{const{data:z,reportId:W}=T;if(W!==g&&W!==P)return y.w;const _=z.getUint8(0),L=function he(e){const t=function de(e,t,l){return(1<<l)-1&e>>t}(e,7,4);return Object.values(d).filter(a=>!isNaN(Number(a))).some(a=>a===t)?t:d.None}(_+256*z.getUint8(1)),Se=Object.values(m).filter(p=>!isNaN(Number(p))),f=function fe(e,t,l,a){const c=e[t];if(!c)return[];(0,r.Vv)(i,`processing reportId: ${t}, value: ${l}`);const n=[];for(const o of c)if(o.mask&l){const T=~((o.usagePage??0)<<16)&(o.usages[0]??0);a.some(Y=>
1Y===T)&&n.push(T)}return n}(o,W,_,Se);if(0===f.length&&L===d.None)return y.w;const $e=`\n Digit pressed: ${d[L]}`,xe=`\n Received States: ${f.length>0?f.map(p=>m[p]+":"+p.toString(16)).join(", "):"None"}`;if((0,r.Vv)(i,`${xe}${$e}`),L!==d.None){const p=this.digitButtonTypesMapper.get(L);if(this.skipConfirmation=Date.now(),p){if(this.callStateHelper.activeCall!==C.o.NO_CALL)return(0,h.of)({CallId:this.callStateHelper.activeCall,Action:v.T.SendDtmf,Value:p});this.keypadDigitsPressed.push(p)}}else if(1===f.length&&f.includes(m.HookSwitch)){if(this.callStateHelper.activeCall!==C.o.NO_CALL)return this.skipConfirmation>0&&Date.now()-this.skipConfirmation<2e3?(this.skipConfirmation=0,y.w):(0,h.of)({CallId:this.callStateHelper.activeCall,Action:v.T.TerminateCall});{const p=this.callStateHelper.ringingCalls.values().next()?.value;if(void 0!==p)return(0,h.of)({CallId:p,Action:v.T.AcceptCall});if(this.callStateHelper.activeCall===C.o.NO_CALL&&this.keypadDigitsPressed.length>0){const Ne=this.keypadDigitsPressed.join("");return(0,h.of)({CallId:-1,Action:v.T.MakeCall,Value:Ne})}}}else if(1===f.length&&f.includes(m.LineBusy)){const p=this.callStateHelper.ringingCalls.values().next()?.value;if(void 0!==p)return(0,h.of)({CallId:p,Action:v.T.AcceptCall})}else if(f.includes(m.PhoneMute)){if(this.callStateHelper.activeCall!==C.o.NO_CALL)return this.skipConfirmation=Date.now(),(0,h.of)({CallId:this.callStateHelper.activeCall,Action:v.T.ToggleMuteCall})}else if(f.includes(m.Reject)||f.includes(m.RejectYL)){const p=this.callStateHelper.ringingCalls.values().next()?.value;if(void 0!==p)return this.skipConfirmation=Date.now(),(0,h.of)({CallId:p,Action:v.T.RejectCall})}else if(f.includes(m.Flash)){this.skipConfirmation=Date.now();const p=this.callStateHelper.ringingCalls.values().next()?.value;return(0,h.of)(void 0!==p?{CallId:p,Action:v.T.AcceptCall}:{CallId:-1,Action:v.T.FlashCall})}return y.w}),(0,ie.j)(()=>{(0,r.Vv)(i,"device closing:",n.productName),n.close().catch(()=>{})}))}return y.w}),(0,E.M)(()=>{this.keypadDigitsPressed=[]}),(0,E.M)(n=>(0,r.Vv)(i,`Headset Command Fired ${v.T[n.Action]} (Value:${n.Value}) with CallId ${n.CallId}`))),this.diagnostics$=this.device$.pipe((0,$.T)(n=>n?new w.j({alertClass:"success",text:`${n.productName} ${n.opened?"connected":"not connected"}`}):w.j.error("No device is connected")),(0,ce.Z)(w.j.Progress))}init(){return(0,N.A)(function*(){return(yield B(S))??null})()}sendCommand(t,l=!0){let a=0;for(const c of t)a|=c;return this.device$.pipe((0,D.p)(c=>!!c),(0,R.n)(c=>{if(!c)throw new Error("No device is connected:");a&u.OffHook&&l&&(this.skipConfirmation=Date.now());const n=function ve(e){return new Uint8Array([255&(e||0)])}(a),o=b(c);return(0,r.Vv)(i,`Send Report "${o}" with data: "${n}" To "${c.productName}" HID device`),(0,I.H)(c.sendReport(o,n)).pipe((0,ue.w)({each:5e3,with:()=>(0,V.$)(()=>new Error(`${i} Yealink did not respond in the expected time`))}))}),(0,E.M)(()=>(0,r.Vv)(i,`Send Actions to headset(Combined bitwise):\n ${t.map(c=>u[c]+":"+c).join(", ")}`)),(0,J.s)(1))}nextCommand(t){this.next=this.next.then(()=>new Promise(l=>{t().subscribe({error:a=>{(0,r.Vg)(i,a),l()},complete:l})}))}holdCall(t){(0,r.Vv)(i,`pbx call command: holdCall (${t})`),this.nextCommand(()=>(this.callStateHelper.holdCalls.add(t),t!==this.callStateHelper.activeCall?y.w:(this.callStateHelper.activeCall=C.o.NO_CALL,this.callStateHelper.isActiveCallMuted=!1,this.sendCommand([u.Hold,u.OnHook]))))}resumeCall(t){(0,r.Vv)(i,`pbx call command: resumeCall (${t})`),this.nextCommand(()=>(this.callStateHelper.holdCalls.delete(t),this.callStateHelper.activeCall=t,(0,j.x)(...this.callStateHelper.callCount>1?[this.sendCommand([u.Hold,u.OnHook]).pipe((0,Q.c)(1e3))]:[y.w],this.sendCommand([u.OffHook]))))}incomingCall(t){(0,r.Vv)(i,`pbx call command: incomingCall (${t})`),this.nextCommand(()=>{const l=[...this.callStateHelper.activeCall!==C.o.NO_CALL?[u.OffHook]:[],u.Ring,...this.callStateHelper.isActiveCallMuted?[u.Mute]:[]];return this.callStateHelper.ringingCalls.add(t),this.callStateHelper.totalCalls.add(t),(0,j.x)(this.sendCommand(l,!1))})}incomingCallAccepted(t){(0,r.Vv)(i,`pbx call command: incomingCallAccepted (${t})`),this.nextCommand(()=>(this.callStateHelper.activeCall=t,this.callStateHelper.isActiveCallMuted=!1,this.callStateHelper.ringingCalls.delete(t),(0,j.x)(this.sendCommand([u.OffHook]).pipe((0,Q.c)(1e3)),...this.callStateHelper.ringingCalls.size>0?[this.sendCommand([u.OffHook,u.Ring])]:[y.w])))}mute(t,l){(0,r.Vv)(i,`pbx call command mute (${t}) with value ${l}`),this.nextCommand(()=>{this.callStateHelper.isActiveCallMuted=l;const a=[u.OffHook,...l?[u.Mute]:[]];return this.sendCommand(a,!1)})}outgoingCall(t){(0,r.Vv)(i,`pbx call command: outgoingCall (${t})`),this.nextCommand(()=>(this.callStateHelper.totalCalls.add(t),this.callStateHelper.activeCall=t,this.callStateHelper.isActiveCallMuted=!1,this.sendCommand([u.OffHook])))}outgoingCallAccepted(t){(0,r.Vv)(i,`pbx call command: outgoingCallAccepted (${t})`)}terminateCall(t){(0,r.Vv)(i,`pbx call command: terminateCall (${t})`),this.nextCommand(()=>{this.callStateHelper.ringingCalls.delete(t),this.callStateHelper.holdCalls.delete(t),this.callStateHelper.totalCalls.delete(t),this.callStateHelper.activeCall===t&&(this.callStateHelper.activeCall=C.o.NO_CALL,this.callStateHelper.isActiveCallMuted=!1);const c=this.callStateHelper.hasNoCalls?[u.OnHook]:[...this.callStateHelper.hasRingingCalls?[u.Ring]:[],...this.callStateHelper.isActiveCallMuted?[u.Mute]:[],...this.callStateHelper.hasNoCalls||this.callStateHelper.activeCall===C.o.NO_CALL||this.callStateHelper.callCount===this.callStateHelper.holdCalls.size?[u.OnHook]:[u.OffHook],...this.callStateHelper.hasHoldCalls?[u.Hold]:[]];return this.sendCommand(c)})}connectDevice(){(0,Z.v)(()=>function me(e){return K.apply(this,arguments)}({filters:S})).pipe((0,J.s)(1)).subscribe({next:t=>{this.requestedDevice$.next(t)}})}}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.