yjz-web-sdk 1.0.8-beta.6 → 1.0.8-beta.7

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.
@@ -24,6 +24,7 @@ export interface WebRTCConfigOptions {
24
24
  spareTurn?: Array<string>;
25
25
  maxRecount?: number;
26
26
  isCalculate?: boolean;
27
+ traceId?: string;
27
28
  }
28
29
  export declare class WebRTCConfig {
29
30
  signalServerUrl: string;
@@ -43,5 +44,6 @@ export declare class WebRTCConfig {
43
44
  token: string;
44
45
  isGroup: boolean;
45
46
  turnKey: Array<string>;
47
+ traceId: string;
46
48
  constructor(options: WebRTCConfigOptions);
47
49
  }
@@ -353,6 +353,7 @@ class SignalingClient extends EventEmitter {
353
353
  start() {
354
354
  this.webSocket = new WebSocket(this.config.signalServerUrl);
355
355
  this.webSocket.onopen = () => {
356
+ this.config.traceId = generateRandomString(16);
356
357
  this.sendSignInMessage();
357
358
  if (this.timeout === null) {
358
359
  this.timeout = setTimeout(() => {
@@ -405,6 +406,7 @@ class SignalingClient extends EventEmitter {
405
406
  }
406
407
  sendSignInMessage() {
407
408
  const message = {
409
+ traceId: this.config.traceId,
408
410
  type: SendType.SignIn,
409
411
  identity: SendType.Identity,
410
412
  turnServerUri: this.config.turnServerUri,
@@ -449,6 +451,16 @@ class SignalingClient extends EventEmitter {
449
451
  this.sendMessage(jsonMessage);
450
452
  }
451
453
  }
454
+ function generateRandomString(length) {
455
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
456
+ let result = "";
457
+ const charsLength = chars.length;
458
+ for (let i = 0; i < length; i++) {
459
+ const randomIndex = Math.floor(Math.random() * charsLength);
460
+ result += chars[randomIndex];
461
+ }
462
+ return result;
463
+ }
452
464
  let logDisabled_ = true;
453
465
  let deprecationWarnings_ = true;
454
466
  function extractVersion(uastring, expr, pos) {
@@ -3058,6 +3070,7 @@ class WebRTCConfig {
3058
3070
  __publicField(this, "token");
3059
3071
  __publicField(this, "isGroup");
3060
3072
  __publicField(this, "turnKey");
3073
+ __publicField(this, "traceId", "");
3061
3074
  this.signalServerUrl = options.signalServerUrl || "";
3062
3075
  this.myId = options.myId || "";
3063
3076
  this.roomId = options.roomId || "";
@@ -3075,6 +3088,7 @@ class WebRTCConfig {
3075
3088
  this.screenshotQuality = options.screenshotQuality || 20;
3076
3089
  this.token = options.token;
3077
3090
  this.isGroup = options.isGroup;
3091
+ this.traceId = options.traceId;
3078
3092
  }
3079
3093
  }
3080
3094
  const setRemoteDescriptionWithHandleOffer = (peerConnection, sdp2, sendAnswer, onError) => {
@@ -3797,6 +3811,7 @@ class WebRTCSdk extends EventEmitter {
3797
3811
  }
3798
3812
  break;
3799
3813
  case MessageType.SignOut:
3814
+ console.log("SignOutSignOutSignOutSignOutSignOutSignOutSignOutSignOut");
3800
3815
  if (message.myId === this.config.myId) {
3801
3816
  (_d = this.webRTCClient) == null ? void 0 : _d.closeConnection();
3802
3817
  (_e = this.signalingClient) == null ? void 0 : _e.close();
@@ -3814,6 +3829,7 @@ class WebRTCSdk extends EventEmitter {
3814
3829
  this.emit(EmitType.screenshot, { "room_id": this.config.roomId, "base64": base64Str });
3815
3830
  break;
3816
3831
  case MessageType.KickOut:
3832
+ console.log("KickOuKickOutKickOutKickOutKickOutKickOutKickOutKickOutKickOutKickOutKickOutt");
3817
3833
  this.emit(EmitType.webrtcError, createWebRtcError(FailCode.KICK_OUT_ERR, ""));
3818
3834
  break;
3819
3835
  case MessageType.Error:
@@ -3847,6 +3863,7 @@ class WebRTCSdk extends EventEmitter {
3847
3863
  if (!this.config) return;
3848
3864
  if (answerSdp && answerSdp.length > 0) {
3849
3865
  const message = {
3866
+ traceId: this.config.traceId,
3850
3867
  type: SendType.Answer,
3851
3868
  identity: SendType.Identity,
3852
3869
  roomId: this.config.roomId,
@@ -3863,6 +3880,7 @@ class WebRTCSdk extends EventEmitter {
3863
3880
  if (!this.config) return;
3864
3881
  if (ice && ice.length > 0) {
3865
3882
  const message = {
3883
+ traceId: this.config.traceId,
3866
3884
  type: SendType.IceCandidates,
3867
3885
  identity: SendType.Identity,
3868
3886
  roomId: this.config.roomId,
@@ -7,14 +7,14 @@ r(this,"config"),
7
7
  r(this,"webSocket",null),r(this,"timeout",null),this.config=e}
8
8
  /**
9
9
  * 启动 WebSocket 连接,并注册各事件处理
10
- */start(){this.webSocket=new WebSocket(this.config.signalServerUrl),this.webSocket.onopen=()=>{this.sendSignInMessage(),null===this.timeout&&(this.timeout=setTimeout(()=>{this.emit(m.webrtcError,f(p.STATE_ERR,"")),this.timeout=null},6e3))},this.webSocket.onclose=()=>{this.webSocket=null},this.webSocket.onerror=e=>{this.emit(m.webrtcError,f(p.SOCKET,e))},this.webSocket.onmessage=e=>{const t=JSON.parse(e.data);t.type===l.Offer&&this.timeout&&(clearTimeout(this.timeout),this.timeout=null),this.emit(m.signalMessage,t)}}
10
+ */start(){this.webSocket=new WebSocket(this.config.signalServerUrl),this.webSocket.onopen=()=>{this.config.traceId=function(e){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let n="";const r=t.length;for(let i=0;i<e;i++){n+=t[Math.floor(Math.random()*r)]}return n}(16),this.sendSignInMessage(),null===this.timeout&&(this.timeout=setTimeout(()=>{this.emit(m.webrtcError,f(p.STATE_ERR,"")),this.timeout=null},6e3))},this.webSocket.onclose=()=>{this.webSocket=null},this.webSocket.onerror=e=>{this.emit(m.webrtcError,f(p.SOCKET,e))},this.webSocket.onmessage=e=>{const t=JSON.parse(e.data);t.type===l.Offer&&this.timeout&&(clearTimeout(this.timeout),this.timeout=null),this.emit(m.signalMessage,t)}}
11
11
  /**
12
12
  * 关闭 WebSocket 连接,并通知外部
13
13
  */close(){this.webSocket&&(this.webSocket.onopen=null,this.webSocket.onmessage=null,this.webSocket.onerror=null,this.webSocket.onclose=null,this.webSocket.readyState!==WebSocket.OPEN&&this.webSocket.readyState!==WebSocket.CONNECTING||this.webSocket.close(1e3,"Normal Closure"),this.webSocket=null),this.removeAllListeners()}
14
14
  /**
15
15
  * 发送消息到服务端
16
16
  * @param message - 消息字符串
17
- */sendMessage(e){this.webSocket&&this.webSocket.readyState===WebSocket.OPEN&&this.webSocket.send(e)}sendSignInMessage(){const e={type:h.SignIn,identity:h.Identity,turnServerUri:this.config.turnServerUri,roomId:this.config.roomId,isControl:this.config.isControl?"true":"false",screenshotWidth:this.config.screenshotWidth,screenshotHeight:this.config.screenshotHeight,screenshotQuality:this.config.screenshotQuality,token:this.config.token,isGroup:this.config.isGroup,turnKey:this.config.turnKey},t=JSON.stringify(e);this.sendMessage(t)}sendSwitchControlMessage(e){this.config.isControl=e;const t={type:h.SwitchControl,identity:h.Identity,isControl:this.config.isControl?"true":"false",roomId:this.config.roomId,screenshotWidth:this.config.screenshotWidth,screenshotHeight:this.config.screenshotHeight,screenshotQuality:this.config.screenshotQuality},n=JSON.stringify(t);this.sendMessage(n)}
17
+ */sendMessage(e){this.webSocket&&this.webSocket.readyState===WebSocket.OPEN&&this.webSocket.send(e)}sendSignInMessage(){const e={traceId:this.config.traceId,type:h.SignIn,identity:h.Identity,turnServerUri:this.config.turnServerUri,roomId:this.config.roomId,isControl:this.config.isControl?"true":"false",screenshotWidth:this.config.screenshotWidth,screenshotHeight:this.config.screenshotHeight,screenshotQuality:this.config.screenshotQuality,token:this.config.token,isGroup:this.config.isGroup,turnKey:this.config.turnKey},t=JSON.stringify(e);this.sendMessage(t)}sendSwitchControlMessage(e){this.config.isControl=e;const t={type:h.SwitchControl,identity:h.Identity,isControl:this.config.isControl?"true":"false",roomId:this.config.roomId,screenshotWidth:this.config.screenshotWidth,screenshotHeight:this.config.screenshotHeight,screenshotQuality:this.config.screenshotQuality},n=JSON.stringify(t);this.sendMessage(n)}
18
18
  /**
19
19
  * 用于从控请求当前截屏
20
20
  * @param visible 当前从控page控件是否可见
@@ -31,7 +31,7 @@ type:t[7]};for(let r=8;r<t.length;r+=2)switch(t[r]){case"raddr":n.relatedAddress
31
31
  // algorithm is case-sensitive in Edge.
32
32
  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 d=t.matchPrefix(e,"a=ssrc-group:FID").map(e=>e.substring(17).split(" ").map(e=>parseInt(e,10)));d.length>0&&d[0].length>1&&d[0][0]===a&&(c=d[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 l=t.matchPrefix(e,"b=");return l.length&&(l=0===l[0].indexOf("b=TIAS:")?parseInt(l[0].substring(7),10):0===l[0].indexOf("b=AS:")?1e3*parseInt(l[0].substring(5),10)*.95-16e3:void 0,n.forEach(e=>{e.maxBitrate=l})),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}(de)),de.exports);const he=o(le),pe=i({__proto__:null,default:he},[le]);function ue(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=he.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,T(e,"icecandidate",t=>(t.candidate&&Object.defineProperty(t,"candidate",{value:new e.RTCIceCandidate(t.candidate),writable:"false"}),t))}function fe(e){!e.RTCIceCandidate||e.RTCIceCandidate&&"relayProtocol"in e.RTCIceCandidate.prototype||T(e,"icecandidate",e=>{if(e.candidate){const t=he.parseCandidate(e.candidate.candidate);"relay"===t.type&&(e.candidate.relayProtocol={0:"tls",1:"tcp",2:"udp"}[t.priority>>24])}return e})}function me(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=he.splitSections(e.sdp);return t.shift(),t.some(e=>{const t=he.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=he.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 Ce(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},T(e,"datachannel",e=>(t(e.channel,e.target),e))}function ge(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 ye(e,t){if(!e.RTCPeerConnection)return;if("chrome"===t.browser&&t.version>=71)return;if("safari"===t.browser&&t._safariVersion>=13.1)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 ve(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 Te(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 Se=Object.freeze(Object.defineProperty({__proto__:null,removeExtmapAllowMixed:ye,shimAddIceCandidateNullOrEmpty:ve,shimConnectionState:ge,shimMaxMessageSize:me,shimParameterlessSetLocalDescription:Te,shimRTCIceCandidate:ue,shimRTCIceCandidateRelayProtocol:fe,shimSendThrowTypeError:Ce},Symbol.toStringTag,{value:"Module"}));!function({window:e}={},t={shimChrome:!0,shimFirefox:!0,shimSafari:!0}){const n=b,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=parseInt(v(n.userAgent,/Firefox\/(\d+)\./,1));else if(n.webkitGetUserMedia||!1===e.isSecureContext&&e.webkitRTCPeerConnection)t.browser="chrome",t.version=parseInt(v(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=parseInt(v(n.userAgent,/AppleWebKit\/(\d+)\./,1)),t.supportsUnifiedPlan=e.RTCRtpTransceiver&&"currentDirection"in e.RTCRtpTransceiver.prototype,t._safariVersion=v(n.userAgent,/Version\/(\d+(\.?\d+))/,1)}return t}(e),i={browserDetails:r,commonShim:Se,extractVersion:v,disableLog:S,disableWarnings:R,
33
33
  // Expose sdp as a convenience. For production apps include directly.
34
- sdp:pe};switch(r.browser){case"chrome":if(!F||!j||!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=F,ve(e,r),Te(e),A(e,r),I(e),j(e,r),D(e),N(e,r),M(e),x(e),U(e,r),ue(e),fe(e),ge(e),me(e,r),Ce(e),ye(e,r);break;case"firefox":if(!X||!V||!t.shimFirefox)return n("Firefox shim is not included in this adapter release."),i;n("adapter.js shimming firefox."),i.browserShim=X,ve(e,r),Te(e),K(e,r),V(e,r),z(e),G(e),W(e),B(e),H(e),J(e),q(e),Q(e),$(e),ue(e),ge(e),me(e,r),Ce(e);break;case"safari":if(!ae||!t.shimSafari)return n("Safari shim is not included in this adapter release."),i;n("adapter.js shimming safari."),i.browserShim=ae,ve(e,r),Te(e),re(e),oe(e),ee(e),Y(e),Z(e),ie(e),te(e),se(e),ue(e),fe(e),me(e,r),Ce(e),ye(e,r);break;default:n("Unsupported browser!")}}({window:"undefined"==typeof window?void 0:window});class Re{constructor(e){r(this,"signalServerUrl"),r(this,"myId"),r(this,"roomId"),r(this,"targetId"),r(this,"stunServerUri"),r(this,"stunServerUriAli"),r(this,"stunServerUriTel"),r(this,"turnServerUri"),r(this,"turnServerUserName"),r(this,"turnServerPassword"),r(this,"isControl"),r(this,"screenshotWidth"),r(this,"screenshotHeight"),r(this,"screenshotQuality"),r(this,"token"),r(this,"isGroup"),r(this,"turnKey"),this.signalServerUrl=e.signalServerUrl||"",this.myId=e.myId||"",this.roomId=e.roomId||"",this.targetId=e.targetId||"",this.turnKey=e.turnKey||[],this.stunServerUri=e.stunServerUri||"stun:stun.l.google.com:19302",this.stunServerUriAli=e.stunServerUriAli||"stun:stun.middle.aliyun.com:3478",this.stunServerUriTel=e.stunServerUriTel||"stun:stun.qq.com:3478",this.turnServerUri=e.turnServerUri||"turn:121.37.25.106:3478",this.turnServerUserName=e.turnServerUserName||"yangyj",this.turnServerPassword=e.turnServerPassword||"hb@2025@168",this.isControl=e.isControl??!0,this.screenshotWidth=e.screenshotWidth||144,this.screenshotHeight=e.screenshotHeight||256,this.screenshotQuality=e.screenshotQuality||20,this.token=e.token,this.isGroup=e.isGroup}}const be=(e,t,n)=>{e.createAnswer().then(r=>we(e,r,t,n)).catch(e=>null==n?void 0:n(f(p.CREATE_ANSWER,e)))},we=(e,t,n,r)=>{e.setLocalDescription(t).then(()=>{null==n||n(t.sdp??"")}).catch(e=>{null==r||r(f(p.LOCAL_DES,e))})},Ee=(e,t,n)=>{e.createOffer().then(r=>Pe(e,r,t,n)).catch(e=>null==n?void 0:n(f(p.CREATE_OFFER,e)))},Pe=(e,t,n,r)=>{e.setLocalDescription(t).then(()=>n(t.sdp??"")).catch(e=>null==r?void 0:r(f(p.LOCAL_DES,e)))};var ke=(e=>(e.ClickData="ClickData",e.ClipboardData="ClipboardData",e.ActionCommand="ActionCommand",e.ActionInput="ActionInput",e.ActionChinese="ActionChinese",e.ActionRequestCloudDeviceInfo="ActionRequestCloudDeviceInfo",e.ActionClarity="ActionClarity",e.ActionWheel="ActionWheel",e.CloudClipData="CloudClipData",e.ActionCommandEvent="ActionCommandEvent",e.ActionUpdateCloudStatus="ActionUpdateCloudStatus",e.ActionGesture="ActionGesture",e.ActionTrack="ActionTrack",e))(ke||{}),_e=(e=>(e.ENABLE="ENABLE",e.DISABLE="DISABLE",e))(_e||{}),Oe=(e=>(e.ActionBack="ActionBack",e.ActionHome="ActionHome",e.ActionRecent="ActionRecent",e.ActionSwitchNavButtons="ActionSwitchNavButtons",e.ActionSwitchNavGestural="ActionSwitchNavGestural",e))(Oe||{}),Ae=(e=>(e.ACTION_CONTROL_VIDEO_AND_AUDIO="ACTION_CONTROL_VIDEO_AND_AUDIO",e.ACTION_CONTROL_VIDEO="ACTION_CONTROL_VIDEO",e.ACTION_CONTROL_AUDIO="ACTION_CONTROL_AUDIO",e))(Ae||{});const Ie={ACTION_DOWN:0,ACTION_MOVE:2,ACTION_UP:1},De={ROTATION_0:0,ROTATION_180:2},Me={Vertical:0,Horizontal:1};class xe{constructor(e,t,n,i,o,s="adb"){r(this,"action"),r(this,"p"),r(this,"x"),r(this,"y"),r(this,"offsetTime"),r(this,"type"),this.action=e,this.p=t,this.x=n,this.y=i,this.offsetTime=o,this.type=s}}class Le{constructor(e){r(this,"axis"),this.axis=e}}class Ne{constructor(e,t){r(this,"keyCode"),r(this,"meta"),this.keyCode=e,this.meta=t}}class je{constructor(e,t=null,n=null){r(this,"type"),r(this,"data"),r(this,"myId"),this.type=e,this.data=t,this.myId=n}toString(){return JSON.stringify({type:this.type,data:this.data,myId:this.myId})}
34
+ sdp:pe};switch(r.browser){case"chrome":if(!F||!j||!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=F,ve(e,r),Te(e),A(e,r),I(e),j(e,r),D(e),N(e,r),M(e),x(e),U(e,r),ue(e),fe(e),ge(e),me(e,r),Ce(e),ye(e,r);break;case"firefox":if(!X||!V||!t.shimFirefox)return n("Firefox shim is not included in this adapter release."),i;n("adapter.js shimming firefox."),i.browserShim=X,ve(e,r),Te(e),K(e,r),V(e,r),z(e),G(e),W(e),B(e),H(e),J(e),q(e),Q(e),$(e),ue(e),ge(e),me(e,r),Ce(e);break;case"safari":if(!ae||!t.shimSafari)return n("Safari shim is not included in this adapter release."),i;n("adapter.js shimming safari."),i.browserShim=ae,ve(e,r),Te(e),re(e),oe(e),ee(e),Y(e),Z(e),ie(e),te(e),se(e),ue(e),fe(e),me(e,r),Ce(e),ye(e,r);break;default:n("Unsupported browser!")}}({window:"undefined"==typeof window?void 0:window});class Re{constructor(e){r(this,"signalServerUrl"),r(this,"myId"),r(this,"roomId"),r(this,"targetId"),r(this,"stunServerUri"),r(this,"stunServerUriAli"),r(this,"stunServerUriTel"),r(this,"turnServerUri"),r(this,"turnServerUserName"),r(this,"turnServerPassword"),r(this,"isControl"),r(this,"screenshotWidth"),r(this,"screenshotHeight"),r(this,"screenshotQuality"),r(this,"token"),r(this,"isGroup"),r(this,"turnKey"),r(this,"traceId",""),this.signalServerUrl=e.signalServerUrl||"",this.myId=e.myId||"",this.roomId=e.roomId||"",this.targetId=e.targetId||"",this.turnKey=e.turnKey||[],this.stunServerUri=e.stunServerUri||"stun:stun.l.google.com:19302",this.stunServerUriAli=e.stunServerUriAli||"stun:stun.middle.aliyun.com:3478",this.stunServerUriTel=e.stunServerUriTel||"stun:stun.qq.com:3478",this.turnServerUri=e.turnServerUri||"turn:121.37.25.106:3478",this.turnServerUserName=e.turnServerUserName||"yangyj",this.turnServerPassword=e.turnServerPassword||"hb@2025@168",this.isControl=e.isControl??!0,this.screenshotWidth=e.screenshotWidth||144,this.screenshotHeight=e.screenshotHeight||256,this.screenshotQuality=e.screenshotQuality||20,this.token=e.token,this.isGroup=e.isGroup,this.traceId=e.traceId}}const be=(e,t,n)=>{e.createAnswer().then(r=>we(e,r,t,n)).catch(e=>null==n?void 0:n(f(p.CREATE_ANSWER,e)))},we=(e,t,n,r)=>{e.setLocalDescription(t).then(()=>{null==n||n(t.sdp??"")}).catch(e=>{null==r||r(f(p.LOCAL_DES,e))})},Ee=(e,t,n)=>{e.createOffer().then(r=>Pe(e,r,t,n)).catch(e=>null==n?void 0:n(f(p.CREATE_OFFER,e)))},Pe=(e,t,n,r)=>{e.setLocalDescription(t).then(()=>n(t.sdp??"")).catch(e=>null==r?void 0:r(f(p.LOCAL_DES,e)))};var ke=(e=>(e.ClickData="ClickData",e.ClipboardData="ClipboardData",e.ActionCommand="ActionCommand",e.ActionInput="ActionInput",e.ActionChinese="ActionChinese",e.ActionRequestCloudDeviceInfo="ActionRequestCloudDeviceInfo",e.ActionClarity="ActionClarity",e.ActionWheel="ActionWheel",e.CloudClipData="CloudClipData",e.ActionCommandEvent="ActionCommandEvent",e.ActionUpdateCloudStatus="ActionUpdateCloudStatus",e.ActionGesture="ActionGesture",e.ActionTrack="ActionTrack",e))(ke||{}),_e=(e=>(e.ENABLE="ENABLE",e.DISABLE="DISABLE",e))(_e||{}),Oe=(e=>(e.ActionBack="ActionBack",e.ActionHome="ActionHome",e.ActionRecent="ActionRecent",e.ActionSwitchNavButtons="ActionSwitchNavButtons",e.ActionSwitchNavGestural="ActionSwitchNavGestural",e))(Oe||{}),Ae=(e=>(e.ACTION_CONTROL_VIDEO_AND_AUDIO="ACTION_CONTROL_VIDEO_AND_AUDIO",e.ACTION_CONTROL_VIDEO="ACTION_CONTROL_VIDEO",e.ACTION_CONTROL_AUDIO="ACTION_CONTROL_AUDIO",e))(Ae||{});const Ie={ACTION_DOWN:0,ACTION_MOVE:2,ACTION_UP:1},De={ROTATION_0:0,ROTATION_180:2},Me={Vertical:0,Horizontal:1};class xe{constructor(e,t,n,i,o,s="adb"){r(this,"action"),r(this,"p"),r(this,"x"),r(this,"y"),r(this,"offsetTime"),r(this,"type"),this.action=e,this.p=t,this.x=n,this.y=i,this.offsetTime=o,this.type=s}}class Le{constructor(e){r(this,"axis"),this.axis=e}}class Ne{constructor(e,t){r(this,"keyCode"),r(this,"meta"),this.keyCode=e,this.meta=t}}class je{constructor(e,t=null,n=null){r(this,"type"),r(this,"data"),r(this,"myId"),this.type=e,this.data=t,this.myId=n}toString(){return JSON.stringify({type:this.type,data:this.data,myId:this.myId})}
35
35
  /**
36
36
  * 格式化数据
37
37
  * 如果数据已经是字符串,则直接返回;否则使用 JSON.stringify() 转换为字符串
@@ -79,9 +79,9 @@ r(this,"handleSignaling",e=>{var t,n,r,i,o;if(this.config)switch(e.type){case l.
79
79
  /** 发送 Offer 信令 */
80
80
  r(this,"sendOffer",e=>{var t;if(this.config&&e&&e.length>0){const n={type:h.Offer,identity:h.Identity,roomId:this.config.roomId,senderId:this.config.myId,targetId:this.config.targetId,sdp:e};null==(t=this.signalingClient)||t.sendMessage(JSON.stringify(n))}}),
81
81
  /** 发送 Answer 信令 */
82
- r(this,"sendAnswer",e=>{var t;if(this.config&&e&&e.length>0){const n={type:h.Answer,identity:h.Identity,roomId:this.config.roomId,senderId:this.config.myId,targetId:this.config.targetId,sdp:e};null==(t=this.signalingClient)||t.sendMessage(JSON.stringify(n))}}),
82
+ r(this,"sendAnswer",e=>{var t;if(this.config&&e&&e.length>0){const n={traceId:this.config.traceId,type:h.Answer,identity:h.Identity,roomId:this.config.roomId,senderId:this.config.myId,targetId:this.config.targetId,sdp:e};null==(t=this.signalingClient)||t.sendMessage(JSON.stringify(n))}}),
83
83
  /** 发送 ICE 候选信息 */
84
- r(this,"sendICEMessage",e=>{var t;if(this.config&&e&&e.length>0){const n={type:h.IceCandidates,identity:h.Identity,roomId:this.config.roomId,senderId:this.config.myId,targetId:this.config.targetId,ice:e};null==(t=this.signalingClient)||t.sendMessage(JSON.stringify(n))}}),this.options=e,this.options.maxRecount&&(this.MAX_COUNT=this.options.maxRecount)}async initConfig(){var e,t;if(!this.options||0===Object.keys(this.options).length)throw f(p.OPTION_ERR,"option null");if(ze(this.options))throw f(p.OPTION_ERR,"中继配置为空");const n=async(e,t)=>{if(0===e.length)return!1;try{const n=await(async e=>{var t,n;try{const r=await Fe(e);return{url:null==(t=r.best)?void 0:t.urls,rtt:null==(n=r.best)?void 0:n.rtt}}catch(r){return{error:r.message||"未知错误"}}})(e);return!(!n.url||"number"!=typeof n.rtt)&&(!(t&&n.rtt>140)&&(this.options.turnServerUri=n.url,this.options.turnKey=[n.url],!0))}catch(n){return!1}},r=!!(null==(e=this.options.hostTurn)?void 0:e.length)&&await n(this.options.hostTurn,!0);if(!r&&(null==(t=this.options.spareTurn)?void 0:t.length)){const e=(this.options.hostTurn??[]).concat(this.options.spareTurn??[]);if(!(await n(e,!1))){if(!this.options.turnServerUri)throw f(p.OPTION_ERR,"暂无可用TURN服务器");this.options.turnKey=[this.options.turnServerUri]}}else if(!r){if(!(await n(this.options.hostTurn??[],!1))){if(!this.options.turnServerUri)throw f(p.OPTION_ERR,"暂无可用TURN服务器");this.options.turnKey=[this.options.turnServerUri]}}}
84
+ r(this,"sendICEMessage",e=>{var t;if(this.config&&e&&e.length>0){const n={traceId:this.config.traceId,type:h.IceCandidates,identity:h.Identity,roomId:this.config.roomId,senderId:this.config.myId,targetId:this.config.targetId,ice:e};null==(t=this.signalingClient)||t.sendMessage(JSON.stringify(n))}}),this.options=e,this.options.maxRecount&&(this.MAX_COUNT=this.options.maxRecount)}async initConfig(){var e,t;if(!this.options||0===Object.keys(this.options).length)throw f(p.OPTION_ERR,"option null");if(ze(this.options))throw f(p.OPTION_ERR,"中继配置为空");const n=async(e,t)=>{if(0===e.length)return!1;try{const n=await(async e=>{var t,n;try{const r=await Fe(e);return{url:null==(t=r.best)?void 0:t.urls,rtt:null==(n=r.best)?void 0:n.rtt}}catch(r){return{error:r.message||"未知错误"}}})(e);return!(!n.url||"number"!=typeof n.rtt)&&(!(t&&n.rtt>140)&&(this.options.turnServerUri=n.url,this.options.turnKey=[n.url],!0))}catch(n){return!1}},r=!!(null==(e=this.options.hostTurn)?void 0:e.length)&&await n(this.options.hostTurn,!0);if(!r&&(null==(t=this.options.spareTurn)?void 0:t.length)){const e=(this.options.hostTurn??[]).concat(this.options.spareTurn??[]);if(!(await n(e,!1))){if(!this.options.turnServerUri)throw f(p.OPTION_ERR,"暂无可用TURN服务器");this.options.turnKey=[this.options.turnServerUri]}}else if(!r){if(!(await n(this.options.hostTurn??[],!1))){if(!this.options.turnServerUri)throw f(p.OPTION_ERR,"暂无可用TURN服务器");this.options.turnKey=[this.options.turnServerUri]}}}
85
85
  /** 开始连接 signal 服务 */startConnection(){this.prepareConnection().catch(e=>{this.emit(m.webrtcError,e)})}async prepareConnection(){var e;if(!this.isConnecting){this.isConnecting=!0;try{if(ze(this.options)){if(!this.options.turnServerUri)return void this.emit(m.webrtcError,f(p.OPTION_ERR,"暂无可用TURN服务器"))}else await this.initConfig();this.initConnectConfig(),null==(e=this.signalingClient)||e.start()}catch(t){throw this.isConnected=!1,t}finally{this.isConnecting=!1}}}async reconnect(){this.resetConfig();try{await this.prepareConnection()}catch(e){this.emit(m.webrtcError,e)}}initConnectConfig(){this.config=new Re(this.options),this.signalingClient=new C(this.config),this.webRTCClient=new Ue(this.config),this.signalingClient.on(m.signalMessage,e=>this.handleSignaling(e)),this.signalingClient.on(m.webrtcError,e=>{this.emit(m.webrtcError,e)}),this.webRTCClient.on(m.sendOffer,e=>this.sendOffer(e)),this.webRTCClient.on(m.sendAnswer,e=>this.sendAnswer(e)),this.webRTCClient.on(m.sendICEMessage,e=>this.sendICEMessage(e)),this.webRTCClient.on(m.streamTrack,e=>{this.emit(m.streamTrack,e)}),this.webRTCClient.on(m.iceConnectionState,e=>{this.emit(m.iceConnectionState,e),"connected"===e&&(this.isConnected=!0)}),this.webRTCClient.on(m.cloudStatusChanged,e=>this.emit(m.cloudStatusChanged,e)),this.webRTCClient.on(m.cloudClipData,e=>this.emit(m.cloudClipData,e)),this.webRTCClient.on(m.webrtcError,e=>{this.emit(m.webrtcError,e)}),this.webRTCClient.on(m.statisticInfo,e=>{this.emit(m.statisticInfo,e)})}switchControl(e){var t;null==(t=this.signalingClient)||t.sendSwitchControlMessage(e)}resetConfig(){var e,t;this.sendSignOut(),null==(e=this.signalingClient)||e.close(),null==(t=this.webRTCClient)||t.closeConnection(),this.signalingClient=null,this.webRTCClient=null,this.config=null,this.isConnected=!1,this.isConnecting=!1}
86
86
  /** 停止连接,并发送退出信令 */stop(){var e,t;this.sendSignOut(),null==(e=this.signalingClient)||e.close(),null==(t=this.webRTCClient)||t.closeConnection(),this.removeAllListeners(),this.signalingClient=null,this.webRTCClient=null,this.config=null,this.connectCount=0,this.isConnected=!1,this.isConnecting=!1}
87
87
  /** 开始推流:触发媒体采集与轨道添加 */async startPush(){}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "yjz-web-sdk",
3
3
  "private": false,
4
- "version": "1.0.8-beta.6",
4
+ "version": "1.0.8-beta.7",
5
5
  "type": "module",
6
6
  "description": "针对于亚矩阵项目的云手机投屏和屏幕控制",
7
7
  "license": "Apache-2.0",
@@ -32,6 +32,7 @@
32
32
  "preview": "vite preview"
33
33
  },
34
34
  "dependencies": {
35
+ "element-plus": "^2.10.5",
35
36
  "eventemitter3": "^5.0.1",
36
37
  "terser": "^5.39.0",
37
38
  "vue": "^3.5.13",