From 4ebd3a5ec41ff4a681ee72141b5a76df62fd0633 Mon Sep 17 00:00:00 2001 From: yandeu <20306025+yandeu@users.noreply.github.com> Date: Tue, 12 Sep 2023 15:31:11 +0200 Subject: [PATCH] v2.3.2 --- bundles/geckos.io-client.2.3.2.min.js | 1 + lerna.json | 2 +- package-lock.json | 19 +++++++++++++++++++ package.json | 3 ++- packages/chatApp/package.json | 6 +++--- packages/client/package.json | 4 ++-- packages/common/package.json | 2 +- packages/server/package.json | 4 ++-- 8 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 bundles/geckos.io-client.2.3.2.min.js diff --git a/bundles/geckos.io-client.2.3.2.min.js b/bundles/geckos.io-client.2.3.2.min.js new file mode 100644 index 0000000..0e43c5b --- /dev/null +++ b/bundles/geckos.io-client.2.3.2.min.js @@ -0,0 +1 @@ +var geckos;(()=>{"use strict";var e={118:function(e,t,n){var o=this&&this.__spreadArray||function(e,t,n){if(n||2===arguments.length)for(var o,r=0,i=t.length;r{Object.defineProperty(t,"__esModule",{value:!0}),t.VERSION=void 0,t.VERSION="0.0.6"}},t={};function n(o){var r=t[o];if(void 0!==r)return r.exports;var i=t[o]={exports:{}};return e[o].call(i.exports,i,i.exports,n),i.exports}n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var o={};(()=>{n.d(o,{default:()=>g});var e=n(118);class t{constructor(){this.eventEmitter=new e.Events}emit(e,t,n={}){this.eventEmitter.emit(e,t,n)}on(e,t){return this.eventEmitter.on(e,((e,n)=>{t(e,n)}))}removeAllListeners(){this.eventEmitter.removeAllListeners()}}new t;const r="disconnected",i="rawMessage",s="BROWSER_NOT_SUPPORTED",a="COULD_NOT_PARSE_MESSAGE",c=Object.getPrototypeOf(Object.getPrototypeOf(new Uint8Array)).constructor,l=("function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout,e=>"string"==typeof e),h=e=>e instanceof ArrayBuffer||e instanceof c,u=e=>{let{data:t}=e;t||(t=e);const n=h(t),o=(e=>{try{return"string"==typeof e&&!!isNaN(parseInt(e))&&(JSON.parse(e),!0)}catch(e){return!1}})(t),r=l(t);if(o){const e=JSON.parse(t),n=Object.keys(e)[0];return{key:n,data:e[n]}}return n||r?{key:i,data:t}:{key:"error",data:new Error(a)}};class d{emit(e,t=null){((e,t,n,o=null)=>{var r;const s=(n,o)=>{var r;const i=null!==(r=n.byteLength)&&void 0!==r?r:2*n.length;if("number"==typeof t&&i>t)throw new Error(`maxMessageSize of ${t} exceeded`);Promise.resolve().then((()=>{e.send?e.send(n):o?e.sendMessageBinary(Buffer.from(n)):e.sendMessage(n)})).catch((e=>{console.log("error",e)}))};if(e&&("open"===e.readyState||(null===(r=e.isOpen)||void 0===r?void 0:r.call(e))))try{n===i&&null!==o&&(l(o)||h(o))?s(o,h(o)):s(JSON.stringify({[n]:o}),!1)}catch(e){return console.error("Error in sendMessage.ts: ",e.message),e}})(this.dataChannel,this.maxMessageSize,e,t)}constructor(e,n,o,r){this.url=e,this.authorization=n,this.label=o,this.rtcConfiguration=r,this.bridge=new t,this.onDataChannel=e=>{const{channel:t}=e;t.label===this.label&&(this.dataChannel=t,this.dataChannel.binaryType="arraybuffer",this.dataChannel.onmessage=e=>{const{key:t,data:n}=u(e);this.bridge.emit(t,n)})}}async fetchAdditionalCandidates(e,t){var n;if("closed"===(null===(n=this.dataChannel)||void 0===n?void 0:n.readyState))return;const o=await fetch(`${e}/connections/${t}/additional-candidates`,{method:"GET",headers:{"Content-Type":"application/json"}});if(o.ok){(await o.json()).forEach((e=>{this.localPeerConnection.addIceCandidate(e)}))}}async connect(){const e=`${this.url}/.wrtc/v2`;let t={"Content-Type":"application/json"};this.authorization&&(t={...t,Authorization:this.authorization});let n={};try{const o=await fetch(`${e}/connections`,{method:"POST",headers:t});if(o.status>=300)throw{name:"Error",message:`Connection failed with status code ${o.status}.`,status:o.status,statusText:o.statusText};const r=await o.json();n=r.userData,this.remotePeerConnection=r}catch(e){return console.error(e.message),{error:e}}const{id:o,localDescription:r}=this.remotePeerConnection,i={sdpSemantics:"unified-plan",...this.rtcConfiguration},s=RTCPeerConnection||webkitRTCPeerConnection;this.localPeerConnection=new s(i);((e=10,t=50,n=1.8,o=20)=>Array(e).fill(0).map(((e,r)=>parseInt((t*n**r).toString())+parseInt((Math.random()*o).toString()))))().forEach((t=>{setTimeout((()=>{this.fetchAdditionalCandidates(e,o).catch((()=>{}))}),t)}));try{await this.localPeerConnection.setRemoteDescription(r),this.localPeerConnection.addEventListener("datachannel",this.onDataChannel,{once:!0});const t=await this.localPeerConnection.createAnswer(),i=new RTCSessionDescription({type:"answer",sdp:t.sdp});await this.localPeerConnection.setLocalDescription(i);try{await fetch(`${e}/connections/${o}/remote-description`,{method:"POST",body:JSON.stringify(this.localPeerConnection.localDescription),headers:{"Content-Type":"application/json"}})}catch(e){return console.error(e.message),{error:e}}const s=()=>new Promise((e=>{this.localPeerConnection.addEventListener("datachannel",(()=>{e()}),{once:!0})}));return this.dataChannel||await s(),{userData:n,localPeerConnection:this.localPeerConnection,dataChannel:this.dataChannel,id:o}}catch(e){return console.error(e.message),this.localPeerConnection.close(),{error:e}}}}class f{async connect(e){if(RTCPeerConnection||webkitRTCPeerConnection){const{localPeerConnection:t,dataChannel:n,id:o,userData:r,error:i}=await e.connect();return i?{error:i}:t&&n&&o&&r?(this.localPeerConnection=t,this.dataChannel=n,this.id=o,{userData:r}):{error:new Error('Something went wrong in "await connectionsManager.connect()"')}}{const e=new Error(s);return console.error(e.message),{error:e}}}}const p=(e,t)=>{const{interval:n=150,runs:o=10}=e,r=((e=24)=>{const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let n="";for(let o=0;o{let o=0;if("function"!=typeof n)return void console.error("You have to define your callback function!");const r=setInterval((()=>{n(),o++,o===t-1&&clearInterval(r)}),e);n()})(n,o,(()=>{t(r)}))};class v{constructor(e,t,n,o,i){this.userData={},this.receivedReliableMessages=[],this.url=n?`${e}:${n}`:e,this.connectionsManager=new d(this.url,t,o,i),this.bridge=this.connectionsManager.bridge,this.bridge.on(r,(()=>this.bridge.removeAllListeners()))}onconnectionstatechange(){const e=this.peerConnection.localPeerConnection;e.onconnectionstatechange=()=>{"disconnected"!==e.connectionState&&"closed"!==e.connectionState||this.bridge.emit(r)}}get id(){return this.peerConnection.id}close(){this.peerConnection.localPeerConnection.close(),this.bridge.emit(r);try{const e=`${this.url}/.wrtc/v2`;fetch(`${e}/connections/${this.id}/close`,{method:"POST",headers:{"Content-Type":"application/json"}})}catch(e){console.error(e.message)}}emit(e,t=null,n){n&&n.reliable?p(n,(n=>this.connectionsManager.emit(e,{MESSAGE:t,RELIABLE:1,ID:n}))):this.connectionsManager.emit(e,t)}get raw(){return{emit:e=>this.emit(i,e)}}onRaw(e){this.bridge.on(i,(t=>{(t=>{e(t)})(t)}))}async onConnect(e){var t;this.peerConnection=new f;const n=await this.peerConnection.connect(this.connectionsManager);n.error?e(n.error):(n.userData&&(this.userData=n.userData),this.maxMessageSize=this.connectionsManager.maxMessageSize=null===(t=this.peerConnection.localPeerConnection.sctp)||void 0===t?void 0:t.maxMessageSize,this.onconnectionstatechange(),e())}onDisconnect(e){this.bridge.on(r,e)}on(e,t){this.bridge.on(e,(e=>{e&&1===e.RELIABLE&&"undefined"!==e.ID?((()=>{const e=(new Date).getTime();this.receivedReliableMessages.forEach(((t,n,o)=>{t.expire<=e&&o.splice(n,1)}))})(),0===this.receivedReliableMessages.filter((t=>t.id===e.ID)).length&&(this.receivedReliableMessages.push({id:e.ID,timestamp:new Date,expire:(new Date).getTime()+15e3}),t(e.MESSAGE))):t(e)}))}}const g=(e={})=>{const{authorization:t,iceServers:n=[],iceTransportPolicy:o="all",label:r="geckos.io",port:i=9208,url:s=`${location.protocol}//${location.hostname}`}=e;return new v(s,t,i,r,{iceServers:n,iceTransportPolicy:o})}})(),geckos=o.default})(); \ No newline at end of file diff --git a/lerna.json b/lerna.json index 9a3078a..c776712 100644 --- a/lerna.json +++ b/lerna.json @@ -2,7 +2,7 @@ "packages": [ "packages/*" ], - "version": "2.3.2-dev.0", + "version": "2.3.2", "command": { "bootstrap": { "npmClientArgs": [ diff --git a/package-lock.json b/package-lock.json index 0be8998..9cb51cc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "@yandeu/eslint-config": "^0.0.4", "@yandeu/prettier-config": "^0.0.4", "copy-webpack-plugin": "^11.0.0", + "cross-env": "^7.0.3", "eslint": "^8.46.0", "express6": "^0.1.2", "html-webpack-plugin": "^5.2.0", @@ -5578,6 +5579,24 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/cross-env": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", + "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==", + "dev": true, + "dependencies": { + "cross-spawn": "^7.0.1" + }, + "bin": { + "cross-env": "src/bin/cross-env.js", + "cross-env-shell": "src/bin/cross-env-shell.js" + }, + "engines": { + "node": ">=10.14", + "npm": ">=6", + "yarn": ">=1" + } + }, "node_modules/cross-fetch": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-4.0.0.tgz", diff --git a/package.json b/package.json index 97d84b2..39b806a 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,7 @@ "@yandeu/eslint-config": "^0.0.4", "@yandeu/prettier-config": "^0.0.4", "copy-webpack-plugin": "^11.0.0", + "cross-env": "^7.0.3", "eslint": "^8.46.0", "express6": "^0.1.2", "html-webpack-plugin": "^5.2.0", @@ -84,4 +85,4 @@ "funding": { "url": "https://github.com/sponsors/yandeu" } -} \ No newline at end of file +} diff --git a/packages/chatApp/package.json b/packages/chatApp/package.json index 0d7b3f5..1bee241 100644 --- a/packages/chatApp/package.json +++ b/packages/chatApp/package.json @@ -1,7 +1,7 @@ { "name": "chat-app", "description": "Real-time client/server communication over UDP using WebRTC and Node.js", - "version": "2.3.2-dev.0", + "version": "2.3.2", "main": "dist", "type": "module", "private": true, @@ -38,8 +38,8 @@ "lib": "lib" }, "dependencies": { - "@geckos.io/client": "^2.3.2-dev.0", - "@geckos.io/server": "^2.3.2-dev.0" + "@geckos.io/client": "^2.3.2", + "@geckos.io/server": "^2.3.2" }, "funding": { "url": "https://github.com/sponsors/yandeu" diff --git a/packages/client/package.json b/packages/client/package.json index 7d20e04..b06d668 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -1,6 +1,6 @@ { "name": "@geckos.io/client", - "version": "2.3.2-dev.0", + "version": "2.3.2", "description": "Real-time client/server communication over UDP using WebRTC and Node.js", "main": "./lib/index.js", "types": "./lib/index.d.ts", @@ -45,7 +45,7 @@ "prepublishOnly": "npm run build" }, "dependencies": { - "@geckos.io/common": "^2.3.2-dev.0" + "@geckos.io/common": "^2.3.2" }, "funding": { "url": "https://github.com/sponsors/yandeu" diff --git a/packages/common/package.json b/packages/common/package.json index ce14b61..44d4d2c 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -1,6 +1,6 @@ { "name": "@geckos.io/common", - "version": "2.3.2-dev.0", + "version": "2.3.2", "description": "The common module for @geckos.io/server and @geckos.io/client.", "main": "lib", "type": "module", diff --git a/packages/server/package.json b/packages/server/package.json index 080aa26..1803926 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -1,6 +1,6 @@ { "name": "@geckos.io/server", - "version": "2.3.2-dev.0", + "version": "2.3.2", "description": "Real-time client/server communication over UDP using WebRTC and Node.js", "main": "./lib/index.js", "types": "./lib/index.d.ts", @@ -43,7 +43,7 @@ "prepublishOnly": "npm run build" }, "dependencies": { - "@geckos.io/common": "^2.3.2-dev.0", + "@geckos.io/common": "^2.3.2", "@yandeu/events": "0.0.6", "node-datachannel": "0.4.3" },