@gjsify/websocket 0.3.20 → 0.4.0
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Object.defineProperty,__name=(t,n)=>e(t,`name`,{value:n,configurable:!0});export{__name};
|
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"@girs/glib-2.0";import t from"@girs/soup-3.0";import n from"@girs/gio-2.0";import{CloseEvent as r,Event as i,EventTarget as a,MessageEvent as o}from"@gjsify/dom-events";function
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import e from"@girs/glib-2.0";import t from"@girs/soup-3.0";import n from"@girs/gio-2.0";import{CloseEvent as r,Event as i,EventTarget as a,MessageEvent as o}from"@gjsify/dom-events";function extensionName(e){return e instanceof t.WebsocketExtensionDeflate?`permessage-deflate`:(e.constructor.$gtype?.name??``).replace(/^SoupWebsocketExtension/,``).toLowerCase()}function serializeExtensions(e){return!e||e.length===0?``:e.map(e=>{let t=e.get_response_params();return t?`${extensionName(e)}${t}`:extensionName(e)}).join(`, `)}var WebSocket=class extends a{static CONNECTING=0;static OPEN=1;static CLOSING=2;static CLOSED=3;CONNECTING=0;OPEN=1;CLOSING=2;CLOSED=3;url;readyState=0;bufferedAmount=0;extensions=``;protocol=``;binaryType=`blob`;onopen=null;onmessage=null;onerror=null;onclose=null;_connection=null;_session;_protocols;_cancellable=null;_handshakeTimedOut=!1;_handshakeTimer=null;constructor(e,n,r){super(),this.url=typeof e==`string`?e:e.toString(),this._protocols=typeof n==`string`?[n]:n??[],this._session=new t.Session,r?.perMessageDeflate&&(this._session.add_feature_by_type(t.WebsocketExtensionManager.$gtype),this._session.add_feature_by_type(t.WebsocketExtensionDeflate.$gtype)),this._connect(r)}_connect(a){let o=e.Uri.parse(this.url,e.UriFlags.NONE),s=new t.Message({method:`GET`,uri:o});if(a?.headers){let e=s.get_request_headers();for(let[t,n]of Object.entries(a.headers))Array.isArray(n)?n.forEach(n=>e.append(t,n)):e.replace(t,n)}if(a?.handshakeTimeout){this._cancellable=new n.Cancellable;let e=this._cancellable;this._handshakeTimer=setTimeout(()=>{this._handshakeTimedOut=!0,this._handshakeTimer=null,e.cancel()},a.handshakeTimeout)}this._session.websocket_connect_async(s,a?.origin??null,this._protocols.length>0?this._protocols:null,e.PRIORITY_DEFAULT,this._cancellable,(e,t)=>{this._handshakeTimer!==null&&(clearTimeout(this._handshakeTimer),this._handshakeTimer=null);try{this._connection=this._session.websocket_connect_finish(t),this._connection.max_incoming_payload_size=100*1024*1024,this.readyState=1,this.protocol=this._connection.get_protocol()??``,this.extensions=serializeExtensions(this._connection.get_extensions()),this._connection.connect(`message`,(e,t,n)=>{this._onMessage(t,n)}),this._connection.connect(`closed`,()=>{this._onClosed()}),this._connection.connect(`error`,(e,t)=>{this._onError(t)});let e=new i(`open`);this.dispatchEvent(e),this.onopen&&this.onopen.call(this,e)}catch(e){this.readyState=3;let t=this._handshakeTimedOut?`Opening handshake has timed out`:e instanceof Error?e.message:String(e),n=Error(t),a=new i(`error`);a.error=n,a.message=t,this.dispatchEvent(a),this.onerror&&this.onerror.call(this,a);let o=new r(`close`,{code:1006,reason:t,wasClean:!1});this.dispatchEvent(o),this.onclose&&this.onclose.call(this,o)}})}_onMessage(e,n){let r;if(e===t.WebsocketDataType.TEXT)r=new TextDecoder().decode(n.toArray());else{let e=n.toArray();r=e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}let i=new o(`message`,{data:r,origin:this.url});this.dispatchEvent(i),this.onmessage&&this.onmessage.call(this,i)}_onError(e){let t=new i(`error`);this.dispatchEvent(t),this.onerror&&this.onerror.call(this,t)}_onClosed(){let e=this._connection?.get_close_code()??1006,t=this._connection?.get_close_data()??``,n=e===1e3;this.readyState=3,this._connection=null;let i=new r(`close`,{code:e,reason:t,wasClean:n});this.dispatchEvent(i),this.onclose&&this.onclose.call(this,i)}send(n){if(this.readyState!==1)throw new DOMException(`WebSocket is not open`,`InvalidStateError`);if(this._connection)if(typeof n==`string`){let r=new TextEncoder().encode(n);this._connection.send_message(t.WebsocketDataType.TEXT,new e.Bytes(r))}else{let r;r=n instanceof ArrayBuffer?new Uint8Array(n):new Uint8Array(n.buffer,n.byteOffset,n.byteLength),this._connection.send_message(t.WebsocketDataType.BINARY,new e.Bytes(r))}}close(e,t){if(!(this.readyState===3||this.readyState===2)){if(e!==void 0&&e!==1e3&&(e<3e3||e>4999))throw new DOMException(`The code must be either 1000, or between 3000 and 4999. ${e} is neither.`,`InvalidAccessError`);if(this.readyState=2,this._connection)this._connection.close(e??1e3,t??null);else{this.readyState=3;let e=new r(`close`,{code:1006,wasClean:!1});this.dispatchEvent(e),this.onclose&&this.onclose.call(this,e)}}}};export{r as CloseEvent,o as MessageEvent,WebSocket,WebSocket as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/websocket",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "W3C WebSocket API for GJS using Soup 3.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -38,16 +38,16 @@
|
|
|
38
38
|
"soup"
|
|
39
39
|
],
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@gjsify/cli": "^0.
|
|
42
|
-
"@gjsify/unit": "^0.
|
|
41
|
+
"@gjsify/cli": "^0.4.0",
|
|
42
|
+
"@gjsify/unit": "^0.4.0",
|
|
43
43
|
"@types/node": "^25.6.2",
|
|
44
44
|
"typescript": "^6.0.3"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@girs/gio-2.0": "2.88.0-4.0.0-rc.
|
|
48
|
-
"@girs/gjs": "4.0.0-rc.
|
|
49
|
-
"@girs/glib-2.0": "2.88.0-4.0.0-rc.
|
|
50
|
-
"@girs/soup-3.0": "3.6.6-4.0.0-rc.
|
|
51
|
-
"@gjsify/dom-events": "^0.
|
|
47
|
+
"@girs/gio-2.0": "2.88.0-4.0.0-rc.15",
|
|
48
|
+
"@girs/gjs": "4.0.0-rc.15",
|
|
49
|
+
"@girs/glib-2.0": "2.88.0-4.0.0-rc.15",
|
|
50
|
+
"@girs/soup-3.0": "3.6.6-4.0.0-rc.15",
|
|
51
|
+
"@gjsify/dom-events": "^0.4.0"
|
|
52
52
|
}
|
|
53
53
|
}
|