koa-ws-socket
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -114,2 +114,67 @@ import { Server } from 'ws'; | ||
/*! ***************************************************************************** | ||
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. | ||
***************************************************************************** */ | ||
/* global Reflect, Promise */ | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
} | ||
function __generator(thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
} | ||
var Socket = /** @class */ (function () { | ||
@@ -147,10 +212,17 @@ function Socket(ws, request, listeners, middleware) { | ||
}; | ||
if (!_this.middleware) { | ||
_this.invokeHandler(handler, ctx, message); | ||
}); | ||
}; | ||
Socket.prototype.invokeHandler = function (handler, ctx, message) { | ||
var _this = this; | ||
if (!this.middleware) { | ||
handler(ctx, message); | ||
return; | ||
} | ||
this.middleware(ctx, function () { return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
handler(ctx, message); | ||
return; | ||
} | ||
_this.middleware(ctx).then(function () { | ||
handler(ctx, message); | ||
return [2 /*return*/]; | ||
}); | ||
}); | ||
}); }); | ||
}; | ||
@@ -157,0 +229,0 @@ return Socket; |
@@ -119,2 +119,67 @@ (function (global, factory) { | ||
/*! ***************************************************************************** | ||
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. | ||
***************************************************************************** */ | ||
/* global Reflect, Promise */ | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
} | ||
function __generator(thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
} | ||
var Socket = /** @class */ (function () { | ||
@@ -152,10 +217,17 @@ function Socket(ws, request, listeners, middleware) { | ||
}; | ||
if (!_this.middleware) { | ||
_this.invokeHandler(handler, ctx, message); | ||
}); | ||
}; | ||
Socket.prototype.invokeHandler = function (handler, ctx, message) { | ||
var _this = this; | ||
if (!this.middleware) { | ||
handler(ctx, message); | ||
return; | ||
} | ||
this.middleware(ctx, function () { return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
handler(ctx, message); | ||
return; | ||
} | ||
_this.middleware(ctx).then(function () { | ||
handler(ctx, message); | ||
return [2 /*return*/]; | ||
}); | ||
}); | ||
}); }); | ||
}; | ||
@@ -162,0 +234,0 @@ return Socket; |
@@ -18,2 +18,3 @@ /// <reference types="koa-compose" /> | ||
on(event: string, handler: EventHandler): void; | ||
invokeHandler(handler: EventHandler, ctx: SocketContext, message: any): void; | ||
} |
@@ -1,1 +0,1 @@ | ||
{"name":"koa-ws-socket","version":"1.0.0","description":"Attaches ws sockets to koa using koa-style middleware","files":["dist"],"main":"dist/koa-ws-socket.umd.js","module":"dist/koa-ws-socket.es5.js","types":"dist/types/index.d.ts","repository":"https://github.com/pbomb/koa-ws-socket.git","author":"Matt Parrish <matt.r.parrish@gmail.com>","engines":{"node":">=6.0.0"},"license":"MIT","private":false,"scripts":{"add-contributor":"kcd-scripts contributors add","prebuild":"rimraf dist && rimraf compiled","build":"rollup --config rollup.config.ts --no-clean","lint":"tslint -p . -c tslint.json -e **/node_modules/**/* -e **/typings/**/* **/*.ts","test":"kcd-scripts test","test:cover":"kcd-scripts test --coverage","test:update":"npm run test:cover -s -- --updateSnapshot","test:build":"kcd-scripts test --no-watch","build-and-test":"npm run build -s && npm run test:build -s","validate":"kcd-scripts validate lint,build-and-test,test:cover","precommit":"kcd-scripts precommit","prettier":"prettier --write \"**/*.ts\" \"**/*.js{,on}\"","tsc":"tsc"},"devDependencies":{"@types/jest":"21.1.5","@types/koa":"2.0.40","@types/koa-compose":"3.2.2","@types/ws":"3.2.0","kcd-scripts":"0.27.2","koa":"2.4.1","prettier":"1.8.2","rimraf":"2.6.2","rollup":"0.51.2","rollup-plugin-commonjs":"8.2.6","rollup-plugin-node-resolve":"3.0.0","rollup-plugin-sourcemaps":"0.4.2","rollup-plugin-typescript2":"0.8.0","tslint":"5.8.0","typescript":"2.6.1","ws":"3.3.1"},"peerDependencies":{"koa":">=2","ws":">=3"},"dependencies":{"base64id":"^1.0.0","koa-compose":"^4.0.0"},"release":{"analyzeCommits":{"releaseRules":[{"type":"refactor","release":"patch"}]}}} | ||
{"name":"koa-ws-socket","version":"1.0.1","description":"Attaches ws sockets to koa using koa-style middleware","files":["dist"],"main":"dist/koa-ws-socket.umd.js","module":"dist/koa-ws-socket.es5.js","types":"dist/types/index.d.ts","repository":"https://github.com/pbomb/koa-ws-socket.git","author":"Matt Parrish <matt.r.parrish@gmail.com>","engines":{"node":">=6.0.0"},"license":"MIT","private":false,"scripts":{"add-contributor":"kcd-scripts contributors add","prebuild":"rimraf dist && rimraf compiled","build":"rollup --config rollup.config.ts --no-clean","lint":"tslint -p . -c tslint.json -e **/node_modules/**/* -e **/typings/**/* **/*.ts","test":"kcd-scripts test","test:cover":"kcd-scripts test --coverage","test:update":"npm run test:cover -s -- --updateSnapshot","test:build":"kcd-scripts test --no-watch","build-and-test":"npm run build -s && npm run test:build -s","validate":"kcd-scripts validate lint,build-and-test,test:cover","precommit":"kcd-scripts precommit","prettier":"prettier --write \"**/*.ts\" \"**/*.js{,on}\"","tsc":"tsc"},"devDependencies":{"@types/jest":"21.1.5","@types/koa":"2.0.40","@types/koa-compose":"3.2.2","@types/ws":"3.2.0","kcd-scripts":"0.27.2","koa":"2.4.1","prettier":"1.8.2","rimraf":"2.6.2","rollup":"0.51.2","rollup-plugin-commonjs":"8.2.6","rollup-plugin-node-resolve":"3.0.0","rollup-plugin-sourcemaps":"0.4.2","rollup-plugin-typescript2":"0.8.0","ts-jest":"^22.0.0","tslint":"5.8.0","typescript":"2.6.1","ws":"3.3.1"},"peerDependencies":{"koa":">=2","ws":">=3"},"dependencies":{"base64id":"^1.0.0","koa-compose":"^4.0.0"},"release":{"analyzeCommits":{"releaseRules":[{"type":"refactor","release":"patch"}]}}} |
@@ -20,3 +20,3 @@ <!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors) | ||
[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors) | ||
[![PRs Welcome][prs-badge]][prs] | ||
@@ -30,4 +30,4 @@ [![Code of Conduct][coc-badge]][coc] | ||
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> | ||
| [<img src="https://avatars0.githubusercontent.com/u/1402095?v=4" width="100px;"/><br /><sub>Matt Parrish</sub>](https://github.com/pbomb)<br />[💻](https://github.com/pbomb/koa-ws-socket/commits?author=pbomb "Code") [📖](https://github.com/pbomb/koa-ws-socket/commits?author=pbomb "Documentation") [⚠️](https://github.com/pbomb/koa-ws-socket/commits?author=pbomb "Tests") [👀](#review-pbomb "Reviewed Pull Requests") | | ||
| :---: | | ||
| [<img src="https://avatars0.githubusercontent.com/u/1402095?v=4" width="100px;"/><br /><sub>Matt Parrish</sub>](https://github.com/pbomb)<br />[💻](https://github.com/pbomb/koa-ws-socket/commits?author=pbomb "Code") [📖](https://github.com/pbomb/koa-ws-socket/commits?author=pbomb "Documentation") [⚠️](https://github.com/pbomb/koa-ws-socket/commits?author=pbomb "Tests") [👀](#review-pbomb "Reviewed Pull Requests") | [<img src="https://avatars3.githubusercontent.com/u/1319157?v=4" width="100px;"/><br /><sub>mateuscb</sub>](https://github.com/mateuscb)<br />[💻](https://github.com/pbomb/koa-ws-socket/commits?author=mateuscb "Code") [⚠️](https://github.com/pbomb/koa-ws-socket/commits?author=mateuscb "Tests") | | ||
| :---: | :---: | | ||
<!-- ALL-CONTRIBUTORS-LIST:END --> | ||
@@ -63,2 +63,2 @@ | ||
[emojis]: https://github.com/kentcdodds/all-contributors#emoji-key | ||
[all-contributors]: https://github.com/kentcdodds/all-contributors | ||
[all-contributors]: https://github.com/kentcdodds/all-contributors |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
87786
11
682
17
61