Class: Socket

UWA/Utils/InterCom. Socket

new Socket(socketId, options)

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

Example
var MySocket = new UWA.Utils.InterCom.Socket('MySocket');
MySocket.subscribeServer('MyServer');
Parameters
Name Type Description
socketId String

the socket Id.

options Object

socket options.

Mixes In

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

Index

Members

id :String

Current Socket id.

Type
  • String

uuid :String

Current Socket generated uuid.

Type
  • String

servers :Object

Current Current socket's servers.

Type
  • Object

listeners :Object

Current socket's listeners.

Type
  • Object

defaultOptions :String

Current Server default options.

Type
  • String

Methods

connect()

Add mainListener

disconnect()

Disconnect Socket instance from his Servers and remove mainListener.

handleEvent()

Handle socket events dispaching.

subscribeServer(serverId, source, origin)

Request a Server, and buffer request during waiting server response.

Parameters
Name Type Description
serverId String

Id of server to subscribe.

source Object

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

origin String

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

unsubscribeServer(serverId)

Unsubscribe server from this socket.

Parameters
Name Type Description
serverId String

Id of server to unsubscribe.

addListener(event, listener)

Handle a new Event with data over the current Server.

Example
mySocket.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, targetSockets, targetServers)

Dispatch Event with data over Server to others Sockets.

Parameters
Name Type Description
event String

Name of listened event.

data Object

Data associate to this event dispatch request.

targetSockets String

List or Name of targeted Sockets.

targetServers Array | String

List or Name of targeted Servers.