new Server(config, paramLine)
Сервер на основе eureca.io
- Source:
Parameters:
Name | Type | Description |
---|---|---|
config |
object
|
конфигурация Eureca.io сервера |
paramLine |
array
|
параметры командной строки |
Members
app :function
Express приложение.
- Source:
- See:
exports :object
Функции, доступные со стороны клиента.
- Source:
- See:
gameModes :Object.<array>
Существующие режимы игры в виде [GameClass, BotClass]
.
- Source:
httpServer :http.Server
Node.js http сервер. Server#app прикрепляется сюда, как колбэк. http сервер затем прикрепляется к Eureca.Server (расширением которого является текущий класс) и обрабатывается им.
- Source:
Methods
attach
createLogger
getClient
handleConnect
handleDisconnect
handleError
handleMessage
parseParams
start
updateClientAllowedFunctions
updateContract
attach()
Sends exported server functions to all connected clients
This can be used if the server is designed to dynamically expose new methods.
Parameters:
Type | Description |
---|---|
Server
|
a nodejs nodejs http server or expressjs Application |
createLogger() → {winston.Logger}
Создает winston логгер.
- Source:
Returns:
- Type:
-
winston.Logger
Логгер.
getClient(id) → {Proxy}
This method is used to get the client proxy of a given connection. it allows the server to call remote client function
Parameters:
Name | Type | Description |
---|---|---|
id |
String
|
client identifier |
Returns:
- Type:
-
Proxy
Example
//we suppose here that the clients are exposing hello() function
//onConnect event give the server an access to the client socket
server.onConnect(function (socket) {
//get client proxy by socket ID
var client = server.getClient(socket.id);
//call remote hello() function.
client.hello();
}
handleConnect(conn)
Обработка подключения нового клиента.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
conn |
object
|
информация о соединении |
handleDisconnect(conn)
Обработка отключения клиента.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
conn |
object
|
информация о соединении |
handleMessage(conn)
Выполняется при любом ответе от клиента.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
conn |
object
|
информация о соединении |
parseParams(paramLine) → {object}
Обрабатывает параметры при помощи minimist.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
paramLine |
array
|
параметры командной строки |
Returns:
- Type:
-
object
Обработанные параметры.
updateClientAllowedFunctions(id)
**!! Experimental !! **
force regeneration of client remote function signatures
this is needed if for some reason we need to dynamically update allowed client functions at runtime
Parameters:
Name | Type | Description |
---|---|---|
id |
String
|
client identifier |
updateContract()
**!! Experimental !! **
Sends exported server functions to all connected clients
This can be used if the server is designed to dynamically expose new methods.
Events
connect
disconnect
error
message
connect
Triggered each time a new client is connected
Properties:
Name | Type | Description |
---|---|---|
socket |
ISocket
|
client socket. |
disconnect
triggered when the client is disconneced.
Properties:
Name | Type | Description |
---|---|---|
socket |
ISocket
|
client socket. |
error
triggered if an error occure.
Properties:
Name | Type | Description |
---|---|---|
error |
String
|
the error message |
socket |
ISocket
|
client socket. |
message
Triggered each time a new message is received from a client.
Properties:
Name | Type | Description |
---|---|---|
message |
String
|
the received message. |
socket |
ISocket
|
client socket. |