Class: Server

UWA/Utils/InterCom. Server

new Server(serverId, options)

Create a new Server instance to dispatch events between sockets that have registered to this server using subscribeServer.

Example
var MyServer = new UWA.Utils.InterCom.Server('MyServer');
Parameters
Name Type Description
serverId String

the server Id.

options Object

server options.

Mixes In

  • UWA.Class.Debug
  • UWA.Class.Options

Index

Members

id :String

Current Server id.

Type
  • String

uuid :String

Current Server generated uuid.

Type
  • String

sockets :Object

Current Current server's sockets.

Type
  • Object

listeners :Object

Current server's listeners.

Type
  • Object

defaultOptions :String

Current Server default options.

Type
  • String

Methods

setServerId(serverId)

Set server id

Parameters
Name Type Description
serverId String

the server Id.

connect()

Add mainListener

disconnect()

Disconnect Server instance from its Sockets and remove mainListener.

handleEvent()

Handle socket events dispaching.

subscribeSocket(socketId, source, origin)

Subscribe socket instance to this server

Parameters
Name Type Description
socketId String

Id of socket to subscribe.

source Object

Source of socket to subscribe (e.g window reference).

origin String

Origin of socket to subscribe (e.g url of window reference).

unsubscribeSocket(socketId)

Unsubscribe socket from this server.

Parameters
Name Type Description
socketId String

Id of socket to unsubscribe.

addListener(event, listener)

Handle a new Event with data over the current Server.

Example
myServer.addListener('MyEvent', function (json, info) {
    alert(json); // event data
    alert(info); // origin sockets and servers data for filtering
});
Parameters
Name Type Description
event String

Name of listened event.

listener Function

Callback function call when new even incoming.

removeListener(event, listener)

Remove an event listener.

Parameters
Name Type Description
event String

Name of listened event.

listener Function

Callback function call when new even incoming.

dispatchEvent(event, data, originSocket, targetSockets)

Dispatch event with data to current Server's Sockets.

Example
myServer.dispatchEvent('MyEvent', {
    data: 'Hello other Sockets'
});
Parameters
Name Type Description
event String

Name of listened event.

data Object

Data associate to this event dispatch request.

originSocket String

Socket who dispatch the Event first.

targetSockets Array | String

List or Name of targeted Sockets