Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"@types/koa-router": "^7.4.0",
"@types/koa__cors": "^3.0.1",
"@types/shortid": "0.0.29",
"@types/socket.io": "^2.1.4",
"ajv": "^6.6.2",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^8.0.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@

import { Server } from '../src/server';
import { FlatFile } from '../src/server/db';
import { SocketIO } from '../src/server/transport/socketio';

export { Server, FlatFile };
export { Server, FlatFile, SocketIO };
2 changes: 1 addition & 1 deletion src/master/master.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const stripCredentialsFromAction = (action: CredentialedActionShape.Any) => {
return { ...action, payload };
};

type AuthFn = (
export type AuthFn = (
actionCredentials: string,
playerMetadata: Server.PlayerMetadata
) => boolean | Promise<boolean>;
Expand Down
2 changes: 1 addition & 1 deletion src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function Server({
typeof authenticateCredentials === 'function'
? authenticateCredentials
: true;
transport = SocketIO({
transport = new SocketIO({
auth,
https,
});
Expand Down
131 changes: 0 additions & 131 deletions src/server/transport/socketio.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,19 @@
import { TransportAPI, SocketIO } from './socketio';
import { ProcessGameConfig } from '../../core/game';

class SocketIOTestAdapter extends SocketIO {
constructor({ clientInfo = new Map(), roomInfo = new Map(), ...args } = {}) {
super(args);
this.clientInfo = clientInfo;
this.roomInfo = roomInfo;
}
}

jest.mock('../../master/master', () => {
class Master {
onUpdate: jest.Mock<any, any>;
onSync: jest.Mock<any, any>;

constructor() {
this.onUpdate = jest.fn();
this.onSync = jest.fn();
Expand All @@ -22,6 +33,11 @@ jest.mock('../../master/master', () => {

jest.mock('koa-socket-2', () => {
class MockSocket {
id: string;
callbacks: {};
emit: jest.Mock<any, any>;
broadcast: { emit: jest.Mock<any, any> };

constructor() {
this.id = 'id';
this.callbacks = {};
Expand Down Expand Up @@ -49,15 +65,20 @@ jest.mock('koa-socket-2', () => {
}

class MockIO {
socket: MockSocket;

constructor() {
this.socket = new MockSocket();
}

attach(app) {
app.io = app._io = this;
}

of() {
return this;
}

on(type, callback) {
callback(this.socket);
}
Expand All @@ -67,15 +88,15 @@ jest.mock('koa-socket-2', () => {
});

describe('basic', () => {
const app = { context: {} };
const app: any = { context: {} };
const games = [ProcessGameConfig({ seed: 0 })];
let clientInfo;
let roomInfo;

beforeEach(() => {
clientInfo = new Map();
roomInfo = new Map();
const transport = SocketIO({ clientInfo, roomInfo });
const transport = new SocketIOTestAdapter({ clientInfo, roomInfo });
transport.init(app, games);
});

Expand All @@ -89,11 +110,11 @@ describe('TransportAPI', () => {
let api;

beforeAll(() => {
const app = { context: {} };
const app: any = { context: {} };
const games = [ProcessGameConfig({ seed: 0 })];
const clientInfo = new Map();
const roomInfo = new Map();
const transport = SocketIO({ clientInfo, roomInfo });
const transport = new SocketIOTestAdapter({ clientInfo, roomInfo });
transport.init(app, games);
io = app.context.io;
api = TransportAPI('gameID', io.socket, clientInfo, roomInfo);
Expand Down Expand Up @@ -132,9 +153,9 @@ describe('TransportAPI', () => {
});

describe('sync / update', () => {
const app = { context: {} };
const app: any = { context: {} };
const games = [ProcessGameConfig({ seed: 0 })];
const transport = SocketIO();
const transport = new SocketIOTestAdapter();
transport.init(app, games);
const io = app.context.io;

Expand All @@ -148,7 +169,7 @@ describe('sync / update', () => {
});

describe('connect / disconnect', () => {
const app = { context: {} };
const app: any = { context: {} };
const games = [ProcessGameConfig({ seed: 0 })];
let clientInfo;
let roomInfo;
Expand All @@ -165,7 +186,7 @@ describe('connect / disconnect', () => {
beforeAll(() => {
clientInfo = new Map();
roomInfo = new Map();
const transport = SocketIO({ clientInfo, roomInfo });
const transport = new SocketIOTestAdapter({ clientInfo, roomInfo });
transport.init(app, games);
io = app.context.io;
});
Expand Down
Loading