From 6d5501ce84e2cf03f50ef5f40a2f281afd5ececf Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 2 Feb 2019 16:24:22 +0300 Subject: [PATCH] 2.0.0: types & structure. --- dist/src/SHA1.d.ts | 2 + dist/src/WS.d.ts | 22 ++++++ dist/src/connectLib.d.ts | 3 + dist/src/types.d.ts | 46 ++++++++++++ dist/src/utils.d.ts | 4 + dist/ws.esm.js.map | 2 +- dist/ws.js.map | 2 +- package-lock.json | 95 ++++++++++++++++-------- package.json | 16 ++-- src/rollup.config.js => rollup.config.js | 2 +- src/{SHA1.js => SHA1.ts} | 9 ++- src/WS.ts | 30 +++++--- src/connectLib.ts | 10 +-- types.d.ts => src/types.ts | 13 +--- src/utils.ts | 9 +-- src/tsconfig.json => tsconfig.json | 16 ++-- 16 files changed, 195 insertions(+), 86 deletions(-) create mode 100644 dist/src/SHA1.d.ts create mode 100644 dist/src/WS.d.ts create mode 100644 dist/src/connectLib.d.ts create mode 100644 dist/src/types.d.ts create mode 100644 dist/src/utils.d.ts rename src/rollup.config.js => rollup.config.js (95%) rename src/{SHA1.js => SHA1.ts} (74%) rename types.d.ts => src/types.ts (94%) rename src/tsconfig.json => tsconfig.json (57%) diff --git a/dist/src/SHA1.d.ts b/dist/src/SHA1.d.ts new file mode 100644 index 0000000..257fc4f --- /dev/null +++ b/dist/src/SHA1.d.ts @@ -0,0 +1,2 @@ +declare const _default: (str1: string) => string; +export default _default; diff --git a/dist/src/WS.d.ts b/dist/src/WS.d.ts new file mode 100644 index 0000000..8a465cd --- /dev/null +++ b/dist/src/WS.d.ts @@ -0,0 +1,22 @@ +import "./types"; +declare class WebSocketClient implements wsc.WebSocketClient { + private open; + private ws; + private forcibly_closed; + private reconnect_timeout; + private queue; + private messages; + private onReadyQueue; + private onCloseQueue; + private config; + private init_flush; + private log; + private connect; + readonly socket: any; + ready(): Promise<{}>; + 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; + constructor(user_config?: wsc.UserConfig); +} +export default WebSocketClient; diff --git a/dist/src/connectLib.d.ts b/dist/src/connectLib.d.ts new file mode 100644 index 0000000..3090056 --- /dev/null +++ b/dist/src/connectLib.d.ts @@ -0,0 +1,3 @@ +import "./types"; +declare const connectLib: (ff: any) => any; +export default connectLib; diff --git a/dist/src/types.d.ts b/dist/src/types.d.ts new file mode 100644 index 0000000..ff015ee --- /dev/null +++ b/dist/src/types.d.ts @@ -0,0 +1,46 @@ +declare namespace wsc { + /** Stuff that in use by this lib. */ + interface Socket { + readyState: number; + send(...any: any[]): void; + close(): void; + addEventListener(event: string, handler: ((event: any) => any), ...any: any[]): void; + } + type AsyncErrCode = Promise; + type EventHandler = (e: any) => void; + type DataPipe = (message: any) => any; + type DataType = 'json' | 'string'; + interface Config { + data_type: DataType; + log(event: string, time?: number, message?: any): void; + log(event: string, message?: any): void; + timer: boolean; + url: string; + timeout: number; + reconnect: number; + lazy: boolean; + socket: Socket; + adapter: (host: string, protocols?: string[]) => Socket; + encode: (key: string, message: any, config: Config) => any; + decode: (rawMessage: any) => { + [id_or_data_key: string]: string; + }; + protocols: string[]; + pipes: DataPipe[]; + server: { + id_key: string; + data_key: string; + }; + } + type UserConfig = Partial; + interface SendOptions { + 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/src/utils.d.ts b/dist/src/utils.d.ts new file mode 100644 index 0000000..7ea15ca --- /dev/null +++ b/dist/src/utils.d.ts @@ -0,0 +1,4 @@ +import "./types"; +declare const add_event: (o: wsc.Socket, e: string, handler: wsc.EventHandler) => void; +declare const once: (fn: Function) => (...args: any) => any; +export { add_event, once, }; diff --git a/dist/ws.esm.js.map b/dist/ws.esm.js.map index 8d4ea77..6d97302 100644 --- a/dist/ws.esm.js.map +++ b/dist/ws.esm.js.map @@ -1 +1 @@ -{"version":3,"file":"ws.esm.js","sources":["../node_modules/tslib/tslib.es6.js","../src/SHA1.js"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation. All rights reserved.\r\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use\r\nthis file except in compliance with the License. You may obtain a copy of the\r\nLicense at http://www.apache.org/licenses/LICENSE-2.0\r\n\r\nTHIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r\nKIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED\r\nWARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,\r\nMERCHANTABLITY OR NON-INFRINGEMENT.\r\n\r\nSee the Apache Version 2.0 License for specific language governing permissions\r\nand limitations under the License.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\r\n\r\nexport function __extends(d, b) {\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)\r\n t[p[i]] = s[p[i]];\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [0, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport function __exportStar(m, exports) {\r\n for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];\r\n}\r\n\r\nexport function __values(o) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator], i = 0;\r\n if (m) return m.call(o);\r\n return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { if (o[n]) i[n] = function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; }; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator];\r\n return m ? m.call(o) : typeof __values === \"function\" ? __values(o) : o[Symbol.iterator]();\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n","\r\n// SHA1 has been taken from https://github.com/jbt/js-crypto\r\n// Thank you, James, for this tiny implementation!\r\n\r\nexport default (str1) => {\r\n for (\r\n var blockstart = 0,\r\n i = 0,\r\n W = [],\r\n A, B, C, D, F, G,\r\n H = [A=0x67452301, B=0xEFCDAB89, ~A, ~B, 0xC3D2E1F0],\r\n word_array = [],\r\n temp2,\r\n s = unescape(encodeURI(str1)),\r\n str_len = s.length;\r\n\r\n i <= str_len;\r\n ){\r\n word_array[i >> 2] |= (s.charCodeAt(i)||128) << (8 * (3 - i++ % 4));\r\n }\r\n word_array[temp2 = ((str_len + 8) >> 2) | 15] = str_len << 3;\r\n\r\n for (; blockstart <= temp2; blockstart += 16) {\r\n A = H; i = 0;\r\n\r\n for (; i < 80;\r\n A = [[\r\n (G = ((s = A[0]) << 5 | s >>> 27) + A[4] + (W[i] = (i<16) ? ~~word_array[blockstart + i] : G << 1 | G >>> 31) + 1518500249) + ((B = A[1]) & (C = A[2]) | ~B & (D = A[3])),\r\n F = G + (B ^ C ^ D) + 341275144,\r\n G + (B & C | B & D | C & D) + 882459459,\r\n F + 1535694389\r\n ][0|((i++) / 20)] | 0, s, B << 30 | B >>> 2, C, D]\r\n ) {\r\n G = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];\r\n }\r\n\r\n for(i = 5; i; ) H[--i] = H[i] + A[i] | 0;\r\n }\r\n\r\n for(str1 = ''; i < 40; )str1 += (H[i >> 3] >> (7 - i++ % 8) * 4 & 15).toString(16);\r\n return str1;\r\n}"],"names":["__awaiter","thisArg","_arguments","P","generator","Promise","resolve","reject","fulfilled","value","step","next","e","rejected","result","done","then","apply","str1","A","B","C","D","F","G","temp2","blockstart","i","W","H","word_array","s","unescape","encodeURI","str_len","length","charCodeAt","toString"],"mappings":"AA2DA,SAAgBA,UAAUC,EAASC,EAAYC,EAAGC,GAC9C,OAAO,IAAKD,IAAMA,EAAIE,UAAU,SAAUC,EAASC,GAC/C,SAASC,EAAUC,GAAS,IAAMC,EAAKN,EAAUO,KAAKF,IAAW,MAAOG,GAAKL,EAAOK,IACpF,SAASC,EAASJ,GAAS,IAAMC,EAAKN,EAAiB,MAAEK,IAAW,MAAOG,GAAKL,EAAOK,IACvF,SAASF,EAAKI,GAAUA,EAAOC,KAAOT,EAAQQ,EAAOL,OAAS,IAAIN,EAAE,SAAUG,GAAWA,EAAQQ,EAAOL,SAAWO,KAAKR,EAAWK,GACnIH,GAAMN,EAAYA,EAAUa,MAAMhB,EAASC,QAAmBS,UC5DtE,SAAgBO,IACd,IACE,IAGEC,EAAGC,EAAGC,EAAGC,EAAGC,EAAGC,EAGfC,EANEC,EAAa,EACfC,EAAI,EACJC,KAEAC,GAAKV,EAAE,WAAYC,EAAE,YAAaD,GAAIC,EAAG,YACzCU,KAEAC,EAAIC,SAASC,UAAUf,IACvBgB,EAAUH,EAAEI,OAEdR,GAAKO,GAELJ,EAAWH,GAAK,KAAOI,EAAEK,WAAWT,IAAI,MAAS,GAAK,EAAIA,IAAM,GAIlE,IAFAG,EAAWL,EAAUS,EAAU,GAAM,EAAK,IAAMA,GAAW,EAEpDR,GAAcD,EAAOC,GAAc,GAAI,CAG5C,IAFAP,EAAIU,EAAGF,EAAI,EAEJA,EAAI,GACTR,GAKoB,IAJjBK,IAAMO,EAAIZ,EAAE,KAAO,EAAIY,IAAM,IAAMZ,EAAE,IAAMS,EAAED,GAAMA,EAAE,KAAQG,EAAWJ,EAAaC,GAAKH,GAAK,EAAIA,IAAM,IAAM,cAAgBJ,EAAID,EAAE,KAAOE,EAAIF,EAAE,KAAOC,GAAKE,EAAIH,EAAE,KACrKI,EAAIC,GAAKJ,EAAIC,EAAIC,GAAK,UACtBE,GAAKJ,EAAIC,EAAID,EAAIE,EAAID,EAAIC,GAAK,UAC9BC,EAAI,YACJ,EAAII,IAAO,IAAUI,EAAGX,GAAK,GAAKA,IAAM,EAAGC,EAAGC,GAEhDE,EAAII,EAAED,EAAI,GAAKC,EAAED,EAAI,GAAKC,EAAED,EAAI,IAAMC,EAAED,EAAI,IAG9C,IAAIA,EAAI,EAAGA,GAAKE,IAAIF,GAAKE,EAAEF,GAAKR,EAAEQ,GAAK,EAGzC,IAAIT,EAAO,GAAIS,EAAI,IAAKT,IAASW,EAAEF,GAAK,IAAsB,GAAf,EAAIA,IAAM,GAAS,IAAIU,SAAS,IAC/E,OAAOnB"} \ No newline at end of file +{"version":3,"file":"ws.esm.js","sources":["../node_modules/tslib/tslib.es6.js"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation. All rights reserved.\r\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use\r\nthis file except in compliance with the License. You may obtain a copy of the\r\nLicense at http://www.apache.org/licenses/LICENSE-2.0\r\n\r\nTHIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r\nKIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED\r\nWARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,\r\nMERCHANTABLITY OR NON-INFRINGEMENT.\r\n\r\nSee the Apache Version 2.0 License for specific language governing permissions\r\nand limitations under the License.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\r\n\r\nexport function __extends(d, b) {\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)\r\n t[p[i]] = s[p[i]];\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [0, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport function __exportStar(m, exports) {\r\n for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];\r\n}\r\n\r\nexport function __values(o) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator], i = 0;\r\n if (m) return m.call(o);\r\n return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { if (o[n]) i[n] = function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; }; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator];\r\n return m ? m.call(o) : typeof __values === \"function\" ? __values(o) : o[Symbol.iterator]();\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n"],"names":["__awaiter","thisArg","_arguments","P","generator","Promise","resolve","reject","fulfilled","value","step","next","e","rejected","result","done","then","apply"],"mappings":"AA2DA,SAAgBA,UAAUC,EAASC,EAAYC,EAAGC,GAC9C,OAAO,IAAKD,IAAMA,EAAIE,UAAU,SAAUC,EAASC,GAC/C,SAASC,EAAUC,GAAS,IAAMC,EAAKN,EAAUO,KAAKF,IAAW,MAAOG,GAAKL,EAAOK,IACpF,SAASC,EAASJ,GAAS,IAAMC,EAAKN,EAAiB,MAAEK,IAAW,MAAOG,GAAKL,EAAOK,IACvF,SAASF,EAAKI,GAAUA,EAAOC,KAAOT,EAAQQ,EAAOL,OAAS,IAAIN,EAAE,SAAUG,GAAWA,EAAQQ,EAAOL,SAAWO,KAAKR,EAAWK,GACnIH,GAAMN,EAAYA,EAAUa,MAAMhB,EAASC,QAAmBS"} \ No newline at end of file diff --git a/dist/ws.js.map b/dist/ws.js.map index 3898915..377302b 100644 --- a/dist/ws.js.map +++ b/dist/ws.js.map @@ -1 +1 @@ -{"version":3,"file":"ws.js","sources":["../node_modules/tslib/tslib.es6.js","../src/SHA1.js"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation. All rights reserved.\r\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use\r\nthis file except in compliance with the License. You may obtain a copy of the\r\nLicense at http://www.apache.org/licenses/LICENSE-2.0\r\n\r\nTHIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r\nKIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED\r\nWARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,\r\nMERCHANTABLITY OR NON-INFRINGEMENT.\r\n\r\nSee the Apache Version 2.0 License for specific language governing permissions\r\nand limitations under the License.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\r\n\r\nexport function __extends(d, b) {\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)\r\n t[p[i]] = s[p[i]];\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [0, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport function __exportStar(m, exports) {\r\n for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];\r\n}\r\n\r\nexport function __values(o) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator], i = 0;\r\n if (m) return m.call(o);\r\n return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { if (o[n]) i[n] = function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; }; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator];\r\n return m ? m.call(o) : typeof __values === \"function\" ? __values(o) : o[Symbol.iterator]();\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n","\n// SHA1 has been taken from https://github.com/jbt/js-crypto\n// Thank you, James, for this tiny implementation!\n\nexport default (str1) => {\n for (\n var blockstart = 0,\n i = 0,\n W = [],\n A, B, C, D, F, G,\n H = [A=0x67452301, B=0xEFCDAB89, ~A, ~B, 0xC3D2E1F0],\n word_array = [],\n temp2,\n s = unescape(encodeURI(str1)),\n str_len = s.length;\n\n i <= str_len;\n ){\n word_array[i >> 2] |= (s.charCodeAt(i)||128) << (8 * (3 - i++ % 4));\n }\n word_array[temp2 = ((str_len + 8) >> 2) | 15] = str_len << 3;\n\n for (; blockstart <= temp2; blockstart += 16) {\n A = H; i = 0;\n\n for (; i < 80;\n A = [[\n (G = ((s = A[0]) << 5 | s >>> 27) + A[4] + (W[i] = (i<16) ? ~~word_array[blockstart + i] : G << 1 | G >>> 31) + 1518500249) + ((B = A[1]) & (C = A[2]) | ~B & (D = A[3])),\n F = G + (B ^ C ^ D) + 341275144,\n G + (B & C | B & D | C & D) + 882459459,\n F + 1535694389\n ][0|((i++) / 20)] | 0, s, B << 30 | B >>> 2, C, D]\n ) {\n G = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];\n }\n\n for(i = 5; i; ) H[--i] = H[i] + A[i] | 0;\n }\n\n for(str1 = ''; i < 40; )str1 += (H[i >> 3] >> (7 - i++ % 8) * 4 & 15).toString(16);\n return str1;\n}"],"names":["__awaiter","thisArg","_arguments","P","generator","Promise","resolve","reject","fulfilled","value","step","next","e","rejected","result","done","then","apply","str1","A","B","C","D","F","G","temp2","blockstart","i","W","H","word_array","s","unescape","encodeURI","str_len","length","charCodeAt","toString"],"mappings":"aA2DA,SAAgBA,UAAUC,EAASC,EAAYC,EAAGC,GAC9C,OAAO,IAAKD,IAAMA,EAAIE,UAAU,SAAUC,EAASC,GAC/C,SAASC,EAAUC,GAAS,IAAMC,EAAKN,EAAUO,KAAKF,IAAW,MAAOG,GAAKL,EAAOK,IACpF,SAASC,EAASJ,GAAS,IAAMC,EAAKN,EAAiB,MAAEK,IAAW,MAAOG,GAAKL,EAAOK,IACvF,SAASF,EAAKI,GAAUA,EAAOC,KAAOT,EAAQQ,EAAOL,OAAS,IAAIN,EAAE,SAAUG,GAAWA,EAAQQ,EAAOL,SAAWO,KAAKR,EAAWK,GACnIH,GAAMN,EAAYA,EAAUa,MAAMhB,EAASC,QAAmBS,UC5DtE,SAAgBO,IACd,IACE,IAGEC,EAAGC,EAAGC,EAAGC,EAAGC,EAAGC,EAGfC,EANEC,EAAa,EACfC,EAAI,EACJC,KAEAC,GAAKV,EAAE,WAAYC,EAAE,YAAaD,GAAIC,EAAG,YACzCU,KAEAC,EAAIC,SAASC,UAAUf,IACvBgB,EAAUH,EAAEI,OAEdR,GAAKO,GAELJ,EAAWH,GAAK,KAAOI,EAAEK,WAAWT,IAAI,MAAS,GAAK,EAAIA,IAAM,GAIlE,IAFAG,EAAWL,EAAUS,EAAU,GAAM,EAAK,IAAMA,GAAW,EAEpDR,GAAcD,EAAOC,GAAc,GAAI,CAG5C,IAFAP,EAAIU,EAAGF,EAAI,EAEJA,EAAI,GACTR,GAKoB,IAJjBK,IAAMO,EAAIZ,EAAE,KAAO,EAAIY,IAAM,IAAMZ,EAAE,IAAMS,EAAED,GAAMA,EAAE,KAAQG,EAAWJ,EAAaC,GAAKH,GAAK,EAAIA,IAAM,IAAM,cAAgBJ,EAAID,EAAE,KAAOE,EAAIF,EAAE,KAAOC,GAAKE,EAAIH,EAAE,KACrKI,EAAIC,GAAKJ,EAAIC,EAAIC,GAAK,UACtBE,GAAKJ,EAAIC,EAAID,EAAIE,EAAID,EAAIC,GAAK,UAC9BC,EAAI,YACJ,EAAII,IAAO,IAAUI,EAAGX,GAAK,GAAKA,IAAM,EAAGC,EAAGC,GAEhDE,EAAII,EAAED,EAAI,GAAKC,EAAED,EAAI,GAAKC,EAAED,EAAI,IAAMC,EAAED,EAAI,IAG9C,IAAIA,EAAI,EAAGA,GAAKE,IAAIF,GAAKE,EAAEF,GAAKR,EAAEQ,GAAK,EAGzC,IAAIT,EAAO,GAAIS,EAAI,IAAKT,IAASW,EAAEF,GAAK,IAAsB,GAAf,EAAIA,IAAM,GAAS,IAAIU,SAAS,IAC/E,OAAOnB"} \ No newline at end of file +{"version":3,"file":"ws.js","sources":["../node_modules/tslib/tslib.es6.js"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation. All rights reserved.\r\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use\r\nthis file except in compliance with the License. You may obtain a copy of the\r\nLicense at http://www.apache.org/licenses/LICENSE-2.0\r\n\r\nTHIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r\nKIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED\r\nWARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,\r\nMERCHANTABLITY OR NON-INFRINGEMENT.\r\n\r\nSee the Apache Version 2.0 License for specific language governing permissions\r\nand limitations under the License.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\r\n\r\nexport function __extends(d, b) {\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)\r\n t[p[i]] = s[p[i]];\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [0, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport function __exportStar(m, exports) {\r\n for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];\r\n}\r\n\r\nexport function __values(o) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator], i = 0;\r\n if (m) return m.call(o);\r\n return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { if (o[n]) i[n] = function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; }; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator];\r\n return m ? m.call(o) : typeof __values === \"function\" ? __values(o) : o[Symbol.iterator]();\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n"],"names":["__awaiter","thisArg","_arguments","P","generator","Promise","resolve","reject","fulfilled","value","step","next","e","rejected","result","done","then","apply"],"mappings":"aA2DA,SAAgBA,UAAUC,EAASC,EAAYC,EAAGC,GAC9C,OAAO,IAAKD,IAAMA,EAAIE,UAAU,SAAUC,EAASC,GAC/C,SAASC,EAAUC,GAAS,IAAMC,EAAKN,EAAUO,KAAKF,IAAW,MAAOG,GAAKL,EAAOK,IACpF,SAASC,EAASJ,GAAS,IAAMC,EAAKN,EAAiB,MAAEK,IAAW,MAAOG,GAAKL,EAAOK,IACvF,SAASF,EAAKI,GAAUA,EAAOC,KAAOT,EAAQQ,EAAOL,OAAS,IAAIN,EAAE,SAAUG,GAAWA,EAAQQ,EAAOL,SAAWO,KAAKR,EAAWK,GACnIH,GAAMN,EAAYA,EAAUa,MAAMhB,EAASC,QAAmBS"} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 1ebdc93..421977d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "wspromisify", - "version": "1.1.2", + "version": "1.1.3", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -2144,6 +2144,49 @@ "randomatic": "^1.1.3", "repeat-element": "^1.1.2", "repeat-string": "^1.5.2" + }, + "dependencies": { + "randomatic": { + "version": "1.1.7", + "resolved": "https://registry.npmjs.org/randomatic/-/randomatic-1.1.7.tgz", + "integrity": "sha512-D5JUjPyJbaJDkuAazpVnSfVkLlpeO3wDlPROTMLGKG1zMFNFRgrciKo1ltz/AzNTkqE0HzDx655QOL51N06how==", + "dev": true, + "requires": { + "is-number": "^3.0.0", + "kind-of": "^4.0.0" + }, + "dependencies": { + "is-number": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-3.0.0.tgz", + "integrity": "sha1-JP1iAaR4LPUFYcgQJ2r8fRLXEZU=", + "dev": true, + "requires": { + "kind-of": "^3.0.2" + }, + "dependencies": { + "kind-of": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", + "integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=", + "dev": true, + "requires": { + "is-buffer": "^1.1.5" + } + } + } + } + } + } + } + }, + "kind-of": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-4.0.0.tgz", + "integrity": "sha1-IIE989cSkosgc3hpGkUGb65y3Vc=", + "dev": true, + "requires": { + "is-buffer": "^1.1.5" } } } @@ -3705,6 +3748,12 @@ "escape-string-regexp": "^1.0.4" } }, + "math-random": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/math-random/-/math-random-1.0.1.tgz", + "integrity": "sha1-izqsWIuKZuSXXjzepn97sylgH6w=", + "dev": true + }, "md5-hex": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/md5-hex/-/md5-hex-2.0.0.tgz", @@ -4456,43 +4505,27 @@ "dev": true }, "randomatic": { - "version": "1.1.7", - "resolved": "https://registry.npmjs.org/randomatic/-/randomatic-1.1.7.tgz", - "integrity": "sha512-D5JUjPyJbaJDkuAazpVnSfVkLlpeO3wDlPROTMLGKG1zMFNFRgrciKo1ltz/AzNTkqE0HzDx655QOL51N06how==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/randomatic/-/randomatic-3.1.1.tgz", + "integrity": "sha512-TuDE5KxZ0J461RVjrJZCJc+J+zCkTb1MbH9AQUq68sMhOMcy9jLcb3BrZKgp9q9Ncltdg4QVqWrH02W2EFFVYw==", "dev": true, "requires": { - "is-number": "^3.0.0", - "kind-of": "^4.0.0" + "is-number": "^4.0.0", + "kind-of": "^6.0.0", + "math-random": "^1.0.1" }, "dependencies": { "is-number": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-number/-/is-number-3.0.0.tgz", - "integrity": "sha1-JP1iAaR4LPUFYcgQJ2r8fRLXEZU=", - "dev": true, - "requires": { - "kind-of": "^3.0.2" - }, - "dependencies": { - "kind-of": { - "version": "3.2.2", - "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", - "integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=", - "dev": true, - "requires": { - "is-buffer": "^1.1.5" - } - } - } + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-4.0.0.tgz", + "integrity": "sha512-rSklcAIlf1OmFdyAqbnWTLVelsQ58uvZ66S/ZyawjWqIviTWCjg2PzVGw8WUA+nNuPTqb4wgA+NszrJ+08LlgQ==", + "dev": true }, "kind-of": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-4.0.0.tgz", - "integrity": "sha1-IIE989cSkosgc3hpGkUGb65y3Vc=", - "dev": true, - "requires": { - "is-buffer": "^1.1.5" - } + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz", + "integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==", + "dev": true } } }, diff --git a/package.json b/package.json index 7ac36fc..af90819 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "Easy", "realtime", "Middleware", + "JSON", "Data", "transport", "API", @@ -34,15 +35,15 @@ }, "scripts": { "lint": "./node_modules/.bin/tslint 'src/**/*.ts'", - "test": "npm run test:compile && npm run test:exec", + "test": "npm run prod:es && npm run test:compile && npm run test:exec", "test:compile": "./node_modules/.bin/tsc -p ./test/", - "test:exec": "npm run prod:es && ./node_modules/.bin/ava ./test/dist/test/src/index.js", - "dev": "rollup --watch -c --config src/rollup.config.js --environment INCLUDE_DEPS,BUILD:development", - "prod:cjs": "rollup -c --config src/rollup.config.js --environment INCLUDE_DEPS,BUILD:cjs", - "prod:es": "rollup -c --config src/rollup.config.js --environment INCLUDE_DEPS,BUILD:es", + "test:exec": "./node_modules/.bin/ava ./test/dist/test/src/index.js", + "dev": "rollup --watch -c --config rollup.config.js --environment INCLUDE_DEPS,BUILD:development", + "prod:cjs": "rollup -c --config rollup.config.js --environment INCLUDE_DEPS,BUILD:cjs", + "prod:es": "rollup -c --config rollup.config.js --environment INCLUDE_DEPS,BUILD:es", "prod": "npm run prod:es && npm run prod:cjs" }, - "version": "1.1.3", + "version": "2.0.0", "devDependencies": { "@types/node": "^8.0.58", "@types/ramda": "^0.25.8", @@ -51,6 +52,7 @@ "axios": "^0.17.1", "express": "^4.16.2", "ramda": "^0.25.0", + "randomatic": "^3.1.1", "rollup": "^0.52.1", "rollup-plugin-alias": "^1.4.0", "rollup-plugin-commonjs": "^8.2.6", @@ -63,5 +65,5 @@ "uglify-es": "^3.3.9", "ws": "^3.3.2" }, - "types": "./index.d.ts" + "types": "./dist/src/WS.d.ts" } diff --git a/src/rollup.config.js b/rollup.config.js similarity index 95% rename from src/rollup.config.js rename to rollup.config.js index f6b4521..22fa4c5 100644 --- a/src/rollup.config.js +++ b/rollup.config.js @@ -17,7 +17,7 @@ export default { commonjs(), typescript({ typescript: require("typescript"), - tsconfig: "./src/tsconfig.json", + tsconfig: "./tsconfig.json", tsconfigOverride: { compilerOptions: { sourceMap: false, diff --git a/src/SHA1.js b/src/SHA1.ts similarity index 74% rename from src/SHA1.js rename to src/SHA1.ts index c0bca7e..c26f193 100644 --- a/src/SHA1.js +++ b/src/SHA1.ts @@ -2,15 +2,16 @@ // SHA1 has been taken from https://github.com/jbt/js-crypto // Thank you, James, for this tiny implementation! -export default (str1) => { +export default (str1: string) => { for ( var blockstart = 0, i = 0, W = [], - A, B, C, D, F, G, + A: number | any[] | number[], + B: number, C: number, D: number, F: number, G: number, H = [A=0x67452301, B=0xEFCDAB89, ~A, ~B, 0xC3D2E1F0], word_array = [], - temp2, + temp2: number, s = unescape(encodeURI(str1)), str_len = s.length; @@ -25,7 +26,7 @@ export default (str1) => { for (; i < 80; A = [[ - (G = ((s = A[0]) << 5 | s >>> 27) + A[4] + (W[i] = (i<16) ? ~~word_array[blockstart + i] : G << 1 | G >>> 31) + 1518500249) + ((B = A[1]) & (C = A[2]) | ~B & (D = A[3])), + (G = ((s = A[0]) << 5 | (s as any >>> 27)) + A[4] + (W[i] = (i<16) ? ~~word_array[blockstart + i] : G << 1 | G >>> 31) + 1518500249) + ((B = A[1]) & (C = A[2]) | ~B & (D = A[3])), F = G + (B ^ C ^ D) + 341275144, G + (B & C | B & D | C & D) + 882459459, F + 1535694389 diff --git a/src/WS.ts b/src/WS.ts index 69947e4..63f1c47 100644 --- a/src/WS.ts +++ b/src/WS.ts @@ -1,18 +1,20 @@ -import SHA1 from './SHA1.js' -import * as types from '../types' +import SHA1 from './SHA1' import connectLib from './connectLib' import { add_event } from './utils' +import "./types" /* .send(your_data) wraps request to server with {id: `hash`, data: `actually your data`}, returns a Promise, that will be rejected after a timeout or resolved if server returns the same signature: {id: `same_hash`, data: `response data`} */ +const sett = ( + a: number, + b: { (): void; (...args: any[]): void; } +) => setTimeout(b, a) -const sett = (a, b) => setTimeout(b, a) - -const default_config = { +const default_config = { data_type: 'json', // ToDo some other stuff maybe. // Debug features. log: ((event = '', time = 0, message = '') => null), @@ -38,7 +40,7 @@ const default_config = { } -class WebSocketClient implements types.WebSocketClient { +class WebSocketClient implements wsc.WebSocketClient { private open = null private ws = null @@ -48,7 +50,7 @@ class WebSocketClient implements types.WebSocketClient { private messages = [] private onReadyQueue = [] private onCloseQueue = [] - private config = {} + private config = {} private init_flush(): void { this.queue = {} // data queuse @@ -89,7 +91,11 @@ class WebSocketClient implements types.WebSocketClient { }) } - public on(event_name, handler, predicate?) { + public on( + event_name: string, + handler: (data: any) => any, + predicate?: (data: any) => boolean + ) { return add_event(this.ws, event_name, event => { if(!predicate || predicate(event)) { handler(event) @@ -97,7 +103,7 @@ class WebSocketClient implements types.WebSocketClient { }) } - public async close(): types.AsyncErrCode { + public async close(): wsc.AsyncErrCode { return new Promise((ff, rj) => { if(this.ws === null) { rj('WSP: closing a non-inited socket!') @@ -114,7 +120,7 @@ class WebSocketClient implements types.WebSocketClient { }) } - public async send(message_data, opts = {}): types.AsyncErrCode { + public async send(message_data: any, opts = {}): wsc.AsyncErrCode { this.log('Send.', message_data) const config = this.config const message = {} @@ -166,9 +172,9 @@ class WebSocketClient implements types.WebSocketClient { } - constructor(user_config = {}) { + constructor(user_config: wsc.UserConfig = {}) { // Config. - const config = {} as types.Config + const config = {} as wsc.Config Object.assign(config, default_config) Object.assign(config, user_config) this.config = config diff --git a/src/connectLib.ts b/src/connectLib.ts index fb20d42..572a7ea 100644 --- a/src/connectLib.ts +++ b/src/connectLib.ts @@ -1,20 +1,18 @@ - -import * as types from '../types' - +import "./types" import { once, add_event } from './utils' -const init = function(ws: types.Socket) { +const init = function(ws: wsc.Socket) { const config = this.config this.open = true - this.onReadyQueue.forEach((fn) => fn()) + this.onReadyQueue.forEach((fn: Function) => fn()) this.onReadyQueue = [] const {id_key, data_key} = config.server // Send all pending messages. - this.messages.forEach((message) => message.send()) + this.messages.forEach((message: any) => message.send()) // It's reconnecting. if(this.reconnect_timeout !== null) { clearInterval(this.reconnect_timeout) diff --git a/types.d.ts b/src/types.ts similarity index 94% rename from types.d.ts rename to src/types.ts index 5f8fa43..9464c4d 100644 --- a/types.d.ts +++ b/src/types.ts @@ -1,16 +1,11 @@ - - -export = wsc - - declare namespace wsc { /** Stuff that in use by this lib. */ interface Socket { readyState: number - send(...any: any[]) - close() - addEventListener(event: string, handler: ((event: any) => any), ...any: any[]) + send(...any: any[]): void + close(): void + addEventListener(event: string, handler: ((event: any) => any), ...any: any[]): void } export type AsyncErrCode = Promise @@ -56,7 +51,7 @@ declare namespace wsc { 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/src/utils.ts b/src/utils.ts index 65aeb1d..4536637 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,15 +1,14 @@ -import * as types from '../types' +import "./types" - -const add_event = (o: types.Socket, e: string, handler: types.EventHandler) => { +const add_event = (o: wsc.Socket, e: string, handler: wsc.EventHandler) => { return o.addEventListener(e, handler) } -const once = (fn) => { +const once = (fn: Function) => { let has_been_cached = false let cached = null - return (...args) => { + return (...args: any) => { if(has_been_cached) { return cached } else { diff --git a/src/tsconfig.json b/tsconfig.json similarity index 57% rename from src/tsconfig.json rename to tsconfig.json index bd7937a..80d308f 100644 --- a/src/tsconfig.json +++ b/tsconfig.json @@ -2,22 +2,20 @@ "compilerOptions": { "lib": [ "dom", - "es2017" + "esnext" ], "target":"es2015", - "allowJs": true, + "allowJs": false, "sourceMap": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "noUnusedLocals": false, - "outDir": "../dist/", - "rootDir": "./", - "baseUrl": "./", - "paths": { - "utils": ["./utils"] - } + "outDir": "./dist/", + "declaration": true, + "rootDir": ".", + "baseUrl": "." }, "include": [ - "./WS.ts" + "./src/WS.ts" ] } \ No newline at end of file