diff --git a/dist/src/WS.d.ts b/dist/src/WS.d.ts index ec5c6fb..991a367 100644 --- a/dist/src/WS.d.ts +++ b/dist/src/WS.d.ts @@ -1,5 +1,5 @@ import './types'; -declare class WebSocketClient implements wsc.WebSocketClient { +declare class WebSocketClient { private open; private ws; private forcibly_closed; diff --git a/dist/src/types.d.ts b/dist/src/types.d.ts index ff015ee..1e610c2 100644 --- a/dist/src/types.d.ts +++ b/dist/src/types.d.ts @@ -1,5 +1,8 @@ declare namespace wsc { - /** Stuff that in use by this lib. */ + interface DataObject { + [key: string]: any; + } + /** Minimal socket-like interface. */ interface Socket { readyState: number; send(...any: any[]): void; @@ -37,10 +40,4 @@ declare namespace wsc { top: any; data_type: DataType; } - class WebSocketClient { - on(event_name: string, handler: (event: string) => void, predicate?: (event: string) => boolean): void; - close(): Promise; - send(user_message: any, opts: wsc.SendOptions): AsyncErrCode; - constructor(user_config: wsc.UserConfig); - } } diff --git a/dist/ws.esm.js b/dist/ws.esm.js index 956e5bf..f20438f 100644 --- a/dist/ws.esm.js +++ b/dist/ws.esm.js @@ -1 +1 @@ -function t(t,e,o,s){return new(o||(o=Promise))(function(n,i){function l(t){try{c(s.next(t))}catch(t){i(t)}}function r(t){try{c(s.throw(t))}catch(t){i(t)}}function c(t){t.done?n(t.value):new o(function(e){e(t.value)}).then(l,r)}c((s=s.apply(t,e||[])).next())})}const e="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",o=e.length-1;var s=t=>{const s=[];for(;t>=1;)s.push(e[t%(o+1)]),t=t/o|0;return s.join("")};const n=(t,e,o)=>t.addEventListener(e,o),i=t=>{let e=!1,o=null;return(...s)=>e?o:(e=!0,o=t(...s))},l=(t,e)=>setTimeout(e,t),r=function(e){const o=this.config;this.open=!0,this.onReadyQueue.forEach(t=>t()),this.onReadyQueue.splice(0);const{id_key:s,data_key:i}=o.server;this.messages.forEach(t=>t.send()),null!==this.reconnect_timeout&&(clearInterval(this.reconnect_timeout),this.reconnect_timeout=null),n(e,"close",()=>t(this,void 0,void 0,function*(){this.log("Closed."),this.open=!1,this.onCloseQueue.forEach(t=>t()),this.onCloseQueue=[];const e=o.reconnect;if("number"!=typeof e||isNaN(e)||this.forcibly_closed)this.ws=null,this.open=null;else{const o=()=>t(this,void 0,void 0,function*(){this.log("Trying to reconnect..."),null!==this.ws&&(this.ws.close(),this.ws=null),null!==(yield this.connect())&&(this.reconnect_timeout=setTimeout(o,1e3*e))});o()}this.forcibly_closed=!1})),n(e,"message",t=>{try{const e=o.decode(t.data);if(e[s]){const t=this.queue[e[s]];if(t){const o=t.sent_time?Date.now()-t.sent_time:null;this.log("Message.",e[i],o),t.ff(e[i]),clearTimeout(t.timeout),delete this.queue[e[s]]}}}catch(e){console.error(e,`Decode error. Got: ${t.data}`)}})},c=function(t){if(!0===this.open)return t(null);const e=this.config,o=e.socket||e.adapter(`ws://${e.url}`,e.protocols);if(this.ws=o,!o||o.readyState>1)return this.ws=null,this.log("Error: ready() on closing or closed state! Status 2."),t(2);n(o,"error",i(()=>(this.ws=null,this.log("Error status 3."),t(3)))),o.readyState?(r.call(this,o),t(null)):n(o,"open",i(()=>(this.log("Opened."),r.call(this,o),t(null))))},u={data_type:"json",log:()=>null,timer:!1,url:"localhost",timeout:1400,reconnect:2,lazy:!1,socket:null,adapter:(t,e)=>new WebSocket(t,e),encode:(t,e,{server:o})=>JSON.stringify({[o.id_key]:t,[o.data_key]:e}),decode:t=>JSON.parse(t),protocols:[],pipes:[],server:{id_key:"id",data_key:"data"}},h=t=>{const e=Object.assign({},u,t),o=e.url;if("/"==o[0])try{e.url=`${location.hostname}:${location.port}${o}`}catch(t){throw new Error("WSP: URL starting with / in non-browser environment!")}return e},a=Math.pow(2,31)-1;export default class{constructor(t={}){this.open=null,this.ws=null,this.forcibly_closed=!1,this.reconnect_timeout=null,this.queue={},this.messages=[],this.onReadyQueue=[],this.onCloseQueue=[],this.config={},this.config=h(t),this.init_flush(),this.open=!1,this.reconnect_timeout=null,this.forcibly_closed=!1,this.config.lazy||this.connect()}init_flush(){this.queue={},this.messages=[]}log(t,e=null,o=null){const s=this.config;t=`WSP: ${t}`,null!==o?s.log(t,o,e):s.timer?s.log(t,null,e):s.log(t,e)}connect(){return t(this,void 0,void 0,function*(){return new Promise(t=>{c.call(this,t)})})}get socket(){return this.ws}ready(){return t(this,void 0,void 0,function*(){return new Promise(t=>{this.open?t():this.onReadyQueue.push(t)})})}on(t,e,o){return n(this.ws,t,t=>{o&&!o(t)||e(t)})}close(){return t(this,void 0,void 0,function*(){return new Promise((t,e)=>{null===this.ws?e("WSP: closing a non-inited socket!"):(this.open=null,this.onCloseQueue.push(()=>{this.init_flush(),this.ws=null,this.forcibly_closed=!0,t()}),this.ws.close())})})}send(e,o={}){return t(this,void 0,void 0,function*(){this.log("Send.",e);const t=this.config,n={},i=t.server.data_key,r=t.lazy&&!this.open,c=s(Math.random()*(a-10)|0);if("object"==typeof o.top){if(o.top[i])throw new Error("Attempting to set data key/token via send() options!");Object.assign(n,o.top)}if(t.pipes.forEach(t=>e=t(e)),!0===this.open)this.ws.send(t.encode(c,e,t));else if(!1===this.open||r)this.messages.push({send:()=>this.ws.send(t.encode(c,e,t))}),r&&this.connect();else if(null===this.open)throw new Error("Attempting to send via closed WebSocket connection!");return new Promise((e,o)=>{this.queue[c]={ff:e,data_type:t.data_type,sent_time:t.timer?Date.now():null,timeout:l(t.timeout,()=>{this.queue[c]&&(o({"Websocket timeout expired: ":t.timeout,"for the message":n}),delete this.queue[c])})}})})}} +function t(t,e,o,s){return new(o||(o=Promise))(function(n,i){function l(t){try{c(s.next(t))}catch(t){i(t)}}function r(t){try{c(s.throw(t))}catch(t){i(t)}}function c(t){t.done?n(t.value):new o(function(e){e(t.value)}).then(l,r)}c((s=s.apply(t,e||[])).next())})}const e="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",o=e.length-1;var s=t=>{const s=[];for(;t>=1;)s.push(e[t%(o+1)]),t=t/o|0;return s.join("")};const n=(t,e,o)=>t.addEventListener(e,o),i=t=>{let e=!1,o=null;return(...s)=>e?o:(e=!0,o=t(...s))},l=(t,e)=>setTimeout(e,t),r=function(e){const o=this.config;this.open=!0,this.onReadyQueue.forEach(t=>t()),this.onReadyQueue.splice(0);const{id_key:s,data_key:i}=o.server;this.messages.forEach(t=>t.send()),null!==this.reconnect_timeout&&(clearInterval(this.reconnect_timeout),this.reconnect_timeout=null),n(e,"close",()=>t(this,void 0,void 0,function*(){this.log("Closed."),this.open=!1,this.onCloseQueue.forEach(t=>t()),this.onCloseQueue=[];const e=o.reconnect;if("number"!=typeof e||isNaN(e)||this.forcibly_closed)this.ws=null,this.open=null;else{const o=()=>t(this,void 0,void 0,function*(){this.log("Trying to reconnect..."),null!==this.ws&&(this.ws.close(),this.ws=null),null!==(yield this.connect())&&(this.reconnect_timeout=setTimeout(o,1e3*e))});o()}this.forcibly_closed=!1})),n(e,"message",t=>{try{const e=o.decode(t.data);if(e[s]){const t=this.queue[e[s]];if(t){const o=t.sent_time?Date.now()-t.sent_time:null;this.log("Message.",e[i],o),t.ff(e[i]),clearTimeout(t.timeout),delete this.queue[e[s]]}}}catch(e){console.error(e,`Decode error. Got: ${t.data}`)}})},c=function(t){if(!0===this.open)return t(null);const e=this.config,o=e.socket||e.adapter(`ws://${e.url}`,e.protocols);if(this.ws=o,!o||o.readyState>1)return this.ws=null,this.log("Error: ready() on closing or closed state! Status 2."),t(2);n(o,"error",i(()=>(this.ws=null,this.log("Error status 3."),t(3)))),o.readyState?(r.call(this,o),t(null)):n(o,"open",i(()=>(this.log("Opened."),r.call(this,o),t(null))))},u={data_type:"json",log:()=>null,timer:!1,url:"localhost",timeout:1400,reconnect:2,lazy:!1,socket:null,adapter:(t,e)=>new WebSocket(t,e),encode:(t,e,{server:o})=>JSON.stringify({[o.id_key]:t,[o.data_key]:e}),decode:t=>JSON.parse(t),protocols:[],pipes:[],server:{id_key:"id",data_key:"data"}},h=t=>{const e=Object.assign({},u,t),o=e.url;if("/"==o[0])try{e.url=`${location.hostname}:${location.port}${o}`}catch(t){throw new Error("WSP: URL starting with / in non-browser environment!")}return e},a=Math.pow(2,31)-1;export default class{constructor(t={}){this.open=null,this.ws=null,this.forcibly_closed=!1,this.reconnect_timeout=null,this.queue={},this.messages=[],this.onReadyQueue=[],this.onCloseQueue=[],this.config={},this.config=h(t),this.init_flush(),this.open=!1,this.reconnect_timeout=null,this.forcibly_closed=!1,this.config.lazy||this.connect()}init_flush(){this.queue={},this.messages=[]}log(t,e=null,o=null){const s=this.config;t=`WSP: ${t}`,null!==o?s.log(t,o,e):s.timer?s.log(t,null,e):s.log(t,e)}connect(){return t(this,void 0,void 0,function*(){return new Promise(t=>{c.call(this,t)})})}get socket(){return this.ws}ready(){return t(this,void 0,void 0,function*(){return new Promise(t=>{this.open?t():this.onReadyQueue.push(t)})})}on(t,e,o){return n(this.ws,t,t=>{o&&!o(t)||e(t)})}close(){return t(this,void 0,void 0,function*(){return new Promise((t,e)=>{null===this.ws?e("WSP: closing a non-inited socket!"):(this.open=null,this.onCloseQueue.push(()=>{this.init_flush(),this.ws=null,this.forcibly_closed=!0,t(null)}),this.ws.close())})})}send(e,o={}){return t(this,void 0,void 0,function*(){this.log("Send.",e);const t=this.config,n={},i=t.server.data_key,r=t.lazy&&!this.open,c=s(Math.random()*(a-10)|0);if("object"==typeof o.top){if(o.top[i])throw new Error("Attempting to set data key/token via send() options!");Object.assign(n,o.top)}if(t.pipes.forEach(t=>e=t(e)),!0===this.open)this.ws.send(t.encode(c,e,t));else if(!1===this.open||r)this.messages.push({send:()=>this.ws.send(t.encode(c,e,t))}),r&&this.connect();else if(null===this.open)throw new Error("Attempting to send via closed WebSocket connection!");return new Promise((e,o)=>{this.queue[c]={ff:e,data_type:t.data_type,sent_time:t.timer?Date.now():null,timeout:l(t.timeout,()=>{this.queue[c]&&(o({"Websocket timeout expired: ":t.timeout,"for the message":n}),delete this.queue[c])})}})})}} diff --git a/dist/ws.js b/dist/ws.js index 9fbdf6a..c691421 100644 --- a/dist/ws.js +++ b/dist/ws.js @@ -1 +1 @@ -"use strict";function __awaiter(e,t,n,o){return new(n||(n=Promise))(function(i,s){function r(e){try{l(o.next(e))}catch(e){s(e)}}function c(e){try{l(o.throw(e))}catch(e){s(e)}}function l(e){e.done?i(e.value):new n(function(t){t(e.value)}).then(r,c)}l((o=o.apply(e,t||[])).next())})}const abc="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",ln=abc.length-1;var packNumber=e=>{const t=[];for(;e>=1;)t.push(abc[e%(ln+1)]),e=e/ln|0;return t.join("")};const add_event=(e,t,n)=>e.addEventListener(t,n),once=e=>{let t=!1,n=null;return(...o)=>t?n:(t=!0,n=e(...o))},sett=(e,t)=>setTimeout(t,e),init=function(e){const t=this.config;this.open=!0,this.onReadyQueue.forEach(e=>e()),this.onReadyQueue.splice(0);const{id_key:n,data_key:o}=t.server;this.messages.forEach(e=>e.send()),null!==this.reconnect_timeout&&(clearInterval(this.reconnect_timeout),this.reconnect_timeout=null),add_event(e,"close",()=>__awaiter(this,void 0,void 0,function*(){this.log("Closed."),this.open=!1,this.onCloseQueue.forEach(e=>e()),this.onCloseQueue=[];const e=t.reconnect;if("number"!=typeof e||isNaN(e)||this.forcibly_closed)this.ws=null,this.open=null;else{const t=()=>__awaiter(this,void 0,void 0,function*(){this.log("Trying to reconnect..."),null!==this.ws&&(this.ws.close(),this.ws=null),null!==(yield this.connect())&&(this.reconnect_timeout=setTimeout(t,1e3*e))});t()}this.forcibly_closed=!1})),add_event(e,"message",e=>{try{const i=t.decode(e.data);if(i[n]){const e=this.queue[i[n]];if(e){const t=e.sent_time?Date.now()-e.sent_time:null;this.log("Message.",i[o],t),e.ff(i[o]),clearTimeout(e.timeout),delete this.queue[i[n]]}}}catch(t){console.error(t,`Decode error. Got: ${e.data}`)}})},connectLib=function(e){if(!0===this.open)return e(null);const t=this.config,n=t.socket||t.adapter(`ws://${t.url}`,t.protocols);if(this.ws=n,!n||n.readyState>1)return this.ws=null,this.log("Error: ready() on closing or closed state! Status 2."),e(2);add_event(n,"error",once(()=>(this.ws=null,this.log("Error status 3."),e(3)))),n.readyState?(init.call(this,n),e(null)):add_event(n,"open",once(()=>(this.log("Opened."),init.call(this,n),e(null))))},default_config={data_type:"json",log:()=>null,timer:!1,url:"localhost",timeout:1400,reconnect:2,lazy:!1,socket:null,adapter:(e,t)=>new WebSocket(e,t),encode:(e,t,{server:n})=>JSON.stringify({[n.id_key]:e,[n.data_key]:t}),decode:e=>JSON.parse(e),protocols:[],pipes:[],server:{id_key:"id",data_key:"data"}},enrichConfig=e=>{const t=Object.assign({},default_config,e),n=t.url;if("/"==n[0])try{t.url=`${location.hostname}:${location.port}${n}`}catch(e){throw new Error("WSP: URL starting with / in non-browser environment!")}return t},MAX_32=Math.pow(2,31)-1;class WebSocketClient{constructor(e={}){this.open=null,this.ws=null,this.forcibly_closed=!1,this.reconnect_timeout=null,this.queue={},this.messages=[],this.onReadyQueue=[],this.onCloseQueue=[],this.config={},this.config=enrichConfig(e),this.init_flush(),this.open=!1,this.reconnect_timeout=null,this.forcibly_closed=!1,this.config.lazy||this.connect()}init_flush(){this.queue={},this.messages=[]}log(e,t=null,n=null){const o=this.config;e=`WSP: ${e}`,null!==n?o.log(e,n,t):o.timer?o.log(e,null,t):o.log(e,t)}connect(){return __awaiter(this,void 0,void 0,function*(){return new Promise(e=>{connectLib.call(this,e)})})}get socket(){return this.ws}ready(){return __awaiter(this,void 0,void 0,function*(){return new Promise(e=>{this.open?e():this.onReadyQueue.push(e)})})}on(e,t,n){return add_event(this.ws,e,e=>{n&&!n(e)||t(e)})}close(){return __awaiter(this,void 0,void 0,function*(){return new Promise((e,t)=>{null===this.ws?t("WSP: closing a non-inited socket!"):(this.open=null,this.onCloseQueue.push(()=>{this.init_flush(),this.ws=null,this.forcibly_closed=!0,e()}),this.ws.close())})})}send(e,t={}){return __awaiter(this,void 0,void 0,function*(){this.log("Send.",e);const n=this.config,o={},i=n.server.data_key,s=n.lazy&&!this.open,r=packNumber(Math.random()*(MAX_32-10)|0);if("object"==typeof t.top){if(t.top[i])throw new Error("Attempting to set data key/token via send() options!");Object.assign(o,t.top)}if(n.pipes.forEach(t=>e=t(e)),!0===this.open)this.ws.send(n.encode(r,e,n));else if(!1===this.open||s)this.messages.push({send:()=>this.ws.send(n.encode(r,e,n))}),s&&this.connect();else if(null===this.open)throw new Error("Attempting to send via closed WebSocket connection!");return new Promise((e,t)=>{this.queue[r]={ff:e,data_type:n.data_type,sent_time:n.timer?Date.now():null,timeout:sett(n.timeout,()=>{this.queue[r]&&(t({"Websocket timeout expired: ":n.timeout,"for the message":o}),delete this.queue[r])})}})})}}module.exports=WebSocketClient; +"use strict";function __awaiter(e,t,n,o){return new(n||(n=Promise))(function(i,s){function r(e){try{l(o.next(e))}catch(e){s(e)}}function c(e){try{l(o.throw(e))}catch(e){s(e)}}function l(e){e.done?i(e.value):new n(function(t){t(e.value)}).then(r,c)}l((o=o.apply(e,t||[])).next())})}const abc="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",ln=abc.length-1;var packNumber=e=>{const t=[];for(;e>=1;)t.push(abc[e%(ln+1)]),e=e/ln|0;return t.join("")};const add_event=(e,t,n)=>e.addEventListener(t,n),once=e=>{let t=!1,n=null;return(...o)=>t?n:(t=!0,n=e(...o))},sett=(e,t)=>setTimeout(t,e),init=function(e){const t=this.config;this.open=!0,this.onReadyQueue.forEach(e=>e()),this.onReadyQueue.splice(0);const{id_key:n,data_key:o}=t.server;this.messages.forEach(e=>e.send()),null!==this.reconnect_timeout&&(clearInterval(this.reconnect_timeout),this.reconnect_timeout=null),add_event(e,"close",()=>__awaiter(this,void 0,void 0,function*(){this.log("Closed."),this.open=!1,this.onCloseQueue.forEach(e=>e()),this.onCloseQueue=[];const e=t.reconnect;if("number"!=typeof e||isNaN(e)||this.forcibly_closed)this.ws=null,this.open=null;else{const t=()=>__awaiter(this,void 0,void 0,function*(){this.log("Trying to reconnect..."),null!==this.ws&&(this.ws.close(),this.ws=null),null!==(yield this.connect())&&(this.reconnect_timeout=setTimeout(t,1e3*e))});t()}this.forcibly_closed=!1})),add_event(e,"message",e=>{try{const i=t.decode(e.data);if(i[n]){const e=this.queue[i[n]];if(e){const t=e.sent_time?Date.now()-e.sent_time:null;this.log("Message.",i[o],t),e.ff(i[o]),clearTimeout(e.timeout),delete this.queue[i[n]]}}}catch(t){console.error(t,`Decode error. Got: ${e.data}`)}})},connectLib=function(e){if(!0===this.open)return e(null);const t=this.config,n=t.socket||t.adapter(`ws://${t.url}`,t.protocols);if(this.ws=n,!n||n.readyState>1)return this.ws=null,this.log("Error: ready() on closing or closed state! Status 2."),e(2);add_event(n,"error",once(()=>(this.ws=null,this.log("Error status 3."),e(3)))),n.readyState?(init.call(this,n),e(null)):add_event(n,"open",once(()=>(this.log("Opened."),init.call(this,n),e(null))))},default_config={data_type:"json",log:()=>null,timer:!1,url:"localhost",timeout:1400,reconnect:2,lazy:!1,socket:null,adapter:(e,t)=>new WebSocket(e,t),encode:(e,t,{server:n})=>JSON.stringify({[n.id_key]:e,[n.data_key]:t}),decode:e=>JSON.parse(e),protocols:[],pipes:[],server:{id_key:"id",data_key:"data"}},enrichConfig=e=>{const t=Object.assign({},default_config,e),n=t.url;if("/"==n[0])try{t.url=`${location.hostname}:${location.port}${n}`}catch(e){throw new Error("WSP: URL starting with / in non-browser environment!")}return t},MAX_32=Math.pow(2,31)-1;class WebSocketClient{constructor(e={}){this.open=null,this.ws=null,this.forcibly_closed=!1,this.reconnect_timeout=null,this.queue={},this.messages=[],this.onReadyQueue=[],this.onCloseQueue=[],this.config={},this.config=enrichConfig(e),this.init_flush(),this.open=!1,this.reconnect_timeout=null,this.forcibly_closed=!1,this.config.lazy||this.connect()}init_flush(){this.queue={},this.messages=[]}log(e,t=null,n=null){const o=this.config;e=`WSP: ${e}`,null!==n?o.log(e,n,t):o.timer?o.log(e,null,t):o.log(e,t)}connect(){return __awaiter(this,void 0,void 0,function*(){return new Promise(e=>{connectLib.call(this,e)})})}get socket(){return this.ws}ready(){return __awaiter(this,void 0,void 0,function*(){return new Promise(e=>{this.open?e():this.onReadyQueue.push(e)})})}on(e,t,n){return add_event(this.ws,e,e=>{n&&!n(e)||t(e)})}close(){return __awaiter(this,void 0,void 0,function*(){return new Promise((e,t)=>{null===this.ws?t("WSP: closing a non-inited socket!"):(this.open=null,this.onCloseQueue.push(()=>{this.init_flush(),this.ws=null,this.forcibly_closed=!0,e(null)}),this.ws.close())})})}send(e,t={}){return __awaiter(this,void 0,void 0,function*(){this.log("Send.",e);const n=this.config,o={},i=n.server.data_key,s=n.lazy&&!this.open,r=packNumber(Math.random()*(MAX_32-10)|0);if("object"==typeof t.top){if(t.top[i])throw new Error("Attempting to set data key/token via send() options!");Object.assign(o,t.top)}if(n.pipes.forEach(t=>e=t(e)),!0===this.open)this.ws.send(n.encode(r,e,n));else if(!1===this.open||s)this.messages.push({send:()=>this.ws.send(n.encode(r,e,n))}),s&&this.connect();else if(null===this.open)throw new Error("Attempting to send via closed WebSocket connection!");return new Promise((e,t)=>{this.queue[r]={ff:e,data_type:n.data_type,sent_time:n.timer?Date.now():null,timeout:sett(n.timeout,()=>{this.queue[r]&&(t({"Websocket timeout expired: ":n.timeout,"for the message":o}),delete this.queue[r])})}})})}}module.exports=WebSocketClient; diff --git a/src/WS.ts b/src/WS.ts index acbd5b4..564e6fd 100644 --- a/src/WS.ts +++ b/src/WS.ts @@ -11,7 +11,7 @@ const MAX_32 = 2**31 - 1 returns a Promise, that will be rejected after a timeout or resolved if server returns the same signature: {id: `same_hash`, data: `response data`} */ -class WebSocketClient implements wsc.WebSocketClient { +class WebSocketClient { private open = null private ws = null @@ -85,7 +85,7 @@ class WebSocketClient implements wsc.WebSocketClient { this.init_flush() this.ws = null this.forcibly_closed = true - ff() + ff(null) }) this.ws.close() } diff --git a/src/types.ts b/src/types.ts index 9464c4d..d30adc3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,6 +1,10 @@ declare namespace wsc { - /** Stuff that in use by this lib. */ + interface DataObject { + [key: string]: any + } + + /** Minimal socket-like interface. */ interface Socket { readyState: number send(...any: any[]): void @@ -45,15 +49,4 @@ declare namespace wsc { top: any data_type: DataType } - - export class WebSocketClient { - on( - event_name: string, - handler: (event: string) => void, - predicate?: (event: string) => boolean - ): void - close(): Promise - send(user_message: any, opts: wsc.SendOptions): AsyncErrCode - constructor(user_config: wsc.UserConfig) - } } \ No newline at end of file