1 | <?php |
||
22 | class SessionMonitor implements MonitorInterface, EventEmitterInterface |
||
23 | { |
||
24 | use MonitorTrait; |
||
25 | |||
26 | const SESSION_JOIN_TOPIC = 'wamp.session.on_join'; |
||
27 | const SESSION_LEAVE_TOPIC = 'wamp.session.on_leave'; |
||
28 | const SESSION_COUNT_TOPIC = 'wamp.session.count'; |
||
29 | const SESSION_LIST_TOPIC = 'wamp.session.list'; |
||
30 | const SESSION_INFO_TOPIC = 'wamp.session.get'; |
||
31 | |||
32 | /** |
||
33 | * @var array monitored session ids |
||
34 | */ |
||
35 | protected $sessionIds = []; |
||
36 | |||
37 | /** |
||
38 | * @var int subscription id for on_join |
||
39 | */ |
||
40 | protected $joinSubscriptionId = 0; |
||
41 | |||
42 | /** |
||
43 | * @var int subscription id for on_leave |
||
44 | */ |
||
45 | protected $leaveSubscriptionId = 0; |
||
46 | |||
47 | /** |
||
48 | * Constructor. |
||
49 | * |
||
50 | * @param ClientSession $session |
||
51 | */ |
||
52 | public function __construct(ClientSession $session) |
||
57 | |||
58 | /** |
||
59 | * Retrieves the session-info for given sessionId |
||
60 | * and populates it in via given callback. |
||
61 | * |
||
62 | * @param $sessionId |
||
63 | * @param callable $callback |
||
64 | * |
||
65 | * @return mixed |
||
66 | */ |
||
67 | public function getSessionInfo($sessionId, callable $callback = null) |
||
81 | |||
82 | /** |
||
83 | * Retrieves the Ids of the sessions currently |
||
84 | * registered on the wamp-router in the monitor's realm |
||
85 | * and populates the data via given callback,. |
||
86 | * |
||
87 | * @param callable $callback |
||
88 | * |
||
89 | * @return mixed |
||
90 | */ |
||
91 | public function getSessionIds(callable $callback) |
||
101 | |||
102 | /** |
||
103 | * Checks if a session id is known. |
||
104 | * |
||
105 | * @param $sessionId |
||
106 | * |
||
107 | * @return bool |
||
108 | */ |
||
109 | public function hasSessionId($sessionId) |
||
113 | |||
114 | /** |
||
115 | * Removes a session id. |
||
116 | * |
||
117 | * @param int $sessionId |
||
118 | */ |
||
119 | protected function removeSessionId($sessionId) |
||
129 | |||
130 | /** |
||
131 | * Checks if a session is known by extracting its id. |
||
132 | * |
||
133 | * @param $sessionInfo |
||
134 | * |
||
135 | * @return bool |
||
136 | */ |
||
137 | protected function hasSession($sessionInfo) |
||
141 | |||
142 | /** |
||
143 | * Adds and publishes a joined session. |
||
144 | * |
||
145 | * @param $sessionInfo |
||
146 | */ |
||
147 | protected function addSession($sessionInfo) |
||
152 | |||
153 | /** |
||
154 | * Validates the sessionInfo sent from the router. |
||
155 | * |
||
156 | * @param string $sessionInfo |
||
157 | * |
||
158 | * @return bool |
||
159 | */ |
||
160 | protected function validateSessionInfo($sessionInfo) |
||
164 | |||
165 | /** |
||
166 | * Initializes the subscription to the meta-events. |
||
167 | */ |
||
168 | protected function initSetupCalls() |
||
191 | |||
192 | /** |
||
193 | * Retrieves the list of current sessionIds on the router. |
||
194 | * |
||
195 | * @param callable|null $callback |
||
196 | */ |
||
197 | protected function retrieveSessionIds(callable $callback = null) |
||
208 | |||
209 | protected function getSessionIdRetrievalCallback() |
||
221 | |||
222 | protected function setList($list) |
||
226 | |||
227 | protected function getList() |
||
231 | |||
232 | /** |
||
233 | * remove the sessionID of the Monitor from the list. |
||
234 | * |
||
235 | * @param array $sessionsIds |
||
236 | * |
||
237 | * @return mixed |
||
238 | */ |
||
239 | protected function removeOwnSessionId(array $sessionsIds) |
||
249 | } |
||
250 |