yjz-web-sdk 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/yjz-web-sdk.js +8 -8
- package/lib/yjz-web-sdk.umd.cjs +1 -1
- package/package.json +1 -1
package/lib/yjz-web-sdk.js
CHANGED
|
@@ -3147,7 +3147,6 @@ const createPeerConnection = (config) => {
|
|
|
3147
3147
|
const configPeerConnection = (peerConnection, onICEMessage, onTrack, onConnectState, onError) => {
|
|
3148
3148
|
peerConnection.onicecandidate = (event) => {
|
|
3149
3149
|
if (!event.candidate) {
|
|
3150
|
-
console.log("ICE candidate collection completed");
|
|
3151
3150
|
return;
|
|
3152
3151
|
}
|
|
3153
3152
|
const candidateObj = {
|
|
@@ -3260,18 +3259,20 @@ class WebRTCClient extends EventEmitter {
|
|
|
3260
3259
|
clearInterval(this.statsTimer);
|
|
3261
3260
|
this.statsTimer = null;
|
|
3262
3261
|
}
|
|
3263
|
-
if (
|
|
3264
|
-
if (this.peerConnection.getSenders) {
|
|
3262
|
+
if (this.peerConnection) {
|
|
3263
|
+
if (typeof this.peerConnection.getSenders === "function" && this.peerConnection.getSenders) {
|
|
3265
3264
|
this.peerConnection.getSenders().forEach((sender) => {
|
|
3265
|
+
var _a, _b;
|
|
3266
3266
|
if (sender.track) {
|
|
3267
|
-
sender.track.stop();
|
|
3267
|
+
(_b = (_a = sender.track).stop) == null ? void 0 : _b.call(_a);
|
|
3268
3268
|
}
|
|
3269
3269
|
});
|
|
3270
3270
|
}
|
|
3271
|
-
if (this.peerConnection.getReceivers) {
|
|
3271
|
+
if (typeof this.peerConnection.getReceivers === "function" && this.peerConnection.getReceivers) {
|
|
3272
3272
|
this.peerConnection.getReceivers().forEach((receiver) => {
|
|
3273
|
+
var _a, _b;
|
|
3273
3274
|
if (receiver.track) {
|
|
3274
|
-
receiver.track.stop();
|
|
3275
|
+
(_b = (_a = receiver.track).stop) == null ? void 0 : _b.call(_a);
|
|
3275
3276
|
}
|
|
3276
3277
|
});
|
|
3277
3278
|
}
|
|
@@ -3281,7 +3282,6 @@ class WebRTCClient extends EventEmitter {
|
|
|
3281
3282
|
(_a = transceiver.stop) == null ? void 0 : _a.call(transceiver);
|
|
3282
3283
|
});
|
|
3283
3284
|
}
|
|
3284
|
-
this.peerConnection.close();
|
|
3285
3285
|
this.removeAllListeners();
|
|
3286
3286
|
this.dataChannel = null;
|
|
3287
3287
|
this.peerConnection.onicecandidate = null;
|
|
@@ -3292,6 +3292,7 @@ class WebRTCClient extends EventEmitter {
|
|
|
3292
3292
|
this.peerConnection.onsignalingstatechange = null;
|
|
3293
3293
|
this.peerConnection.onnegotiationneeded = null;
|
|
3294
3294
|
this.peerConnection.onicegatheringstatechange = null;
|
|
3295
|
+
this.peerConnection.close();
|
|
3295
3296
|
this.peerConnection = null;
|
|
3296
3297
|
}
|
|
3297
3298
|
}
|
|
@@ -3371,7 +3372,6 @@ class WebRTCClient extends EventEmitter {
|
|
|
3371
3372
|
configPeerConnection(this.peerConnection, (candidate) => {
|
|
3372
3373
|
this.emit(EmitType.sendICEMessage, candidate);
|
|
3373
3374
|
}, (track) => {
|
|
3374
|
-
console.error("send track====>", track, Date.now());
|
|
3375
3375
|
this.emit(EmitType.streamTrack, track);
|
|
3376
3376
|
}, (state) => {
|
|
3377
3377
|
this.emit(EmitType.iceConnectionState, state);
|
package/lib/yjz-web-sdk.umd.cjs
CHANGED
|
@@ -55,7 +55,7 @@ type:t[7]};for(let r=8;r<t.length;r+=2)switch(t[r]){case"raddr":n.relatedAddress
|
|
|
55
55
|
// algorithm is case-sensitive in Edge.
|
|
56
56
|
value:t[1].toUpperCase()}},t.getDtlsParameters=function(e,n){return{role:"auto",fingerprints:t.matchPrefix(e+n,"a=fingerprint:").map(t.parseFingerprint)}},t.writeDtlsParameters=function(e,t){let n="a=setup:"+t+"\r\n";return e.fingerprints.forEach((e=>{n+="a=fingerprint:"+e.algorithm+" "+e.value+"\r\n"})),n},t.parseCryptoLine=function(e){const t=e.substring(9).split(" ");return{tag:parseInt(t[0],10),cryptoSuite:t[1],keyParams:t[2],sessionParams:t.slice(3)}},t.writeCryptoLine=function(e){return"a=crypto:"+e.tag+" "+e.cryptoSuite+" "+("object"==typeof e.keyParams?t.writeCryptoKeyParams(e.keyParams):e.keyParams)+(e.sessionParams?" "+e.sessionParams.join(" "):"")+"\r\n"},t.parseCryptoKeyParams=function(e){if(0!==e.indexOf("inline:"))return null;const t=e.substring(7).split("|");return{keyMethod:"inline",keySalt:t[0],lifeTime:t[1],mkiValue:t[2]?t[2].split(":")[0]:void 0,mkiLength:t[2]?t[2].split(":")[1]:void 0}},t.writeCryptoKeyParams=function(e){return e.keyMethod+":"+e.keySalt+(e.lifeTime?"|"+e.lifeTime:"")+(e.mkiValue&&e.mkiLength?"|"+e.mkiValue+":"+e.mkiLength:"")},t.getCryptoParameters=function(e,n){return t.matchPrefix(e+n,"a=crypto:").map(t.parseCryptoLine)},t.getIceParameters=function(e,n){const r=t.matchPrefix(e+n,"a=ice-ufrag:")[0],i=t.matchPrefix(e+n,"a=ice-pwd:")[0];return r&&i?{usernameFragment:r.substring(12),password:i.substring(10)}:null},t.writeIceParameters=function(e){let t="a=ice-ufrag:"+e.usernameFragment+"\r\na=ice-pwd:"+e.password+"\r\n";return e.iceLite&&(t+="a=ice-lite\r\n"),t},t.parseRtpParameters=function(e){const n={codecs:[],headerExtensions:[],fecMechanisms:[],rtcp:[]},r=t.splitLines(e)[0].split(" ");n.profile=r[2];for(let o=3;o<r.length;o++){const i=r[o],s=t.matchPrefix(e,"a=rtpmap:"+i+" ")[0];if(s){const r=t.parseRtpMap(s),o=t.matchPrefix(e,"a=fmtp:"+i+" ");switch(r.parameters=o.length?t.parseFmtp(o[0]):{},r.rtcpFeedback=t.matchPrefix(e,"a=rtcp-fb:"+i+" ").map(t.parseRtcpFb),n.codecs.push(r),r.name.toUpperCase()){case"RED":case"ULPFEC":n.fecMechanisms.push(r.name.toUpperCase())}}}t.matchPrefix(e,"a=extmap:").forEach((e=>{n.headerExtensions.push(t.parseExtmap(e))}));const i=t.matchPrefix(e,"a=rtcp-fb:* ").map(t.parseRtcpFb);return n.codecs.forEach((e=>{i.forEach((t=>{e.rtcpFeedback.find((e=>e.type===t.type&&e.parameter===t.parameter))||e.rtcpFeedback.push(t)}))})),n},t.writeRtpDescription=function(e,n){let r="";r+="m="+e+" ",r+=n.codecs.length>0?"9":"0",r+=" "+(n.profile||"UDP/TLS/RTP/SAVPF")+" ",r+=n.codecs.map((e=>void 0!==e.preferredPayloadType?e.preferredPayloadType:e.payloadType)).join(" ")+"\r\n",r+="c=IN IP4 0.0.0.0\r\n",r+="a=rtcp:9 IN IP4 0.0.0.0\r\n",n.codecs.forEach((e=>{r+=t.writeRtpMap(e),r+=t.writeFmtp(e),r+=t.writeRtcpFb(e)}));let i=0;return n.codecs.forEach((e=>{e.maxptime>i&&(i=e.maxptime)})),i>0&&(r+="a=maxptime:"+i+"\r\n"),n.headerExtensions&&n.headerExtensions.forEach((e=>{r+=t.writeExtmap(e)})),r},t.parseRtpEncodingParameters=function(e){const n=[],r=t.parseRtpParameters(e),i=-1!==r.fecMechanisms.indexOf("RED"),o=-1!==r.fecMechanisms.indexOf("ULPFEC"),s=t.matchPrefix(e,"a=ssrc:").map((e=>t.parseSsrcMedia(e))).filter((e=>"cname"===e.attribute)),a=s.length>0&&s[0].ssrc;let c;const p=t.matchPrefix(e,"a=ssrc-group:FID").map((e=>e.substring(17).split(" ").map((e=>parseInt(e,10)))));p.length>0&&p[0].length>1&&p[0][0]===a&&(c=p[0][1]),r.codecs.forEach((e=>{if("RTX"===e.name.toUpperCase()&&e.parameters.apt){let t={ssrc:a,codecPayloadType:parseInt(e.parameters.apt,10)};a&&c&&(t.rtx={ssrc:c}),n.push(t),i&&(t=JSON.parse(JSON.stringify(t)),t.fec={ssrc:a,mechanism:o?"red+ulpfec":"red"},n.push(t))}})),0===n.length&&a&&n.push({ssrc:a});let d=t.matchPrefix(e,"b=");return d.length&&(d=0===d[0].indexOf("b=TIAS:")?parseInt(d[0].substring(7),10):0===d[0].indexOf("b=AS:")?1e3*parseInt(d[0].substring(5),10)*.95-16e3:void 0,n.forEach((e=>{e.maxBitrate=d}))),n},t.parseRtcpParameters=function(e){const n={},r=t.matchPrefix(e,"a=ssrc:").map((e=>t.parseSsrcMedia(e))).filter((e=>"cname"===e.attribute))[0];r&&(n.cname=r.value,n.ssrc=r.ssrc);const i=t.matchPrefix(e,"a=rtcp-rsize");n.reducedSize=i.length>0,n.compound=0===i.length;const o=t.matchPrefix(e,"a=rtcp-mux");return n.mux=o.length>0,n},t.writeRtcpParameters=function(e){let t="";return e.reducedSize&&(t+="a=rtcp-rsize\r\n"),e.mux&&(t+="a=rtcp-mux\r\n"),void 0!==e.ssrc&&e.cname&&(t+="a=ssrc:"+e.ssrc+" cname:"+e.cname+"\r\n"),t},t.parseMsid=function(e){let n;const r=t.matchPrefix(e,"a=msid:");if(1===r.length)return n=r[0].substring(7).split(" "),{stream:n[0],track:n[1]};const i=t.matchPrefix(e,"a=ssrc:").map((e=>t.parseSsrcMedia(e))).filter((e=>"msid"===e.attribute));return i.length>0?(n=i[0].value.split(" "),{stream:n[0],track:n[1]}):void 0},t.parseSctpDescription=function(e){const n=t.parseMLine(e),r=t.matchPrefix(e,"a=max-message-size:");let i;r.length>0&&(i=parseInt(r[0].substring(19),10)),isNaN(i)&&(i=65536);const o=t.matchPrefix(e,"a=sctp-port:");if(o.length>0)return{port:parseInt(o[0].substring(12),10),protocol:n.fmt,maxMessageSize:i};const s=t.matchPrefix(e,"a=sctpmap:");if(s.length>0){const e=s[0].substring(10).split(" ");return{port:parseInt(e[0],10),protocol:e[1],maxMessageSize:i}}},t.writeSctpDescription=function(e,t){let n=[];return n="DTLS/SCTP"!==e.protocol?["m="+e.kind+" 9 "+e.protocol+" "+t.protocol+"\r\n","c=IN IP4 0.0.0.0\r\n","a=sctp-port:"+t.port+"\r\n"]:["m="+e.kind+" 9 "+e.protocol+" "+t.port+"\r\n","c=IN IP4 0.0.0.0\r\n","a=sctpmap:"+t.port+" "+t.protocol+" 65535\r\n"],void 0!==t.maxMessageSize&&n.push("a=max-message-size:"+t.maxMessageSize+"\r\n"),n.join("")},t.generateSessionId=function(){return Math.random().toString().substr(2,22)},t.writeSessionBoilerplate=function(e,n,r){let i;const o=void 0!==n?n:2;return i=e||t.generateSessionId(),"v=0\r\no="+(r||"thisisadapterortc")+" "+i+" "+o+" IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\n"},t.getDirection=function(e,n){const r=t.splitLines(e);for(let t=0;t<r.length;t++)switch(r[t]){case"a=sendrecv":case"a=sendonly":case"a=recvonly":case"a=inactive":return r[t].substring(2)}return n?t.getDirection(n):"sendrecv"},t.getKind=function(e){return t.splitLines(e)[0].split(" ")[0].substring(2)},t.isRejected=function(e){return"0"===e.split(" ",2)[1]},t.parseMLine=function(e){const n=t.splitLines(e)[0].substring(2).split(" ");return{kind:n[0],port:parseInt(n[1],10),protocol:n[2],fmt:n.slice(3).join(" ")}},t.parseOLine=function(e){const n=t.matchPrefix(e,"o=")[0].substring(2).split(" ");return{username:n[0],sessionId:n[1],sessionVersion:parseInt(n[2],10),netType:n[3],addressType:n[4],address:n[5]}},t.isValidSDP=function(e){if("string"!=typeof e||0===e.length)return!1;const n=t.splitLines(e);for(let t=0;t<n.length;t++)if(n[t].length<2||"="!==n[t].charAt(1))return!1;return!0},e.exports=t}(ue)),ue.exports);const me=i(fe),Ce=r({__proto__:null,default:me},[fe]);function ye(e){if(!e.RTCIceCandidate||e.RTCIceCandidate&&"foundation"in e.RTCIceCandidate.prototype)return;const t=e.RTCIceCandidate;e.RTCIceCandidate=function(e){if("object"==typeof e&&e.candidate&&0===e.candidate.indexOf("a=")&&((e=JSON.parse(JSON.stringify(e))).candidate=e.candidate.substring(2)),e.candidate&&e.candidate.length){const n=new t(e),r=me.parseCandidate(e.candidate);for(const e in r)e in n||Object.defineProperty(n,e,{value:r[e]});return n.toJSON=function(){return{candidate:n.candidate,sdpMid:n.sdpMid,sdpMLineIndex:n.sdpMLineIndex,usernameFragment:n.usernameFragment}},n}return new t(e)},e.RTCIceCandidate.prototype=t.prototype,E(e,"icecandidate",(t=>(t.candidate&&Object.defineProperty(t,"candidate",{value:new e.RTCIceCandidate(t.candidate),writable:"false"}),t)))}function ge(e){!e.RTCIceCandidate||e.RTCIceCandidate&&"relayProtocol"in e.RTCIceCandidate.prototype||E(e,"icecandidate",(e=>{if(e.candidate){const t=me.parseCandidate(e.candidate.candidate);"relay"===t.type&&(e.candidate.relayProtocol={0:"tls",1:"tcp",2:"udp"}[t.priority>>24])}return e}))}function ve(e,t){if(!e.RTCPeerConnection)return;"sctp"in e.RTCPeerConnection.prototype||Object.defineProperty(e.RTCPeerConnection.prototype,"sctp",{get(){return void 0===this._sctp?null:this._sctp}});const n=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(){if(this._sctp=null,"chrome"===t.browser&&t.version>=76){const{sdpSemantics:e}=this.getConfiguration();"plan-b"===e&&Object.defineProperty(this,"sctp",{get(){return void 0===this._sctp?null:this._sctp},enumerable:!0,configurable:!0})}if(function(e){if(!e||!e.sdp)return!1;const t=me.splitSections(e.sdp);return t.shift(),t.some((e=>{const t=me.parseMLine(e);return t&&"application"===t.kind&&-1!==t.protocol.indexOf("SCTP")}))}(arguments[0])){const e=function(e){const t=e.sdp.match(/mozilla...THIS_IS_SDPARTA-(\d+)/);if(null===t||t.length<2)return-1;const n=parseInt(t[1],10);return n!=n?-1:n}(arguments[0]),n=function(e){let n=65536;return"firefox"===t.browser&&(n=t.version<57?-1===e?16384:2147483637:t.version<60?57===t.version?65535:65536:2147483637),n}(e),r=function(e,n){let r=65536;"firefox"===t.browser&&57===t.version&&(r=65535);const i=me.matchPrefix(e.sdp,"a=max-message-size:");return i.length>0?r=parseInt(i[0].substring(19),10):"firefox"===t.browser&&-1!==n&&(r=2147483637),r}(arguments[0],e);let i;i=0===n&&0===r?Number.POSITIVE_INFINITY:0===n||0===r?Math.max(n,r):Math.min(n,r);const o={};Object.defineProperty(o,"maxMessageSize",{get:()=>i}),this._sctp=o}return n.apply(this,arguments)}}function Se(e){if(!e.RTCPeerConnection||!("createDataChannel"in e.RTCPeerConnection.prototype))return;function t(e,t){const n=e.send;e.send=function(){const r=arguments[0],i=r.length||r.size||r.byteLength;if("open"===e.readyState&&t.sctp&&i>t.sctp.maxMessageSize)throw new TypeError("Message too large (can send a maximum of "+t.sctp.maxMessageSize+" bytes)");return n.apply(e,arguments)}}const n=e.RTCPeerConnection.prototype.createDataChannel;e.RTCPeerConnection.prototype.createDataChannel=function(){const e=n.apply(this,arguments);return t(e,this),e},E(e,"datachannel",(e=>(t(e.channel,e.target),e)))}function Te(e){if(!e.RTCPeerConnection||"connectionState"in e.RTCPeerConnection.prototype)return;const t=e.RTCPeerConnection.prototype;Object.defineProperty(t,"connectionState",{get(){return{completed:"connected",checking:"connecting"}[this.iceConnectionState]||this.iceConnectionState},enumerable:!0,configurable:!0}),Object.defineProperty(t,"onconnectionstatechange",{get(){return this._onconnectionstatechange||null},set(e){this._onconnectionstatechange&&(this.removeEventListener("connectionstatechange",this._onconnectionstatechange),delete this._onconnectionstatechange),e&&this.addEventListener("connectionstatechange",this._onconnectionstatechange=e)},enumerable:!0,configurable:!0}),["setLocalDescription","setRemoteDescription"].forEach((e=>{const n=t[e];t[e]=function(){return this._connectionstatechangepoly||(this._connectionstatechangepoly=e=>{const t=e.target;if(t._lastConnectionState!==t.connectionState){t._lastConnectionState=t.connectionState;const n=new Event("connectionstatechange",e);t.dispatchEvent(n)}return e},this.addEventListener("iceconnectionstatechange",this._connectionstatechangepoly)),n.apply(this,arguments)}}))}function Re(e,t){if(!e.RTCPeerConnection)return;if("chrome"===t.browser&&t.version>=71)return;if("safari"===t.browser&&t.version>=605)return;const n=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(t){if(t&&t.sdp&&-1!==t.sdp.indexOf("\na=extmap-allow-mixed")){const n=t.sdp.split("\n").filter((e=>"a=extmap-allow-mixed"!==e.trim())).join("\n");e.RTCSessionDescription&&t instanceof e.RTCSessionDescription?arguments[0]=new e.RTCSessionDescription({type:t.type,sdp:n}):t.sdp=n}return n.apply(this,arguments)}}function be(e,t){if(!e.RTCPeerConnection||!e.RTCPeerConnection.prototype)return;const n=e.RTCPeerConnection.prototype.addIceCandidate;n&&0!==n.length&&(e.RTCPeerConnection.prototype.addIceCandidate=function(){return arguments[0]?("chrome"===t.browser&&t.version<78||"firefox"===t.browser&&t.version<68||"safari"===t.browser)&&arguments[0]&&""===arguments[0].candidate?Promise.resolve():n.apply(this,arguments):(arguments[1]&&arguments[1].apply(null),Promise.resolve())})}function Pe(e,t){if(!e.RTCPeerConnection||!e.RTCPeerConnection.prototype)return;const n=e.RTCPeerConnection.prototype.setLocalDescription;n&&0!==n.length&&(e.RTCPeerConnection.prototype.setLocalDescription=function(){let e=arguments[0]||{};if("object"!=typeof e||e.type&&e.sdp)return n.apply(this,arguments);if(e={type:e.type,sdp:e.sdp},!e.type)switch(this.signalingState){case"stable":case"have-local-offer":case"have-remote-pranswer":e.type="offer";break;default:e.type="answer"}if(e.sdp||"offer"!==e.type&&"answer"!==e.type)return n.apply(this,[e]);return("offer"===e.type?this.createOffer:this.createAnswer).apply(this).then((e=>n.apply(this,[e])))})}const Ee=Object.freeze(Object.defineProperty({__proto__:null,removeExtmapAllowMixed:Re,shimAddIceCandidateNullOrEmpty:be,shimConnectionState:Te,shimMaxMessageSize:ve,shimParameterlessSetLocalDescription:Pe,shimRTCIceCandidate:ye,shimRTCIceCandidateRelayProtocol:ge,shimSendThrowTypeError:Se},Symbol.toStringTag,{value:"Module"}));const we=function({window:e}={},t={shimChrome:!0,shimFirefox:!0,shimSafari:!0}){const n=k,r=function(e){const t={browser:null,version:null};if(void 0===e||!e.navigator||!e.navigator.userAgent)return t.browser="Not a browser.",t;const{navigator:n}=e;if(n.userAgentData&&n.userAgentData.brands){const e=n.userAgentData.brands.find((e=>"Chromium"===e.brand));if(e)return{browser:"chrome",version:parseInt(e.version,10)}}if(n.mozGetUserMedia)t.browser="firefox",t.version=P(n.userAgent,/Firefox\/(\d+)\./,1);else if(n.webkitGetUserMedia||!1===e.isSecureContext&&e.webkitRTCPeerConnection)t.browser="chrome",t.version=P(n.userAgent,/Chrom(e|ium)\/(\d+)\./,2);else{if(!e.RTCPeerConnection||!n.userAgent.match(/AppleWebKit\/(\d+)\./))return t.browser="Not a supported browser.",t;t.browser="safari",t.version=P(n.userAgent,/AppleWebKit\/(\d+)\./,1),t.supportsUnifiedPlan=e.RTCRtpTransceiver&&"currentDirection"in e.RTCRtpTransceiver.prototype}return t}(e),i={browserDetails:r,commonShim:Ee,extractVersion:P,disableLog:w,disableWarnings:_,
|
|
57
57
|
// Expose sdp as a convenience. For production apps include directly.
|
|
58
|
-
sdp:Ce};switch(r.browser){case"chrome":if(!V||!z||!t.shimChrome)return n("Chrome shim is not included in this adapter release."),i;if(null===r.version)return n("Chrome shim can not determine version, not shimming."),i;n("adapter.js shimming chrome."),i.browserShim=V,be(e,r),Pe(e),M(e,r),L(e),z(e,r),N(e),K(e,r),j(e),F(e),J(e,r),ye(e),ge(e),Te(e),ve(e,r),Se(e),Re(e,r);break;case"firefox":if(!te||!B||!t.shimFirefox)return n("Firefox shim is not included in this adapter release."),i;n("adapter.js shimming firefox."),i.browserShim=te,be(e,r),Pe(e),W(e,r),B(e,r),G(e),$(e),H(e),q(e),Y(e),Q(e),X(e),Z(e),ee(e),ye(e),Te(e),ve(e,r),Se(e);break;case"safari":if(!he||!t.shimSafari)return n("Safari shim is not included in this adapter release."),i;n("adapter.js shimming safari."),i.browserShim=he,be(e,r),Pe(e),ae(e),pe(e),ie(e),ne(e),re(e),ce(e),oe(e),de(e),ye(e),ge(e),ve(e,r),Se(e),Re(e,r);break;default:n("Unsupported browser!")}return i}({window:"undefined"==typeof window?void 0:window}),_e=(e,t,n)=>{e.createAnswer().then((r=>ke(e,r,t,n))).catch((e=>null==n?void 0:n(u(h.CREATE_ANSWER,e))))},ke=(e,t,n,r)=>{e.setLocalDescription(t).then((()=>{null==n||n(t.sdp??"")})).catch((e=>null==r?void 0:r(u(h.LOCAL_DES,e))))},De=(e,t,n)=>{e.createOffer().then((r=>Oe(e,r,t,n))).catch((e=>null==n?void 0:n(u(h.CREATE_OFFER,e))))},Oe=(e,t,n,r)=>{e.setLocalDescription(t).then((()=>n(t.sdp??""))).catch((e=>null==r?void 0:r(u(h.LOCAL_DES,e))))};class Ie extends c{constructor(e){super(),n(this,"config"),n(this,"peerConnection",null),n(this,"localStream",null),n(this,"isPushingStream",!1),n(this,"dataChannel",null),n(this,"statsTimer",null),n(this,"lastReportTime",0),n(this,"lastBytesReceived",0),n(this,"lastPacketsLost",0),n(this,"lastPacketsReceived",0),n(this,"lostPacketCount",0),n(this,"maxLostRate",0),n(this,"decodedCount",0),n(this,"lastSecondDecodedCount",0),this.config=e}async startPush(){if(!this.isPushingStream){this.isPushingStream=!0;try{await this.readyCapture()}catch(e){this.emit(f.webrtcError,u(h.CAMERA,e))}}}handleOffer(e){this.resetPeerConnection(),((e,t,n,r)=>{const i=new RTCSessionDescription({type:"offer",sdp:t});e.setRemoteDescription(i).then((()=>_e(e,n,r))).catch((e=>null==r?void 0:r(u(h.HANDLE_OFFER,e))))})(this.peerConnection,e,(e=>{this.emit(f.sendAnswer,e)}),(e=>this.emit(f.webrtcError,e)))}handleAnswer(e){((e,t,n)=>{const r=new RTCSessionDescription({type:"answer",sdp:t});e.setRemoteDescription(r).catch((e=>null==n?void 0:n(u(h.REMOTE_DES,e))))})(this.peerConnection,e,(e=>this.emit(f.webrtcError,e)))}handleIceCandidate(e){((e,t,n)=>{e.addIceCandidate(t).catch((e=>null==n?void 0:n(u(h.HANDLE_ICE,e))))})(this.peerConnection,e,(e=>this.emit(f.webrtcError,e)))}sendChannelData(e,t){try{let n="";switch(e){case C.ClickData:n=S.click(t);break;case C.ClipboardData:n=S.clipboard(t);break;case C.ActionInput:n=S.input(t);break;case C.ActionChinese:n=S.chinese(t);break;case C.ActionRequestCloudDeviceInfo:n=S.requestCloudDeviceInfo();break;case C.ActionClarity:n=S.clarity(t)}const r=(new TextEncoder).encode(n).buffer;this.dataChannel.send(r)}catch(n){this.emit(f.webrtcError,u(h.DATACHANNEL_ERR,n))}}closeConnection(){this.statsTimer&&(clearInterval(this.statsTimer),this.statsTimer=null),this.peerConnection
|
|
58
|
+
sdp:Ce};switch(r.browser){case"chrome":if(!V||!z||!t.shimChrome)return n("Chrome shim is not included in this adapter release."),i;if(null===r.version)return n("Chrome shim can not determine version, not shimming."),i;n("adapter.js shimming chrome."),i.browserShim=V,be(e,r),Pe(e),M(e,r),L(e),z(e,r),N(e),K(e,r),j(e),F(e),J(e,r),ye(e),ge(e),Te(e),ve(e,r),Se(e),Re(e,r);break;case"firefox":if(!te||!B||!t.shimFirefox)return n("Firefox shim is not included in this adapter release."),i;n("adapter.js shimming firefox."),i.browserShim=te,be(e,r),Pe(e),W(e,r),B(e,r),G(e),$(e),H(e),q(e),Y(e),Q(e),X(e),Z(e),ee(e),ye(e),Te(e),ve(e,r),Se(e);break;case"safari":if(!he||!t.shimSafari)return n("Safari shim is not included in this adapter release."),i;n("adapter.js shimming safari."),i.browserShim=he,be(e,r),Pe(e),ae(e),pe(e),ie(e),ne(e),re(e),ce(e),oe(e),de(e),ye(e),ge(e),ve(e,r),Se(e),Re(e,r);break;default:n("Unsupported browser!")}return i}({window:"undefined"==typeof window?void 0:window}),_e=(e,t,n)=>{e.createAnswer().then((r=>ke(e,r,t,n))).catch((e=>null==n?void 0:n(u(h.CREATE_ANSWER,e))))},ke=(e,t,n,r)=>{e.setLocalDescription(t).then((()=>{null==n||n(t.sdp??"")})).catch((e=>null==r?void 0:r(u(h.LOCAL_DES,e))))},De=(e,t,n)=>{e.createOffer().then((r=>Oe(e,r,t,n))).catch((e=>null==n?void 0:n(u(h.CREATE_OFFER,e))))},Oe=(e,t,n,r)=>{e.setLocalDescription(t).then((()=>n(t.sdp??""))).catch((e=>null==r?void 0:r(u(h.LOCAL_DES,e))))};class Ie extends c{constructor(e){super(),n(this,"config"),n(this,"peerConnection",null),n(this,"localStream",null),n(this,"isPushingStream",!1),n(this,"dataChannel",null),n(this,"statsTimer",null),n(this,"lastReportTime",0),n(this,"lastBytesReceived",0),n(this,"lastPacketsLost",0),n(this,"lastPacketsReceived",0),n(this,"lostPacketCount",0),n(this,"maxLostRate",0),n(this,"decodedCount",0),n(this,"lastSecondDecodedCount",0),this.config=e}async startPush(){if(!this.isPushingStream){this.isPushingStream=!0;try{await this.readyCapture()}catch(e){this.emit(f.webrtcError,u(h.CAMERA,e))}}}handleOffer(e){this.resetPeerConnection(),((e,t,n,r)=>{const i=new RTCSessionDescription({type:"offer",sdp:t});e.setRemoteDescription(i).then((()=>_e(e,n,r))).catch((e=>null==r?void 0:r(u(h.HANDLE_OFFER,e))))})(this.peerConnection,e,(e=>{this.emit(f.sendAnswer,e)}),(e=>this.emit(f.webrtcError,e)))}handleAnswer(e){((e,t,n)=>{const r=new RTCSessionDescription({type:"answer",sdp:t});e.setRemoteDescription(r).catch((e=>null==n?void 0:n(u(h.REMOTE_DES,e))))})(this.peerConnection,e,(e=>this.emit(f.webrtcError,e)))}handleIceCandidate(e){((e,t,n)=>{e.addIceCandidate(t).catch((e=>null==n?void 0:n(u(h.HANDLE_ICE,e))))})(this.peerConnection,e,(e=>this.emit(f.webrtcError,e)))}sendChannelData(e,t){try{let n="";switch(e){case C.ClickData:n=S.click(t);break;case C.ClipboardData:n=S.clipboard(t);break;case C.ActionInput:n=S.input(t);break;case C.ActionChinese:n=S.chinese(t);break;case C.ActionRequestCloudDeviceInfo:n=S.requestCloudDeviceInfo();break;case C.ActionClarity:n=S.clarity(t)}const r=(new TextEncoder).encode(n).buffer;this.dataChannel.send(r)}catch(n){this.emit(f.webrtcError,u(h.DATACHANNEL_ERR,n))}}closeConnection(){this.statsTimer&&(clearInterval(this.statsTimer),this.statsTimer=null),this.peerConnection&&("function"==typeof this.peerConnection.getSenders&&this.peerConnection.getSenders&&this.peerConnection.getSenders().forEach((e=>{var t,n;e.track&&(null==(n=(t=e.track).stop)||n.call(t))})),"function"==typeof this.peerConnection.getReceivers&&this.peerConnection.getReceivers&&this.peerConnection.getReceivers().forEach((e=>{var t,n;e.track&&(null==(n=(t=e.track).stop)||n.call(t))})),this.peerConnection.getTransceivers&&this.peerConnection.getTransceivers().forEach((e=>{var t;null==(t=e.stop)||t.call(e)})),this.removeAllListeners(),this.dataChannel=null,this.peerConnection.onicecandidate=null,this.peerConnection.ontrack=null,this.peerConnection.ondatachannel=null,this.peerConnection.onconnectionstatechange=null,this.peerConnection.oniceconnectionstatechange=null,this.peerConnection.onsignalingstatechange=null,this.peerConnection.onnegotiationneeded=null,this.peerConnection.onicegatheringstatechange=null,this.peerConnection.close(),this.peerConnection=null)}async readyCapture(){this.resetPeerConnection();try{this.localStream=await navigator.mediaDevices.getUserMedia({video:{width:640,height:480},audio:!0});const e=await this.getRotatedStream(this.localStream);e.getTracks().forEach((t=>{t.contentHint="detail",this.peerConnection.addTrack(t,e)})),this.peerConnection.getSenders().forEach((e=>this.setVideoParams(e))),De(this.peerConnection,(e=>{this.emit(f.sendOffer,e)}),(e=>this.emit(f.webrtcError,e)))}catch(e){throw new Error(`mediaDevices error: ${e}`)}}async getRotatedStream(e){const t=document.createElement("canvas"),n=t.getContext("2d"),r=e.getVideoTracks()[0],{width:i,height:o}=await new Promise((e=>{const t=document.createElement("video");t.srcObject=new MediaStream([r]),t.onloadedmetadata=()=>e({width:t.videoWidth,height:t.videoHeight})}));t.width=640,t.height=480;const s=document.createElement("video");s.srcObject=e,await s.play();const a=()=>{n.clearRect(0,0,t.width,t.height),n.save(),n.translate(t.width/2,t.height/2),n.rotate(Math.PI/2),n.drawImage(s,-i/2,-o/2,i,o),n.restore(),requestAnimationFrame(a)};return a(),t.captureStream()}async setVideoParams(e){const t=e.getParameters();t.degradationPreference="maintain-resolution",t.encodings.forEach((e=>{e.maxBitrate=1e6,e.priority="high",e.scaleResolutionDownBy=1})),await e.setParameters(t)}stopPush(){var e;this.isPushingStream&&(this.isPushingStream=!1,null==(e=this.localStream)||e.getTracks().forEach((e=>{var t;null==(t=this.peerConnection)||t.getSenders().forEach((e=>{var t;null==(t=this.peerConnection)||t.removeTrack(e)})),e.stop()})),this.localStream=null,De(this.peerConnection,(e=>{this.emit(f.sendOffer,e)}),(e=>this.emit(f.webrtcError,e))))}resetPeerConnection(){var e,t,n,r,i;this.peerConnection||(this.peerConnection=(e=>{const t={iceServers:[{urls:e.stunServerUri},{urls:e.stunServerUriAli},{urls:e.turnServerUri,username:e.turnServerUserName,credential:e.turnServerPassword}],iceTransportPolicy:"all",sdpSemantics:"unified-plan",rtcpMuxPolicy:"require",bundlePolicy:"max-bundle"};return"chrome"===we.browserDetails.browser&&(t.sdpSemantics=we.browserDetails.version&&we.browserDetails.version<72?"plan-b":"unified-plan"),new(window.RTCPeerConnection||window.mozRTCPeerConnection||window.webkitRTCPeerConnection)(t,{optional:[{DtlsSrtpKeyAgreement:!0},{googIPv6:!0}]})})(this.config),e=this.peerConnection,t=e=>{this.emit(f.sendICEMessage,e)},n=e=>{this.emit(f.streamTrack,e)},r=e=>{this.emit(f.iceConnectionState,e)},i=e=>this.emit(f.webrtcError,e),e.onicecandidate=e=>{if(!e.candidate)return;const n={sdp:e.candidate.candidate,sdpMid:e.candidate.sdpMid,sdpMLineIndex:e.candidate.sdpMLineIndex};t(JSON.stringify(n))},e.oniceconnectionstatechange=()=>{const t=e.iceConnectionState;t&&("failed"===t&&(null==i||i(u(h.ICE_STATE,"failed"))),null==r||r(t))},e.ontrack=e=>{const t=e.track;t.contentHint="detail",null==n||n(t)},this.checkStats(),this.configDataChannel())}configDataChannel(){this.peerConnection.ondatachannel=e=>{this.dataChannel=e.channel,this.dataChannel.onmessage=e=>this.handleDataChannelMessage(e),this.dataChannel.onerror=e=>this.emit(f.webrtcError,u(h.DATACHANNEL_ERR,e)),this.sendChannelData(C.ActionRequestCloudDeviceInfo,"")}}handleDataChannelMessage(e){const t=JSON.parse(e.data);if("ActionCommandEvent"===t.type){const{action:e,value:n}=JSON.parse(t.data);"ACTION_CONTROL_VIDEO"===e&&("ENABLE"===n?this.startPush():this.stopPush())}else if("ActionUpdateCloudStatus"===t.type){const{rotation:e,screenWidth:n,screenHeight:r}=JSON.parse(t.data),i={direction:[g.ROTATION_0,g.ROTATION_180].includes(e)?v.Vertical:v.Horizontal,screenWidth:n,screenHeight:r};this.emit(f.cloudStatusChanged,i)}}checkStats(){this.statsTimer=setInterval((()=>this.processStats()),1e3)}processStats(){this.peerConnection&&this.peerConnection.getStats(null).then((e=>{let t=0,n=0,r=0,i=0,o=0,s=0,a=0,c=0,p="";const d=Date.now();e.forEach((d=>{if("inbound-rtp"===d.type&&(s+=d.bytesReceived||0,i+=d.packetsLost||0,o+=d.packetsReceived||0,"video"===d.kind&&(t=d.framesPerSecond||0,n=d.totalDecodeTime||0,a=d.framesDecoded||0,d.framesReceived,c=(d.pliCount||0)+(d.firCount||0))),"candidate-pair"===d.type&&"succeeded"===d.state){r=void 0!==d.currentRoundTripTime?d.currentRoundTripTime:d.responsesReceived>0?d.totalRoundTripTime/d.responsesReceived:0;const t=e.get(d.localCandidateId),n=e.get(d.remoteCandidateId);t&&n&&(p=this.getConnectionType(t,n))}})),r=Math.floor(1e3*(r||0));const h=d-this.lastReportTime,l=s-this.lastBytesReceived,u=(h>0?1e3*l/h:0)/1024,m=u/1024;this.lastBytesReceived=s,this.lastReportTime=d;let C=0;const y=i-this.lastPacketsLost,g=o-this.lastPacketsReceived;y>0&&g>0&&(C=y/(y+g),this.maxLostRate=Math.max(this.maxLostRate||0,C),this.lostPacketCount++),this.lastPacketsLost=i,this.lastPacketsReceived=o;const v=void 0!==t?t:a-this.lastSecondDecodedCount;this.lastSecondDecodedCount=a;const S=u<1024?`${Math.floor(u)} KB/s`:`${Math.floor(m)} MB/s`,T=a>0?Math.floor(1e4*n/a):0,R={connectionType:p,framesPerSecond:v,currentRoundTripTime:r,lostRate:Math.floor(100*C),
|
|
59
59
|
// percent
|
|
60
60
|
bitrate:S,pliCount:c,averageDecodeTime:T};this.emit(f.statisticInfo,R)})).catch((e=>{this.emit(f.webrtcError,u(h.STREAM_STATE,e))}))}getConnectionType(e,t){return"host"===e.candidateType&&"host"===t.candidateType?"直连":"relay"===e.candidateType||"relay"===t.candidateType?"中继":"NAT"}}const Ae={
|
|
61
61
|
// 数字键
|