1 | <?php |
||
21 | class SessionMonitor implements MonitorInterface, EventEmitterInterface |
||
22 | { |
||
23 | use MonitorTrait { |
||
24 | start as doStart; |
||
25 | stop as doStop; |
||
26 | } |
||
27 | |||
28 | const SESSION_JOIN_TOPIC = 'wamp.session.on_join'; |
||
29 | const SESSION_LEAVE_TOPIC = 'wamp.session.on_leave'; |
||
30 | const SESSION_COUNT_TOPIC = 'wamp.session.count'; |
||
31 | const SESSION_LIST_TOPIC = 'wamp.session.list'; |
||
32 | const SESSION_INFO_TOPIC = 'wamp.session.get'; |
||
33 | |||
34 | protected $sessionIds = []; |
||
35 | |||
36 | protected $joinSubscriptionId = false; |
||
37 | |||
38 | protected $leaveSubscriptionId = false; |
||
39 | |||
40 | protected $calledList = false; |
||
41 | |||
42 | /** |
||
43 | * Constructor. |
||
44 | * |
||
45 | * @param ClientSession $session |
||
46 | */ |
||
47 | public function __construct(ClientSession $session) |
||
51 | |||
52 | /** |
||
53 | * Start the monitor. |
||
54 | * |
||
55 | * @return bool |
||
56 | */ |
||
57 | public function start() |
||
64 | |||
65 | /** |
||
66 | * Checks if all necessary subscriptions and calls have been responded to. |
||
67 | */ |
||
68 | protected function checkStarted() |
||
78 | |||
79 | /** |
||
80 | * Stop the monitor. |
||
81 | * Returns boolean wether the monitor could be started. |
||
82 | * |
||
83 | * @return bool |
||
84 | */ |
||
85 | public function stop() |
||
92 | |||
93 | /** |
||
94 | * Retrieves the session-info for given sessionId |
||
95 | * and populates it in via given callback. |
||
96 | * |
||
97 | * @param $sessionId |
||
98 | * @param callable $callback |
||
99 | * |
||
100 | * @return mixed |
||
101 | */ |
||
102 | public function getSessionInfo($sessionId, callable $callback = null) |
||
116 | |||
117 | /** |
||
118 | * Retrieves the Ids of the sessions currently |
||
119 | * registered on the wamp-router in the monitor's realm |
||
120 | * and populates the data via given callback,. |
||
121 | * |
||
122 | * @param callable $callback |
||
123 | * |
||
124 | * @return mixed |
||
125 | */ |
||
126 | public function getSessionIds(callable $callback) |
||
136 | |||
137 | /** |
||
138 | * Checks if a session id is known. |
||
139 | * |
||
140 | * @param $sessionId |
||
141 | * |
||
142 | * @return bool |
||
143 | */ |
||
144 | public function hasSessionId($sessionId) |
||
148 | |||
149 | /** |
||
150 | * Removes a session id. |
||
151 | * |
||
152 | * @param int $sessionId |
||
153 | */ |
||
154 | protected function removeSessionId($sessionId) |
||
164 | |||
165 | /** |
||
166 | * Checks if a session is known by extracting its id. |
||
167 | * |
||
168 | * @param $sessionInfo |
||
169 | * |
||
170 | * @return bool |
||
171 | */ |
||
172 | protected function hasSession($sessionInfo) |
||
176 | |||
177 | /** |
||
178 | * Adds and publishes a joined session. |
||
179 | * |
||
180 | * @param $sessionInfo |
||
181 | */ |
||
182 | protected function addSession($sessionInfo) |
||
187 | |||
188 | /** |
||
189 | * Validates the sessionInfo sent from the router. |
||
190 | * |
||
191 | * @param string $sessionInfo |
||
192 | * |
||
193 | * @return bool |
||
194 | */ |
||
195 | protected function validateSessionInfo($sessionInfo) |
||
199 | |||
200 | /** |
||
201 | * Initializes the subscription to the meta-events. |
||
202 | */ |
||
203 | protected function startSubscriptions() |
||
229 | |||
230 | /** |
||
231 | * Unsubscribes from the meta-events. |
||
232 | */ |
||
233 | protected function stopSubscriptions() |
||
242 | |||
243 | /** |
||
244 | * Retrieves the list of current sessionIds on the router. |
||
245 | * |
||
246 | * @param callable|null $callback |
||
247 | */ |
||
248 | protected function retrieveSessionIds(callable $callback = null) |
||
267 | |||
268 | protected function setList($list) |
||
272 | |||
273 | protected function getList() |
||
277 | |||
278 | /** |
||
279 | * remove the sessionID of the Monitor from the list. |
||
280 | * |
||
281 | * @param array $sessionsIds |
||
282 | * |
||
283 | * @return mixed |
||
284 | */ |
||
285 | protected function removeOwnSessionId(array $sessionsIds) |
||
295 | } |
||
296 |