SocketService

Websocket game service, create threads to simulate gameobject + socket

Constructor

new SocketService(httpServer, options)

Parameters:
NameTypeDescription
httpServermodule:http~Server

http server

optionsobject

options

Properties
NameTypeAttributesDefaultDescription
pingIntervalnumber<optional>
2000

ping interval of the socket connection in ms

pingTimeoutnumber<optional>
5000

ping timeout in ms

socketConnectionCallbacksArray.<SocketCallback><optional>
[]

callback to apply when socket is connected

socketDisconnectionCallbacksArray.<SocketCallback><optional>
[]

callback to apply when socket is disconnected

socketReadyForGamePromisesArray.<ReadyForGameCallback><optional>
[]

callback to apply when socket is ready for game

Members

io :socketio.Server

Type:
  • socketio.Server

socketConnectionCallbacks :Array.<SocketCallback>

Type:

socketDisconnectionCallbacks :Array.<SocketCallback>

Type:

socketReadyForGamePromises :Array.<ReadyForGameCallback>

socketWrappers :Object.<string, SocketWrapper>

socket wrappers currently connected

Type:
  • Object.<string, SocketWrapper>

threads :Object.<string, Parent>

threads running a gamecontext

Type:

Methods

loadGameThreads(gameObjects3D, threadProcessPath, entryGameObject3DUUIDopt) → {Promise}

Launch thread running game context simulation

Parameters:
NameTypeAttributesDescription
gameObjects3DArray.<object>

array of gameobject3D json to simulate

threadProcessPathstring

path to the thread process

entryGameObject3DUUIDstring<optional>

uuid of default gameobject to connect socket connected

Returns:
  • a promises resolving when all thread have been initialized
Type: 
Promise

onSocketConnection(socket)

init

Parameters:
NameTypeDescription
socketsocketio.Socket

new socket connected to game service

stop() → {Promise}

Stop threads + disconnect socket client + close websocket connection

Returns:
  • a promise resolving when all thread have been closed
Type: 
Promise