Socket
Socket
Sign inDemoInstall

wspromisify

Package Overview
Dependencies
0
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.1.17 to 2.2.0

4

dist/src/WS.d.ts

@@ -15,9 +15,9 @@ import './types';

private connect;
readonly socket: any;
get socket(): any;
ready(): Promise<unknown>;
on(event_name: string, handler: (data: any) => any, predicate?: (data: any) => boolean): void;
close(): wsc.AsyncErrCode;
send(message_data: any, opts?: wsc.SendOptions): wsc.AsyncErrCode;
send<DataType = any>(message_data: DataType, opts?: wsc.SendOptions): Promise<DataType>;
constructor(user_config?: wsc.UserConfig);
}
export default WebSocketClient;

@@ -1,1 +0,15 @@

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])})}})})}}
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
function t(t,e,s,o){return new(s||(s=Promise))((function(n,i){function l(t){try{c(o.next(t))}catch(t){i(t)}}function r(t){try{c(o.throw(t))}catch(t){i(t)}}function c(t){t.done?n(t.value):new s((function(e){e(t.value)})).then(l,r)}c((o=o.apply(t,e||[])).next())}))}const e="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",s=e.length-1;const o=(t,e,s)=>t.addEventListener(e,s),n=t=>{let e=!1,s=null;return(...o)=>e?s:(e=!0,s=t(...o))},i=function(e){const s=this.config;this.open=!0,this.onReadyQueue.forEach(t=>t()),this.onReadyQueue.splice(0);const{id_key:n,data_key:i}=s.server;this.messages.forEach(t=>t.send()),null!==this.reconnect_timeout&&(clearInterval(this.reconnect_timeout),this.reconnect_timeout=null),o(e,"close",()=>t(this,void 0,void 0,(function*(){this.log("close"),this.open=!1,this.onCloseQueue.forEach(t=>t()),this.onCloseQueue=[];const e=s.reconnect;if("number"!=typeof e||isNaN(e)||this.forcibly_closed)this.ws=null,this.open=null;else{const s=()=>t(this,void 0,void 0,(function*(){this.log("reconnect"),null!==this.ws&&(this.ws.close(),this.ws=null),null!==(yield this.connect())&&(this.reconnect_timeout=setTimeout(s,1e3*e))}));s()}this.forcibly_closed=!1}))),o(e,"message",t=>{try{const e=s.decode(t.data);if(e[n]){const t=this.queue[e[n]];if(t){const s=t.sent_time?Date.now()-t.sent_time:null;this.log("message",e[i],s),t.ff(e[i]),clearTimeout(t.timeout),delete this.queue[e[n]]}}}catch(e){console.error(e,`WSP: Decode error. Got: ${t.data}`)}})},l=function(t){if(!0===this.open)return t(null);const e=this.config,s=e.socket||e.adapter(e.url,e.protocols);if(this.ws=s,!s||s.readyState>1)return this.ws=null,this.log("error",null,"ready() on closing or closed state! status 2."),t(2);o(s,"error",n(()=>(this.ws=null,this.log("error",null,"status 3."),t(3)))),s.readyState?(i.call(this,s),t(null)):o(s,"open",n(()=>(this.log("open"),i.call(this,s),t(null))))},r={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:s})=>JSON.stringify({[s.id_key]:t,[s.data_key]:e}),decode:t=>JSON.parse(t),protocols:[],pipes:[],server:{id_key:"id",data_key:"data"}},c=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=(t=>{const e=Object.assign({},r,t),s=e.url;if("/"==s[0])try{const t=location.protocol.includes("s:")?"wss":"ws";e.url=`${t}://${location.hostname}:${location.port}${s}`}catch(t){throw new Error("WSP: URL starting with / in non-browser environment!")}return e})(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,s=null){const o=this.config;null!==s?o.log(t,s,e):o.timer?o.log(t,null,e):o.log(t,e)}connect(){return t(this,void 0,void 0,(function*(){return new Promise(t=>{l.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,s){return o(this.ws,t,t=>{s&&!s(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(o,n={}){return t(this,void 0,void 0,(function*(){this.log("send",o);const t=this.config,i={},l=t.server.data_key,r=t.lazy&&!this.open,u=(t=>{const o=[];for(;t>=1;)o.push(e[t%(s+1)]),t=t/s|0;return o.join("")})(Math.random()*(c-10)|0);if("object"==typeof n.top){if(n.top[l])throw new Error("Attempting to set data key/token via send() options!");Object.assign(i,n.top)}if(t.pipes.forEach(t=>o=t(o)),!0===this.open)this.ws.send(t.encode(u,o,t));else if(!1===this.open||r)this.messages.push({send:()=>this.ws.send(t.encode(u,o,t))}),r&&this.connect();else if(null===this.open)throw new Error("Attempting to send via closed WebSocket connection!");return new Promise((e,s)=>{var o,n;this.queue[u]={ff:e,data_type:t.data_type,sent_time:t.timer?Date.now():null,timeout:(o=t.timeout,n=()=>{this.queue[u]&&(s({"Websocket timeout expired: ":t.timeout,"for the message":i}),delete this.queue[u])},setTimeout(n,o))}})}))}}

@@ -1,1 +0,15 @@

"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;
"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */function t(t,e,s,o){return new(s||(s=Promise))((function(n,i){function l(t){try{c(o.next(t))}catch(t){i(t)}}function r(t){try{c(o.throw(t))}catch(t){i(t)}}function c(t){t.done?n(t.value):new s((function(e){e(t.value)})).then(l,r)}c((o=o.apply(t,e||[])).next())}))}const e="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",s=e.length-1;const o=(t,e,s)=>t.addEventListener(e,s),n=t=>{let e=!1,s=null;return(...o)=>e?s:(e=!0,s=t(...o))},i=function(e){const s=this.config;this.open=!0,this.onReadyQueue.forEach(t=>t()),this.onReadyQueue.splice(0);const{id_key:n,data_key:i}=s.server;this.messages.forEach(t=>t.send()),null!==this.reconnect_timeout&&(clearInterval(this.reconnect_timeout),this.reconnect_timeout=null),o(e,"close",()=>t(this,void 0,void 0,(function*(){this.log("close"),this.open=!1,this.onCloseQueue.forEach(t=>t()),this.onCloseQueue=[];const e=s.reconnect;if("number"!=typeof e||isNaN(e)||this.forcibly_closed)this.ws=null,this.open=null;else{const s=()=>t(this,void 0,void 0,(function*(){this.log("reconnect"),null!==this.ws&&(this.ws.close(),this.ws=null),null!==(yield this.connect())&&(this.reconnect_timeout=setTimeout(s,1e3*e))}));s()}this.forcibly_closed=!1}))),o(e,"message",t=>{try{const e=s.decode(t.data);if(e[n]){const t=this.queue[e[n]];if(t){const s=t.sent_time?Date.now()-t.sent_time:null;this.log("message",e[i],s),t.ff(e[i]),clearTimeout(t.timeout),delete this.queue[e[n]]}}}catch(e){console.error(e,`WSP: Decode error. Got: ${t.data}`)}})},l=function(t){if(!0===this.open)return t(null);const e=this.config,s=e.socket||e.adapter(e.url,e.protocols);if(this.ws=s,!s||s.readyState>1)return this.ws=null,this.log("error",null,"ready() on closing or closed state! status 2."),t(2);o(s,"error",n(()=>(this.ws=null,this.log("error",null,"status 3."),t(3)))),s.readyState?(i.call(this,s),t(null)):o(s,"open",n(()=>(this.log("open"),i.call(this,s),t(null))))},r={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:s})=>JSON.stringify({[s.id_key]:t,[s.data_key]:e}),decode:t=>JSON.parse(t),protocols:[],pipes:[],server:{id_key:"id",data_key:"data"}},c=Math.pow(2,31)-1;module.exports=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=(t=>{const e=Object.assign({},r,t),s=e.url;if("/"==s[0])try{const t=location.protocol.includes("s:")?"wss":"ws";e.url=`${t}://${location.hostname}:${location.port}${s}`}catch(t){throw new Error("WSP: URL starting with / in non-browser environment!")}return e})(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,s=null){const o=this.config;null!==s?o.log(t,s,e):o.timer?o.log(t,null,e):o.log(t,e)}connect(){return t(this,void 0,void 0,(function*(){return new Promise(t=>{l.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,s){return o(this.ws,t,t=>{s&&!s(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(o,n={}){return t(this,void 0,void 0,(function*(){this.log("send",o);const t=this.config,i={},l=t.server.data_key,r=t.lazy&&!this.open,u=(t=>{const o=[];for(;t>=1;)o.push(e[t%(s+1)]),t=t/s|0;return o.join("")})(Math.random()*(c-10)|0);if("object"==typeof n.top){if(n.top[l])throw new Error("Attempting to set data key/token via send() options!");Object.assign(i,n.top)}if(t.pipes.forEach(t=>o=t(o)),!0===this.open)this.ws.send(t.encode(u,o,t));else if(!1===this.open||r)this.messages.push({send:()=>this.ws.send(t.encode(u,o,t))}),r&&this.connect();else if(null===this.open)throw new Error("Attempting to send via closed WebSocket connection!");return new Promise((e,s)=>{var o,n;this.queue[u]={ff:e,data_type:t.data_type,sent_time:t.timer?Date.now():null,timeout:(o=t.timeout,n=()=>{this.queue[u]&&(s({"Websocket timeout expired: ":t.timeout,"for the message":i}),delete this.queue[u])},setTimeout(n,o))}})}))}};

@@ -46,3 +46,3 @@ {

},
"version": "2.1.17",
"version": "2.2.0",
"ava": {

@@ -65,30 +65,30 @@ "files": [

"devDependencies": {
"@babel/core": "^7.5.4",
"@babel/polyfill": "^7.4.4",
"@babel/register": "^7.4.4",
"@types/node": "^12.6.2",
"@types/ramda": "^0.26.15",
"@types/ws": "^6.0.1",
"@babel/core": "^7.8.4",
"@babel/polyfill": "^7.8.3",
"@babel/register": "^7.8.3",
"@types/node": "^13.7.0",
"@types/ramda": "^0.26.40",
"@types/ws": "^7.2.1",
"ava": "^2.2.0",
"axios": "^0.19.0",
"codecov": "^3.5.0",
"cross-env": "^5.2.0",
"axios": "^0.19.2",
"codecov": "^3.6.4",
"cross-env": "^7.0.0",
"express": "^4.17.1",
"nyc": "^14.1.1",
"ramda": "^0.26.1",
"nyc": "^15.0.0",
"ramda": "^0.27.0",
"randomatic": "^3.1.1",
"rollup": "^1.16.7",
"rollup": "^1.31.0",
"rollup-plugin-alias": "^1.5.2",
"rollup-plugin-commonjs": "^10.0.1",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-resolve-aliases": "^0.2.0",
"rollup-plugin-terser": "5.1.1",
"rollup-plugin-typescript2": "^0.22.0",
"ts-node": "^8.3.0",
"tslint": "^5.18.0",
"typescript": "^3.5.3",
"ws": "^7.1.0"
"rollup-plugin-terser": "5.2.0",
"rollup-plugin-typescript2": "^0.25.3",
"ts-node": "^8.6.2",
"tslint": "^6.0.0",
"typescript": "^3.7.5",
"ws": "^7.2.1"
},
"types": "./dist/src/WS.d.ts"
}

@@ -116,6 +116,8 @@ # WebsocketPromisify

const ws = new WSP({
// Just a random config. log() is ok.
url: `${somehost}/ws`,
timeout: 2e3,
timer: true,
// If url starts with /,
// it results in ws(s if in https)://currentHost:currentPort/thisUrl
url: 'ws://example.com/ws',
timeout: 2e3, // 1400ms by default.
timer: true, // false by default.
// To log data trips. Events: open, close, send, reconnect, error.
log(event, time, message = '') {

@@ -122,0 +124,0 @@ if(time !== null) {

@@ -38,3 +38,4 @@ import './types'

try {
full_config.url = `${location.hostname}:${location.port}${url}`
const protocol = location.protocol.includes('s:') ? 'wss' : 'ws'
full_config.url = `${protocol}://${location.hostname}:${location.port}${url}`
} catch (e) {

@@ -41,0 +42,0 @@ throw new Error('WSP: URL starting with / in non-browser environment!')

@@ -23,3 +23,3 @@ import './types'

add_event(ws, 'close', async () => {
this.log('Closed.')
this.log('close')
this.open = false

@@ -36,3 +36,3 @@ this.onCloseQueue.forEach((fn: Function) => fn())

const reconnectFunc = async () => {
this.log('Trying to reconnect...')
this.log('reconnect')
if(this.ws !== null) {

@@ -66,3 +66,3 @@ this.ws.close()

const time = q.sent_time ? (Date.now() - q.sent_time) : null
this.log('Message.', data[data_key], time)
this.log('message', data[data_key], time)
// Play.

@@ -75,3 +75,3 @@ q.ff(data[data_key])

} catch (err) {
console.error(err, `Decode error. Got: ${e.data}`)
console.error(err, `WSP: Decode error. Got: ${e.data}`)
}

@@ -89,3 +89,3 @@ })

const config = this.config
const ws = config.socket || config.adapter(`ws://${config.url}`, config.protocols)
const ws = config.socket || config.adapter(config.url, config.protocols)
this.ws = ws

@@ -95,3 +95,3 @@

this.ws = null
this.log('Error: ready() on closing or closed state! Status 2.')
this.log('error', null, 'ready() on closing or closed state! status 2.')
return ff(2)

@@ -102,3 +102,3 @@ }

this.ws = null
this.log('Error status 3.')
this.log('error', null, 'status 3.')
// Some network error: Connection refused or so.

@@ -113,3 +113,3 @@ return ff(3)

add_event(ws, 'open', once(() => {
this.log('Opened.')
this.log('open')
init.call(this, ws)

@@ -116,0 +116,0 @@ return ff(null)

@@ -34,3 +34,2 @@

const config = this.config
event = `WSP: ${event}`
if(time !== null) {

@@ -96,4 +95,7 @@ config.log(event, time, message)

public async send(message_data: any, opts = <wsc.SendOptions>{}): wsc.AsyncErrCode {
this.log('Send.', message_data)
public async send<DataType = any>(
message_data: DataType,
opts = <wsc.SendOptions>{}
): Promise<DataType> {
this.log('send', message_data)
const config = this.config

@@ -100,0 +102,0 @@ const message = {}

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc