Files
gd_water_websdk/hs-web3d-core/dist/index.js
2026-02-23 16:25:54 +08:00

3 lines
14 KiB
JavaScript

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).UscRtc={})}(this,(function(e){"use strict";let t;const n=new Uint8Array(16);function s(){if(!t&&(t="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!t))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return t(n)}var r=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;const o=[];for(let e=0;e<256;++e)o.push((e+256).toString(16).slice(1));function a(e,t=0){return(o[e[t+0]]+o[e[t+1]]+o[e[t+2]]+o[e[t+3]]+"-"+o[e[t+4]]+o[e[t+5]]+"-"+o[e[t+6]]+o[e[t+7]]+"-"+o[e[t+8]]+o[e[t+9]]+"-"+o[e[t+10]]+o[e[t+11]]+o[e[t+12]]+o[e[t+13]]+o[e[t+14]]+o[e[t+15]]).toLowerCase()}function i(e){if(!function(e){return"string"==typeof e&&r.test(e)}(e))throw TypeError("Invalid UUID");let t;const n=new Uint8Array(16);return n[0]=(t=parseInt(e.slice(0,8),16))>>>24,n[1]=t>>>16&255,n[2]=t>>>8&255,n[3]=255&t,n[4]=(t=parseInt(e.slice(9,13),16))>>>8,n[5]=255&t,n[6]=(t=parseInt(e.slice(14,18),16))>>>8,n[7]=255&t,n[8]=(t=parseInt(e.slice(19,23),16))>>>8,n[9]=255&t,n[10]=(t=parseInt(e.slice(24,36),16))/1099511627776&255,n[11]=t/4294967296&255,n[12]=t>>>24&255,n[13]=t>>>16&255,n[14]=t>>>8&255,n[15]=255&t,n}const c="6ba7b810-9dad-11d1-80b4-00c04fd430c8",l="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function d(e,t,n){function s(e,s,r,o){var c;if("string"==typeof e&&(e=function(e){e=unescape(encodeURIComponent(e));const t=[];for(let n=0;n<e.length;++n)t.push(e.charCodeAt(n));return t}(e)),"string"==typeof s&&(s=i(s)),16!==(null===(c=s)||void 0===c?void 0:c.length))throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let l=new Uint8Array(16+e.length);if(l.set(s),l.set(e,s.length),l=n(l),l[6]=15&l[6]|t,l[8]=63&l[8]|128,r){o=o||0;for(let e=0;e<16;++e)r[o+e]=l[e];return r}return a(l)}try{s.name=e}catch(e){}return s.DNS=c,s.URL=l,s}function h(e){return 14+(e+64>>>9<<4)+1}function p(e,t){const n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n}function u(e,t,n,s,r,o){return p((a=p(p(t,e),p(s,o)))<<(i=r)|a>>>32-i,n);var a,i}function y(e,t,n,s,r,o,a){return u(t&n|~t&s,e,t,r,o,a)}function f(e,t,n,s,r,o,a){return u(t&s|n&~s,e,t,r,o,a)}function k(e,t,n,s,r,o,a){return u(t^n^s,e,t,r,o,a)}function g(e,t,n,s,r,o,a){return u(n^(t|~s),e,t,r,o,a)}d("v3",48,(function(e){if("string"==typeof e){const t=unescape(encodeURIComponent(e));e=new Uint8Array(t.length);for(let n=0;n<t.length;++n)e[n]=t.charCodeAt(n)}return function(e){const t=[],n=32*e.length,s="0123456789abcdef";for(let r=0;r<n;r+=8){const n=e[r>>5]>>>r%32&255,o=parseInt(s.charAt(n>>>4&15)+s.charAt(15&n),16);t.push(o)}return t}(function(e,t){e[t>>5]|=128<<t%32,e[h(t)-1]=t;let n=1732584193,s=-271733879,r=-1732584194,o=271733878;for(let t=0;t<e.length;t+=16){const a=n,i=s,c=r,l=o;n=y(n,s,r,o,e[t],7,-680876936),o=y(o,n,s,r,e[t+1],12,-389564586),r=y(r,o,n,s,e[t+2],17,606105819),s=y(s,r,o,n,e[t+3],22,-1044525330),n=y(n,s,r,o,e[t+4],7,-176418897),o=y(o,n,s,r,e[t+5],12,1200080426),r=y(r,o,n,s,e[t+6],17,-1473231341),s=y(s,r,o,n,e[t+7],22,-45705983),n=y(n,s,r,o,e[t+8],7,1770035416),o=y(o,n,s,r,e[t+9],12,-1958414417),r=y(r,o,n,s,e[t+10],17,-42063),s=y(s,r,o,n,e[t+11],22,-1990404162),n=y(n,s,r,o,e[t+12],7,1804603682),o=y(o,n,s,r,e[t+13],12,-40341101),r=y(r,o,n,s,e[t+14],17,-1502002290),s=y(s,r,o,n,e[t+15],22,1236535329),n=f(n,s,r,o,e[t+1],5,-165796510),o=f(o,n,s,r,e[t+6],9,-1069501632),r=f(r,o,n,s,e[t+11],14,643717713),s=f(s,r,o,n,e[t],20,-373897302),n=f(n,s,r,o,e[t+5],5,-701558691),o=f(o,n,s,r,e[t+10],9,38016083),r=f(r,o,n,s,e[t+15],14,-660478335),s=f(s,r,o,n,e[t+4],20,-405537848),n=f(n,s,r,o,e[t+9],5,568446438),o=f(o,n,s,r,e[t+14],9,-1019803690),r=f(r,o,n,s,e[t+3],14,-187363961),s=f(s,r,o,n,e[t+8],20,1163531501),n=f(n,s,r,o,e[t+13],5,-1444681467),o=f(o,n,s,r,e[t+2],9,-51403784),r=f(r,o,n,s,e[t+7],14,1735328473),s=f(s,r,o,n,e[t+12],20,-1926607734),n=k(n,s,r,o,e[t+5],4,-378558),o=k(o,n,s,r,e[t+8],11,-2022574463),r=k(r,o,n,s,e[t+11],16,1839030562),s=k(s,r,o,n,e[t+14],23,-35309556),n=k(n,s,r,o,e[t+1],4,-1530992060),o=k(o,n,s,r,e[t+4],11,1272893353),r=k(r,o,n,s,e[t+7],16,-155497632),s=k(s,r,o,n,e[t+10],23,-1094730640),n=k(n,s,r,o,e[t+13],4,681279174),o=k(o,n,s,r,e[t],11,-358537222),r=k(r,o,n,s,e[t+3],16,-722521979),s=k(s,r,o,n,e[t+6],23,76029189),n=k(n,s,r,o,e[t+9],4,-640364487),o=k(o,n,s,r,e[t+12],11,-421815835),r=k(r,o,n,s,e[t+15],16,530742520),s=k(s,r,o,n,e[t+2],23,-995338651),n=g(n,s,r,o,e[t],6,-198630844),o=g(o,n,s,r,e[t+7],10,1126891415),r=g(r,o,n,s,e[t+14],15,-1416354905),s=g(s,r,o,n,e[t+5],21,-57434055),n=g(n,s,r,o,e[t+12],6,1700485571),o=g(o,n,s,r,e[t+3],10,-1894986606),r=g(r,o,n,s,e[t+10],15,-1051523),s=g(s,r,o,n,e[t+1],21,-2054922799),n=g(n,s,r,o,e[t+8],6,1873313359),o=g(o,n,s,r,e[t+15],10,-30611744),r=g(r,o,n,s,e[t+6],15,-1560198380),s=g(s,r,o,n,e[t+13],21,1309151649),n=g(n,s,r,o,e[t+4],6,-145523070),o=g(o,n,s,r,e[t+11],10,-1120210379),r=g(r,o,n,s,e[t+2],15,718787259),s=g(s,r,o,n,e[t+9],21,-343485551),n=p(n,a),s=p(s,i),r=p(r,c),o=p(o,l)}return[n,s,r,o]}(function(e){if(0===e.length)return[];const t=8*e.length,n=new Uint32Array(h(t));for(let s=0;s<t;s+=8)n[s>>5]|=(255&e[s/8])<<s%32;return n}(e),8*e.length))}));var I={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function m(e,t,n){if(I.randomUUID&&!t&&!e)return I.randomUUID();const r=(e=e||{}).random||(e.rng||s)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=r[e];return t}return a(r)}function v(e,t,n,s){switch(e){case 0:return t&n^~t&s;case 1:case 3:return t^n^s;case 2:return t&n^t&s^n&s}}function b(e,t){return e<<t|e>>>32-t}d("v5",80,(function(e){const t=[1518500249,1859775393,2400959708,3395469782],n=[1732584193,4023233417,2562383102,271733878,3285377520];if("string"==typeof e){const t=unescape(encodeURIComponent(e));e=[];for(let n=0;n<t.length;++n)e.push(t.charCodeAt(n))}else Array.isArray(e)||(e=Array.prototype.slice.call(e));e.push(128);const s=e.length/4+2,r=Math.ceil(s/16),o=new Array(r);for(let t=0;t<r;++t){const n=new Uint32Array(16);for(let s=0;s<16;++s)n[s]=e[64*t+4*s]<<24|e[64*t+4*s+1]<<16|e[64*t+4*s+2]<<8|e[64*t+4*s+3];o[t]=n}o[r-1][14]=8*(e.length-1)/Math.pow(2,32),o[r-1][14]=Math.floor(o[r-1][14]),o[r-1][15]=8*(e.length-1)&4294967295;for(let e=0;e<r;++e){const s=new Uint32Array(80);for(let t=0;t<16;++t)s[t]=o[e][t];for(let e=16;e<80;++e)s[e]=b(s[e-3]^s[e-8]^s[e-14]^s[e-16],1);let r=n[0],a=n[1],i=n[2],c=n[3],l=n[4];for(let e=0;e<80;++e){const n=Math.floor(e/20),o=b(r,5)+v(n,a,i,c)+l+t[n]+s[e]>>>0;l=c,c=i,i=b(a,30)>>>0,a=r,r=o}n[0]=n[0]+r>>>0,n[1]=n[1]+a>>>0,n[2]=n[2]+i>>>0,n[3]=n[3]+c>>>0,n[4]=n[4]+l>>>0}return[n[0]>>24&255,n[0]>>16&255,n[0]>>8&255,255&n[0],n[1]>>24&255,n[1]>>16&255,n[1]>>8&255,255&n[1],n[2]>>24&255,n[2]>>16&255,n[2]>>8&255,255&n[2],n[3]>>24&255,n[3]>>16&255,n[3]>>8&255,255&n[3],n[4]>>24&255,n[4]>>16&255,n[4]>>8&255,255&n[4]]}));class T{constructor(e,t){this.socket=null,this.reconnectCount=0,this.delay=null,this.timer=null;const{autoReconnect:n=!0,query:s={},heartbeat:r=!0,appId:o,clientId:a,sessionId:i}=t||{};this.autoReconnect=n,this.heartbeat=r,this.appId=o,this.clientId=a,this.sessionId=i,this.query=s,this.url=e||"ws://test/api"+JSON.stringify(Object.assign({token:""},this.query)),console.log("==============Web3DCore constructor",(new Date).getTime())}static getInstance(e,t){return this.instance||(this.instance=new T(e,t),this.instance.connect()),this.instance}connect(){this.close(),this.socket=new WebSocket(this.url),this.onError(),this.onOpen()}onOpen(){this.socket&&(this.socket.onopen=()=>{this.login(),this.send("ping"),this.heartbeat&&this.startHeartbeat()})}startHeartbeat(){var e,t;const n=(null===(e=this.heartbeat)||void 0===e?void 0:e.message)||"ping",s=(null===(t=this.heartbeat)||void 0===t?void 0:t.interval)||1e7;this.timer=setInterval((()=>{this.send(n)}),s)}onError(){this.socket&&(this.socket.onerror=()=>{var e;const t=(null===(e=this.autoReconnect)||void 0===e?void 0:e.reconnectMaxCount)||3;this.autoReconnect&&this.reconnectCount<t&&(this.reconnectCount++,this.connect())})}close(){this.socket&&this.socket.close(),this.delay&&clearTimeout(this.delay),this.timer&&clearInterval(this.timer),this.socket=null}onMessage(e){this.socket&&(this.socket.onmessage=t=>{try{const n=JSON.parse(t.data);n.data=JSON.parse(n.data),e(n)}catch(n){e(t)}})}sendToEngin(e){var t={appId:this.appId,sessionId:this.sessionId,clientId:this.clientId,action:"2",role:"web",data:e};this.send(t)}sendToWebClient(e){var t={appId:this.appId,sessionId:this.sessionId,clientId:this.clientId,action:"3",role:"web",data:e};this.send(t)}send(e){console.log("=========== send"),console.log(this.socket),this.socket&&(this.socket.readyState===this.socket.OPEN?this.socket.send(JSON.stringify(e)):(this.socket.readyState===this.socket.CONNECTING||this.connect(),this.delay=setTimeout((()=>{var t;null===(t=this.socket)||void 0===t||t.send(JSON.stringify(e))}),1e3)))}login(){var e={appId:this.appId,sessionId:this.sessionId,clientId:this.clientId,action:"1",role:"web"};console.error(e),this.send(e)}}e.MapServerController=class{constructor(e){this.socket=null,this.socket=e}debugInfo(){var e={appId:this.socket.appId,sessionId:this.socket.sessionId,clientId:this.socket.clientId,action:"100",role:"web",data:""};this.socket.send(e)}createApiServiceLayer(e){if("api"==e.extendData.type){var t={code:m(),function:"",type:"noCallBack",parameters:{layerType:e.extendData.layerType,requestsType:"",requestsContentType:"",url:"",headers:"",paramerts:"",treeStructure:"",fieldMapping:"",fieldType:""}};t.function="PointController.AddPointsFromServerApi",t.parameters.requestsType=e.extendData.requestsType,t.parameters.requestsContentType="json",t.parameters.url=e.extendData.url,t.parameters.headers=e.extendData.haeder,t.parameters.paramerts=e.extendData.params,t.parameters.treeStructure=e.extendData.treeStructure,t.parameters.fieldMapping=e.extendData.fieldMapping,t.parameters.fieldType=e.extendData.fieldType,this.socket.sendToEngin(t)}}showLayer(e){switch(e.extendData.type){case"api":this.socket.sendToEngin({code:m(),function:"PointController.ShowPointsByType",type:"noCallBack",parameters:{type:e.extendData.layerType}});break;case"terrain":this.socket.sendToEngin({code:m(),function:"MapServerController.SetTerrainUrl",type:"noCallBack",parameters:{type:e.extendData.type,icon:"图标路径",name:e.extendData.layerType,serverOrFile:!0,url:e.extendData.url}});break;case"tms":this.socket.sendToEngin({code:m(),function:"MapServerController.AddTMSLayer",type:"noCallBack",parameters:{type:e.extendData.type,icon:"图标路径",name:e.extendData.layerType,serverOrFile:!0,url:e.extendData.url}});break;case"wms":this.socket.sendToEngin({code:m(),function:"MapServerController.AddWMSLayer",type:"noCallBack",parameters:{type:e.extendData.type,icon:"图标路径",name:e.extendData.layerType,serverOrFile:!0,url:e.extendData.url,layer:e.extendData.layer}});break;case"3dtiles":this.socket.sendToEngin({code:m(),function:"MapServerController.Add3DTileLayer",type:"noCallBack",parameters:{type:e.extendData.type,icon:"图标路径",name:e.extendData.layerType,serverOrFile:!0,url:e.extendData.url,layer:e.extendData.layer}});break;case"Point":console.log(e.extendData)}}hideLayer(e){switch(e.extendData.type){case"api":var t={code:m(),function:"PointController.HiddenPointsByType",type:"noCallBack",parameters:{type:e.extendData.layerType}};this.socket.sendToEngin(t);break;case"terrain":this.socket.sendToEngin({code:m(),function:"MapServerController.AddTMSLayer",type:"noCallBack",parameters:{type:e.extendData.type,icon:"图标路径",name:e.extendData.layerType,serverOrFile:!0,url:e.extendData.url}});break;case"tms":this.socket.sendToEngin({code:m(),function:"MapServerController.RemoveTMSLayer",type:"noCallBack",parameters:{name:e.extendData.layerType}});break;case"wms":this.socket.sendToEngin({code:m(),function:"MapServerController.RemoveWMSLayer",type:"noCallBack",parameters:{name:e.extendData.layerType}});break;case"3dtiles":this.socket.sendToEngin({code:m(),function:"MapServerController.Remove3DTileLayer",type:"noCallBack",parameters:{type:e.extendData.type,icon:"图标路径",name:e.extendData.layerType,serverOrFile:!0,url:e.extendData.url,layer:e.extendData.layer}});break;case"Point":console.log(e.extendData)}}},e.Web3DCore=T,e.web3DCoreSocket=class{constructor(e,t){this.socket=null,this.reconnectCount=0,this.delay=null,this.timer=null;const{autoReconnect:n=!0,query:s={},heartbeat:r=!0,appId:o,clientId:a,sessionId:i}=t||{};console.log("==============constructor"),console.log(t),console.log(o),this.autoReconnect=n,this.heartbeat=r,this.appId=o,this.clientId=a,this.sessionId=i,this.query=s,this.url=e||"ws://test/api"+JSON.stringify(Object.assign({token:""},this.query)),this.connect()}connect(){this.close(),this.socket=new WebSocket(this.url),this.onError(),this.onOpen()}onOpen(){this.socket&&(this.socket.onopen=()=>{this.login(),this.send("ping"),this.heartbeat&&this.startHeartbeat()})}startHeartbeat(){var e,t;const n=(null===(e=this.heartbeat)||void 0===e?void 0:e.message)||"ping",s=(null===(t=this.heartbeat)||void 0===t?void 0:t.interval)||1e7;this.timer=setInterval((()=>{this.send(n)}),s)}onError(){this.socket&&(this.socket.onerror=()=>{var e;const t=(null===(e=this.autoReconnect)||void 0===e?void 0:e.reconnectMaxCount)||3;this.autoReconnect&&this.reconnectCount<t&&(this.reconnectCount++,this.connect())})}close(){this.socket&&this.socket.close(),this.delay&&clearTimeout(this.delay),this.timer&&clearInterval(this.timer),this.socket=null}onMessage(e){this.socket&&(this.socket.onmessage=t=>{try{const n=JSON.parse(t.data);n.data=JSON.parse(n.data),e(n)}catch(n){e(t)}})}sendToEngin(e){var t={appId:this.appId,sessionId:this.sessionId,clientId:this.clientId,action:"2",role:"web",data:e};this.send(t)}sendToWebClient(e){var t={appId:this.appId,sessionId:this.sessionId,clientId:this.clientId,action:"3",role:"web",data:e};this.send(t)}send(e){this.socket&&(this.socket.readyState===this.socket.OPEN?this.socket.send(JSON.stringify(e)):(this.socket.readyState===this.socket.CONNECTING||this.connect(),this.delay=setTimeout((()=>{var t;null===(t=this.socket)||void 0===t||t.send(JSON.stringify(e))}),1e3)))}login(){var e={appId:this.appId,sessionId:this.sessionId,clientId:this.clientId,action:"1",role:"web"};console.error(e),this.send(e)}},Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.js.map