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