1 | <?php |
||
25 | class SessionMonitor implements MonitorInterface, EventEmitterInterface |
||
26 | { |
||
27 | use MonitorTrait; |
||
28 | |||
29 | const SESSION_JOIN_TOPIC = 'wamp.session.on_join'; |
||
30 | const SESSION_LEAVE_TOPIC = 'wamp.session.on_leave'; |
||
31 | const SESSION_COUNT_TOPIC = 'wamp.session.count'; |
||
32 | const SESSION_LIST_TOPIC = 'wamp.session.list'; |
||
33 | const SESSION_INFO_TOPIC = 'wamp.session.get'; |
||
34 | |||
35 | /** |
||
36 | * @var array monitored session ids |
||
37 | */ |
||
38 | protected $sessionIds = []; |
||
39 | |||
40 | /** |
||
41 | * @var int subscription id for on_join |
||
42 | */ |
||
43 | protected $joinSubscriptionId = 0; |
||
44 | |||
45 | /** |
||
46 | * @var int subscription id for on_leave |
||
47 | */ |
||
48 | protected $leaveSubscriptionId = 0; |
||
49 | |||
50 | /** |
||
51 | * Constructor. |
||
52 | * |
||
53 | * @param ClientSession $session |
||
54 | */ |
||
55 | public function __construct(ClientSession $session) |
||
60 | |||
61 | /** |
||
62 | * Retrieves the session-info for given sessionId |
||
63 | * and populates it in via given callback. |
||
64 | * |
||
65 | * @param $sessionId |
||
66 | * |
||
67 | * @return PromiseInterface |
||
68 | */ |
||
69 | public function getSessionInfo($sessionId) |
||
82 | |||
83 | /** |
||
84 | * Retrieves the Ids of the sessions currently |
||
85 | * registered on the wamp-router in the monitor's realm |
||
86 | * and populates the data via given callback,. |
||
87 | * |
||
88 | * @return PromiseAdapter |
||
89 | */ |
||
90 | public function getSessionIds() |
||
102 | |||
103 | /** |
||
104 | * Checks if a session id is known. |
||
105 | * |
||
106 | * @param $sessionId |
||
107 | * |
||
108 | * @return bool |
||
109 | */ |
||
110 | public function hasSessionId($sessionId) |
||
114 | |||
115 | /** |
||
116 | * Removes a session id. |
||
117 | * |
||
118 | * @param int $sessionId |
||
119 | */ |
||
120 | protected function removeSessionId($sessionId) |
||
130 | |||
131 | /** |
||
132 | * Checks if a session is known by extracting its id. |
||
133 | * |
||
134 | * @param $sessionInfo |
||
135 | * |
||
136 | * @return bool |
||
137 | */ |
||
138 | protected function hasSession($sessionInfo) |
||
142 | |||
143 | /** |
||
144 | * Adds and publishes a joined session. |
||
145 | * |
||
146 | * @param $sessionInfo |
||
147 | */ |
||
148 | protected function addSession($sessionInfo) |
||
153 | |||
154 | /** |
||
155 | * Validates the sessionInfo sent from the router. |
||
156 | * |
||
157 | * @param string $sessionInfo |
||
158 | * |
||
159 | * @return bool |
||
160 | */ |
||
161 | protected function validateSessionInfo($sessionInfo) |
||
165 | |||
166 | /** |
||
167 | * Initializes the subscription to the meta-events. |
||
168 | */ |
||
169 | protected function initSetupCalls() |
||
192 | |||
193 | /** |
||
194 | * Retrieves the list of current sessionIds on the router. |
||
195 | * |
||
196 | * @return PromiseAdapter |
||
197 | */ |
||
198 | protected function retrieveSessionIds() |
||
206 | |||
207 | /** |
||
208 | * @return \Closure |
||
209 | */ |
||
210 | protected function getSessionIdRetrievalCallback() |
||
220 | |||
221 | /** |
||
222 | * @param $list |
||
223 | */ |
||
224 | protected function setList($list) |
||
228 | |||
229 | /** |
||
230 | * @return array |
||
231 | */ |
||
232 | protected function getList() |
||
236 | |||
237 | /** |
||
238 | * remove the sessionID of the Monitor from the list. |
||
239 | * |
||
240 | * @param array $sessionsIds |
||
241 | * |
||
242 | * @return mixed |
||
243 | */ |
||
244 | protected function removeOwnSessionId(array $sessionsIds) |
||
255 | |||
256 | public static function create(ClientSession $session) |
||
260 | } |
||
261 |