/
clientTracker.js
138 lines (124 loc) · 4.13 KB
/
clientTracker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/**
* @fileOverview
* ClientTracker class definition.
*/
var util = require('util');
var Thywill = require('thywill');
//-----------------------------------------------------------
// Class Definition
//-----------------------------------------------------------
/**
* @class
* The superclass for client trackers, which keep track of connections and
* sessions connected to the various processes in a cluster.
*
* A clientTracker implementation must emit the following events, which
* require integration with the cluster communication mechanisms.
*
* When a cluster member goes down, emit the list of connectionIds and
* sessionIds that were disconnected.
* clientTracker.on(clientTracker.events.CLUSTER_MEMBER_DOWN, function (clusterMemberId, connectionData) {});
*
* Emit on connection of a client to this cluster member.
* clientTracker.on(clientTracker.events.CONNECTION, function (client, session) {});
*
* Emit when a client disconnects from this or any other cluster member.
* clientTracker.on(clientTracker.events.CONNECTION_TO, function (clusterMemberId, client {});
*
* Emit on disconnection of a client to this cluster member.
* clientTracker.on(clientTracker.events.DISCONNECTION, function (client) {});
*
* Emit when a client disconnects from this or any other cluster member.
* clientTracker.on(clientTracker.events.DISCONNECTION_FROM, function (clusterMemberId, client) {});
*/
function ClientTracker() {
ClientTracker.super_.call(this);
this.componentType = 'clientTracker';
// Convenience reference.
this.events = ClientTracker.EVENTS;
}
util.inherits(ClientTracker, Thywill.getBaseClass('Component'));
var p = ClientTracker.prototype;
//-----------------------------------------------------------
// 'Static'
//-----------------------------------------------------------
ClientTracker.EVENTS = {
CONNECTION: 'connection',
CONNECTION_TO: 'connectionTo',
DISCONNECTION: 'disconnection',
DISCONNECTION_FROM: 'disconnectionFrom',
CLUSTER_MEMBER_DOWN: 'clusterMemberDown'
};
//-----------------------------------------------------------
// Methods
//-----------------------------------------------------------
/**
* @see Component#_getDependencies
*/
p._getDependencies = function () {
return {
components: ['clientInterface']
};
};
/**
* Is the specified client connected to any of the cluster's server processes?
*
* @param {Client|string} client
* A Client instance or connection ID.
* @param {function} callback
* Of the form function (error, boolean).
*/
p.clientIsConnected = function (client, callback) {
throw new Error('Not implemented.');
};
/**
* Is the specified client connected to this process?
*
* @param {Client|string} client
* A Client instance or connection ID.
* @param {function} callback
* Of the form function (error, boolean).
*/
p.clientIsConnectedLocally = function (client, callback) {
throw new Error('Not implemented.');
};
/**
* Are any clients with the specified session connected to any of the cluster's
* server processes?
*
* @param {Client|string} client
* A Client instance or session ID.
* @param {function} callback
* Of the form function (error, boolean).
*/
p.clientSessionIsConnected = function (client, callback) {
throw new Error('Not implemented.');
};
/**
* Obtain an array of connection IDs associated with this session.
*
* @param {string} sessionId
* The connection ID.
* @param {function} callback
* Of the form function (error, connectionIds).
*/
p.connectionIdsForSession = function (sessionId, callback) {
throw new Error('Not implemented.');
};
/**
* Return a reference to a data structure for connected sessions and clients
* for all of the cluster members.
*
* This data may or may not be a clone of the actual data structure used by
* the clientInterface to keep track of who is online.
*
* @param {function} callback
* Of the form function (error, data).
*/
p.getConnectionData = function (callback) {
throw new Error('Not implemented.');
};
//-----------------------------------------------------------
// Exports - Class Constructor
//-----------------------------------------------------------
module.exports = ClientTracker;