@socialgorithm/game-server
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -7,3 +7,3 @@ /// <reference types="socket.io" /> | ||
private serverOptions?; | ||
socket: SocketIO.Server; | ||
io: SocketIO.Server; | ||
constructor(inputBindings: GameInputBindings, serverOptions?: ServerOptions); | ||
@@ -10,0 +10,0 @@ sendPlayerMessage: (player: string, payload: any) => void; |
@@ -12,3 +12,3 @@ "use strict"; | ||
this.sendPlayerMessage = function (player, payload) { | ||
_this.socket.send(constants_1.SOCKET_MESSAGE.GAME__PLAYER, { | ||
_this.io.emit(constants_1.SOCKET_MESSAGE.GAME__PLAYER, { | ||
payload: payload, | ||
@@ -19,3 +19,3 @@ player: player | ||
this.sendGameUpdate = function (payload) { | ||
_this.socket.send(constants_1.SOCKET_MESSAGE.UPDATE, { | ||
_this.io.emit(constants_1.SOCKET_MESSAGE.UPDATE, { | ||
payload: payload | ||
@@ -25,3 +25,3 @@ }); | ||
this.sendGameEnd = function (payload) { | ||
_this.socket.send(constants_1.SOCKET_MESSAGE.GAME_ENDED, { | ||
_this.io.emit(constants_1.SOCKET_MESSAGE.GAME_ENDED, { | ||
payload: payload | ||
@@ -31,8 +31,10 @@ }); | ||
var app = http.createServer(); | ||
this.socket = io(app); | ||
this.io = io(app); | ||
var port = serverOptions.port || 3333; | ||
app.listen(port); | ||
console.log("Started Socialgorithm Game Server on " + port); | ||
this.socket.on(constants_1.SOCKET_MESSAGE.START_GAME, this.inputBindings.startGame); | ||
this.socket.on(constants_1.SOCKET_MESSAGE.GAME__PLAYER, this.inputBindings.onPlayerMessage); | ||
this.io.on("connection", function (socket) { | ||
socket.on(constants_1.SOCKET_MESSAGE.START_GAME, _this.inputBindings.startGame); | ||
socket.on(constants_1.SOCKET_MESSAGE.GAME__PLAYER, _this.inputBindings.onPlayerMessage); | ||
}); | ||
} | ||
@@ -39,0 +41,0 @@ return GameServer; |
{ | ||
"name": "@socialgorithm/game-server", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "JS Game Server library", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -8,7 +8,7 @@ import * as http from "http"; | ||
export class GameServer { | ||
public socket: SocketIO.Server; | ||
public io: SocketIO.Server; | ||
constructor(private inputBindings: GameInputBindings, private serverOptions?: ServerOptions) { | ||
const app = http.createServer(); | ||
this.socket = io(app); | ||
this.io = io(app); | ||
const port = serverOptions.port || 3333; | ||
@@ -20,8 +20,10 @@ | ||
this.socket.on(SOCKET_MESSAGE.START_GAME, this.inputBindings.startGame); | ||
this.socket.on(SOCKET_MESSAGE.GAME__PLAYER, this.inputBindings.onPlayerMessage); | ||
this.io.on("connection", (socket: io.Socket) => { | ||
socket.on(SOCKET_MESSAGE.START_GAME, this.inputBindings.startGame); | ||
socket.on(SOCKET_MESSAGE.GAME__PLAYER, this.inputBindings.onPlayerMessage); | ||
}); | ||
} | ||
public sendPlayerMessage = (player: Player, payload: any) => { | ||
this.socket.send(SOCKET_MESSAGE.GAME__PLAYER, { | ||
this.io.emit(SOCKET_MESSAGE.GAME__PLAYER, { | ||
payload, | ||
@@ -33,3 +35,3 @@ player, | ||
public sendGameUpdate = (payload: any) => { | ||
this.socket.send(SOCKET_MESSAGE.UPDATE, { | ||
this.io.emit(SOCKET_MESSAGE.UPDATE, { | ||
payload, | ||
@@ -40,3 +42,3 @@ }); | ||
public sendGameEnd = (payload: any) => { | ||
this.socket.send(SOCKET_MESSAGE.GAME_ENDED, { | ||
this.io.emit(SOCKET_MESSAGE.GAME_ENDED, { | ||
payload, | ||
@@ -43,0 +45,0 @@ }); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80755
225