Server

new Server(config, paramLine)

Сервер на основе eureca.io

Source:
Parameters:
Name Type Description
config object

конфигурация Eureca.io сервера

paramLine array

параметры командной строки

Members

app :function

Express приложение.

Source:
See:

clients :Object.<Object>

Подключенные клиенты

Source:

exports :object

Функции, доступные со стороны клиента.

Source:
See:

gameModes :Object.<array>

Существующие режимы игры в виде [GameClass, BotClass].

Source:

httpServer :http.Server

Node.js http сервер. Server#app прикрепляется сюда, как колбэк. http сервер затем прикрепляется к Eureca.Server (расширением которого является текущий класс) и обрабатывается им.

Source:

log :winston.Logger

Логгер сервера.

Source:

manager :QueueManager

Менеджер очередей и игр.

Source:

params :object

Параметры сервера.

Source:

players :Object.<Player>

Игроки.

Source:

Methods

attach()

Sends exported server functions to all connected clients
This can be used if the server is designed to dynamically expose new methods.

Source:
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

Source:
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

информация о соединении

handleError()

Оработка ошибок.

Source:

handleMessage(conn)

Выполняется при любом ответе от клиента.

Source:
Parameters:
Name Type Description
conn object

информация о соединении

parseParams(paramLine) → {object}

Обрабатывает параметры при помощи minimist.

Source:
Parameters:
Name Type Description
paramLine array

параметры командной строки

Returns:
Type:
object

Обработанные параметры.

start()

Запускает сервер

Source:

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

Source:
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.

Source:

Events

connect disconnect error message

connect

Triggered each time a new client is connected

Properties:
Name Type Description
socket ISocket

client socket.

Source:

disconnect

triggered when the client is disconneced.

Properties:
Name Type Description
socket ISocket

client socket.

Source:

error

triggered if an error occure.

Properties:
Name Type Description
error String

the error message

socket ISocket

client socket.

Source:

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.

Source:

new Server(settingsopt)

Eureca server constructor This constructor takes an optional settings object

Properties:
Name Type Attributes Default Description
settings.transport string <optional>
engine.io

can be "engine.io", "sockjs", "websockets", "faye" or "browserchannel" by default "engine.io" is used

settings.authenticate function <optional>

If this function is defined, the client will not be able to invoke server functions until it successfully call the client side authenticate method, which will invoke this function.

settings.serialize function <optional>

If defined, this function is used to serialize the request object before sending it to the client (default is JSON.stringify). This function can be useful to add custom information/meta-data to the transmitted request.

settings.deserialize function <optional>

If defined, this function is used to deserialize the received response string.

Source:
See:
  • attach
  • getClient
Parameters:
Name Type Attributes Description
settings object <optional>

have the following properties

Examples
<h4> # default instantiation</h4>
var Eureca = require('eureca.io');
//use default transport
var server = new Eureca.Server();
<h4> # custom transport instantiation </h4>
var Eureca = require('eureca.io');
//use websockets transport
var server = new Eureca.Server({transport:'websockets'});
<h4> # Authentication </h4>
var Eureca = require('eureca.io');

var eurecaServer = new Eureca.Server({
    authenticate: function (authToken, next) {
        console.log('Called Auth with token=', authToken);

        if (isValidToekn(authToken)) next();  // authentication success
        else next('Auth failed'); //authentication fail
    }
});

Members

app :function

Express приложение.

Source:
See:

clients :Object.<Object>

Подключенные клиенты

Source:

exports :object

Функции, доступные со стороны клиента.

Source:
See:

gameModes :Object.<array>

Существующие режимы игры в виде [GameClass, BotClass].

Source:

httpServer :http.Server

Node.js http сервер. Server#app прикрепляется сюда, как колбэк. http сервер затем прикрепляется к Eureca.Server (расширением которого является текущий класс) и обрабатывается им.

Source:

log :winston.Logger

Логгер сервера.

Source:

manager :QueueManager

Менеджер очередей и игр.

Source:

params :object

Параметры сервера.

Source:

players :Object.<Player>

Игроки.

Source:

Methods

attach()

Sends exported server functions to all connected clients
This can be used if the server is designed to dynamically expose new methods.

Source:
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

Source:
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

информация о соединении

handleError()

Оработка ошибок.

Source:

handleMessage(conn)

Выполняется при любом ответе от клиента.

Source:
Parameters:
Name Type Description
conn object

информация о соединении

parseParams(paramLine) → {object}

Обрабатывает параметры при помощи minimist.

Source:
Parameters:
Name Type Description
paramLine array

параметры командной строки

Returns:
Type:
object

Обработанные параметры.

start()

Запускает сервер

Source:

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

Source:
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.

Source:

Events

connect disconnect error message

connect

Triggered each time a new client is connected

Properties:
Name Type Description
socket ISocket

client socket.

Source:

disconnect

triggered when the client is disconneced.

Properties:
Name Type Description
socket ISocket

client socket.

Source:

error

triggered if an error occure.

Properties:
Name Type Description
error String

the error message

socket ISocket

client socket.

Source:

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.

Source: