Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
chore(release): 0.1.0-beta.1
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerntannern committed Nov 14, 2018
1 parent 4290610 commit 2db7633
Show file tree
Hide file tree
Showing 33 changed files with 1,325 additions and 332 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,16 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

<a name="0.1.0-beta.1"></a>
# [0.1.0-beta.1](https://github.com/tannerntannern/table-talk/compare/v0.1.0-beta.0...v0.1.0-beta.1) (2018-11-14)


### Bug Fixes

* fixed lint error ([4290610](https://github.com/tannerntannern/table-talk/commit/4290610))



<a name="0.1.0-beta.0"></a>
# [0.1.0-beta.0](https://github.com/tannerntannern/table-talk/compare/v0.1.0-alpha.3...v0.1.0-beta.0) (2018-11-14)

Expand Down
16 changes: 4 additions & 12 deletions dist/client/socket-client.d.ts
@@ -1,4 +1,5 @@
import { SocketHandlers, SocketInterface } from '../interface/socket-interface';
import { SocketMixin } from '../lib/socket-mixin';
/**
* Describes the shape of the `this` context that will be available in every SocketClient handler.
*/
Expand All @@ -9,7 +10,7 @@ export declare type HandlerCtx<API extends SocketInterface> = {
/**
* Basic socket client that can be used in Node or in the browser.
*/
export declare abstract class SocketClient<API extends SocketInterface> {
export declare abstract class SocketClient<API extends SocketInterface> extends SocketMixin<API, 'client'> {
/**
* Socket.io Socket instance for internal use.
*/
Expand All @@ -19,15 +20,6 @@ export declare abstract class SocketClient<API extends SocketInterface> {
* SocketServer that implements the same API.
*/
protected abstract socketHandlers: SocketHandlers<API, 'client', HandlerCtx<API>>;
/**
* @internal
*/
private waiters;
/**
* Processes an incoming event with the appropriate socketHandler. If the handler returns an EventResponse, the
* proper event will automatically be emitted.
*/
protected handleEvent(ctx: HandlerCtx<API>, event: string, ...args: any[]): void;
/**
* Sets up the socket handlers for the client.
*/
Expand All @@ -53,7 +45,7 @@ export declare abstract class SocketClient<API extends SocketInterface> {
*/
emit<Event extends keyof API['client']>(event: Event, ...args: API['client'][Event]['args']): void;
/**
* Gives the ability to block and wait for an event. Usage: `await client.blockEvent('some-event');`
* Handles a Response that requires a reply.
*/
blockEvent<Event extends string>(event: Event): Promise<any>;
protected reply(ctx: any, response: any): void;
}
63 changes: 24 additions & 39 deletions dist/client/socket-client.js
@@ -1,42 +1,31 @@
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
}
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import * as socketio from 'socket.io-client';
import { SocketMixin } from '../lib/socket-mixin';
/**
* Basic socket client that can be used in Node or in the browser.
*/
var SocketClient = /** @class */ (function () {
var SocketClient = /** @class */ (function (_super) {
__extends(SocketClient, _super);
function SocketClient() {
var _this = _super !== null && _super.apply(this, arguments) || this;
/**
* Socket.io Socket instance for internal use.
*/
this.socket = null;
/**
* @internal
*/
this.waiters = {};
_this.socket = null;
return _this;
}
/**
* Processes an incoming event with the appropriate socketHandler. If the handler returns an EventResponse, the
* proper event will automatically be emitted.
*/
SocketClient.prototype.handleEvent = function (ctx, event) {
var args = [];
for (var _i = 2; _i < arguments.length; _i++) {
args[_i - 2] = arguments[_i];
}
var _a;
// Process the response if there is one
var response = (_a = this.socketHandlers[event]).call.apply(_a, [ctx].concat(args));
if (response) {
this.emit.apply(this, [response.name].concat(response.args));
}
// Process any waiters
var waiters = this.waiters[event];
if (waiters)
for (var _b = 0, waiters_1 = waiters; _b < waiters_1.length; _b++) {
var waiter = waiters_1[_b];
waiter();
}
this.waiters[event] = [];
};
/**
* Sets up the socket handlers for the client.
*/
Expand Down Expand Up @@ -114,16 +103,12 @@ var SocketClient = /** @class */ (function () {
(_a = this.socket).emit.apply(_a, [event].concat(args));
};
/**
* Gives the ability to block and wait for an event. Usage: `await client.blockEvent('some-event');`
* Handles a Response that requires a reply.
*/
SocketClient.prototype.blockEvent = function (event) {
var _this = this;
return new Promise(function (resolve, reject) {
if (!_this.waiters[event])
_this.waiters[event] = [];
_this.waiters[event].push(resolve);
});
SocketClient.prototype.reply = function (ctx, response) {
var _a;
(_a = this.socket).emit.apply(_a, [response.name].concat(response.args));
};
return SocketClient;
}());
}(SocketMixin));
export { SocketClient };
8 changes: 6 additions & 2 deletions dist/interface/socket-interface.d.ts
@@ -1,7 +1,11 @@
/**
* Where socket handlers can reside -- either on the server or the client.
*/
declare type SocketLocation = 'server' | 'client';
export declare type SocketLocation = 'server' | 'client';
/**
* Given a SocketLocation, generates the opposite SocketLocation.
*/
export declare type OtherLocation<L extends SocketLocation> = L extends 'server' ? 'client' : 'server';
/**
* Describes a transmittable event on either the client or the server. Each one may specify its argument types with a
* tuple, the name of the event it expects to receive as a response, and optionally the name of the event for which the
Expand Down Expand Up @@ -95,5 +99,5 @@ declare type EventHandlers<T extends TransmitterMap, RT extends TransmitterMap,
/**
* Utility type for generating EventHandlers given a SocketInterface and a SocketLocation.
*/
export declare type SocketHandlers<TS extends SocketInterface, SL extends SocketLocation, HandlerContext> = SL extends 'server' ? EventHandlers<TS['server'], TS['client'], SL, HandlerContext> : EventHandlers<TS['client'], TS['server'], SL, HandlerContext>;
export declare type SocketHandlers<TS extends SocketInterface, SL extends SocketLocation, HandlerContext> = EventHandlers<TS[SL], TS[OtherLocation<SL>], SL, HandlerContext>;
export {};
27 changes: 27 additions & 0 deletions dist/lib/socket-mixin.d.ts
@@ -0,0 +1,27 @@
import { SocketLocation, Response, SocketInterface } from '../interface/socket-interface';
/**
* Mixin for shared socket functionality between the server and client.
*/
export declare abstract class SocketMixin<API extends SocketInterface, Loc extends SocketLocation> {
/**
* @internal
*/
private waiters;
/**
* Expected by the mixin.
*/
protected abstract socketHandlers: any;
/**
* Handles a Response that requires a reply.
*/
protected abstract reply(ctx: any, response: Response<string, API[Loc], Loc>): any;
/**
* Processes an incoming event with the appropriate socketHandler. If the handler returns an EventResponse, the
* proper event will automatically be emitted.
*/
protected handleEvent(ctx: unknown, event: string, ...args: any[]): void;
/**
* Gives the ability to block and wait for an event. Usage: `await this.blockEvent('some-event');`
*/
blockEvent<Event extends string>(event: Event): Promise<any>;
}
47 changes: 47 additions & 0 deletions dist/lib/socket-mixin.js
@@ -0,0 +1,47 @@
/**
* Mixin for shared socket functionality between the server and client.
*/
var SocketMixin = /** @class */ (function () {
function SocketMixin() {
/**
* @internal
*/
this.waiters = {};
}
/**
* Processes an incoming event with the appropriate socketHandler. If the handler returns an EventResponse, the
* proper event will automatically be emitted.
*/
SocketMixin.prototype.handleEvent = function (ctx, event) {
var args = [];
for (var _i = 2; _i < arguments.length; _i++) {
args[_i - 2] = arguments[_i];
}
var _a;
// Process the response if there is one
var response = (_a = this.socketHandlers[event]).call.apply(_a, [ctx].concat(args));
if (response)
this.reply(ctx, response);
// Process any waiters
var waiters = this.waiters[event];
if (waiters)
for (var _b = 0, waiters_1 = waiters; _b < waiters_1.length; _b++) {
var waiter = waiters_1[_b];
waiter();
}
this.waiters[event] = [];
};
/**
* Gives the ability to block and wait for an event. Usage: `await this.blockEvent('some-event');`
*/
SocketMixin.prototype.blockEvent = function (event) {
var _this = this;
return new Promise(function (resolve, reject) {
if (!_this.waiters[event])
_this.waiters[event] = [];
_this.waiters[event].push(resolve);
});
};
return SocketMixin;
}());
export { SocketMixin };
11 changes: 7 additions & 4 deletions dist/server/socket-server.d.ts
Expand Up @@ -3,6 +3,7 @@ import * as http from 'http';
import * as socketio from 'socket.io';
import { HttpServer, HttpServerConfig } from './http-server';
import { SocketHandlers, SocketInterface } from '../interface/socket-interface';
import { SocketMixin } from '../lib/socket-mixin';
/**
* Defines how SocketServer may be configured.
*/
Expand All @@ -21,7 +22,7 @@ export declare type HandlerCtx<API extends SocketInterface> = {
/**
* A simple SocketServer with an API protected by TypeScript.
*/
export declare abstract class SocketServer<API extends SocketInterface> extends HttpServer {
declare abstract class SocketServer<API extends SocketInterface> extends HttpServer {
/**
* Socket.io server instance for managing socket communication.
*/
Expand All @@ -48,10 +49,9 @@ export declare abstract class SocketServer<API extends SocketInterface> extends
*/
emit<Event extends keyof API['server']>(target: socketio.Namespace | socketio.Socket, event: Event, ...args: API['server'][Event]['args']): void;
/**
* Processes an incoming event with the appropriate socketHandler. If the handler returns an EventResponse, the
* proper event will automatically be emitted.
* Handles a Response that requires a reply.
*/
protected handleEvent(ctx: HandlerCtx<API>, event: string, ...args: any[]): void;
protected reply(ctx: any, response: any): void;
/**
* Sets up the socket handlers for the given namespace.
*/
Expand All @@ -77,3 +77,6 @@ export declare abstract class SocketServer<API extends SocketInterface> extends
*/
protected takedown(): void;
}
interface SocketServer<API extends SocketInterface> extends HttpServer, SocketMixin<API, 'server'> {
}
export { SocketServer };
27 changes: 15 additions & 12 deletions dist/server/socket-server.js
Expand Up @@ -11,11 +11,20 @@ var __extends = (this && this.__extends) || (function () {
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import * as socketio from 'socket.io';
import { MixinDecorator } from 'ts-mixer';
import { HttpServer } from './http-server';
import { SocketMixin } from '../lib/socket-mixin';
/**
* A simple SocketServer with an API protected by TypeScript.
*/
// @ts-ignore: It's ok to mix these abstract classes
var SocketServer = /** @class */ (function (_super) {
__extends(SocketServer, _super);
/**
Expand Down Expand Up @@ -58,19 +67,10 @@ var SocketServer = /** @class */ (function (_super) {
target.emit.apply(target, [event].concat(args));
};
/**
* Processes an incoming event with the appropriate socketHandler. If the handler returns an EventResponse, the
* proper event will automatically be emitted.
* Handles a Response that requires a reply.
*/
SocketServer.prototype.handleEvent = function (ctx, event) {
var args = [];
for (var _i = 2; _i < arguments.length; _i++) {
args[_i - 2] = arguments[_i];
}
var _a;
var response = (_a = this.socketHandlers[event]).call.apply(_a, [ctx].concat(args));
if (response) {
this.emit.apply(this, [response.broadcast ? ctx.nsp : ctx.socket, response.name].concat(response.args));
}
SocketServer.prototype.reply = function (ctx, response) {
this.emit.apply(this, [response.broadcast ? ctx.nsp : ctx.socket, response.name].concat(response.args));
};
/**
* Sets up the socket handlers for the given namespace.
Expand Down Expand Up @@ -163,6 +163,9 @@ var SocketServer = /** @class */ (function (_super) {
SocketServer.prototype.takedown = function () {
this.io = null;
};
SocketServer = __decorate([
MixinDecorator(SocketMixin)
], SocketServer);
return SocketServer;
}(HttpServer));
export { SocketServer };
2 changes: 1 addition & 1 deletion docs/assets/js/search.js

Large diffs are not rendered by default.

0 comments on commit 2db7633

Please sign in to comment.