3
3
namespace DEMO3 ;
4
4
5
5
use MockModel \MyMockModel ;
6
+ use Thruway \Logging \Logger ;
6
7
7
8
/**
8
9
* Class InternalClient3 based on Examples/MetaEvent/InternalClient.php
@@ -32,7 +33,16 @@ public function __construct()
32
33
*/
33
34
public function onSessionStart ($ session , $ transport )
34
35
{
35
- echo "--------------- Hello from InternalClient ------------ \n" ;
36
+ Logger::debug ($ this , "--------------- Hello from InternalClient ------------ " );
37
+ Logger::debug ($ this , "registering getphpversion " );
38
+ Logger::debug ($ this , "registering getonline " );
39
+ Logger::debug ($ this , "registering getfreespace " );
40
+ Logger::debug ($ this , "registering getMockData " );
41
+ Logger::debug ($ this , "registering isTheUserConnected " );
42
+ Logger::debug ($ this , "registering ws_login " );
43
+ Logger::debug ($ this , "listenint for wamp.metaevent.session.on_join events " );
44
+ Logger::debug ($ this , "listening for wamp.metaevent.session.on_leave events " );
45
+
36
46
$ session ->register ('com.example.getphpversion ' , [$ this , 'getPhpVersion ' ]);
37
47
$ session ->register ('com.example.getonline ' , [$ this , 'getOnline ' ]);
38
48
$ session ->register ('com.example.getfreespace ' , [$ this , 'getFreeSpace ' ]);
@@ -59,6 +69,7 @@ public function getPhpVersion()
59
69
*/
60
70
public function getFreeSpace ()
61
71
{
72
+ Logger::debug ($ this , "internal client: managing RPC getFreeSpace " );
62
73
return ["Free space: " . (string )disk_free_space ('/ ' )];
63
74
// return [disk_free_space('c:')]; // use c: for you windowers
64
75
}
@@ -68,6 +79,7 @@ public function getFreeSpace()
68
79
*/
69
80
public function getMockData (): array
70
81
{
82
+ Logger::debug ($ this , "internal client: managing RPC getMockData " );
71
83
return MyMockModel::getMyMockData ();
72
84
}
73
85
@@ -78,6 +90,7 @@ public function getMockData(): array
78
90
*/
79
91
public function getOnline ()
80
92
{
93
+ Logger::debug ($ this , "internal client: managing RPC getOnline " );
81
94
return [$ this ->_sessions ];
82
95
}
83
96
@@ -110,18 +123,26 @@ public function isTheUserConnected($args)
110
123
*/
111
124
public function ws_login ($ args )
112
125
{
126
+ Logger::debug ($ this , "internal client: managing RPC ws_login, args: " . json_encode ($ args ));
113
127
$ marked = false ;
128
+ $ array_args = self ::toArray ($ args [0 ]);
114
129
foreach ($ this ->_sessions as $ ws_id => $ ws_data ){
115
- if ($ ws_id == $ args [1 ]){
116
- $ this ->_sessions [$ ws_id ]['user_id ' ] = $ args [0 ];
130
+ if ($ ws_id == $ array_args ['ws_session_id ' ]){
131
+ $ this ->_sessions [$ ws_id ]['user_id ' ] = $ array_args ['user_id ' ];
132
+ $ this ->_sessions [$ ws_id ]['user_data ' ] = MyMockModel::getUserById ($ array_args ['user_id ' ]);
117
133
$ marked = true ;
118
134
break ;
119
135
}
120
136
}
121
137
122
138
if ($ marked ){
123
139
return [
124
- "ws_session_data " => $ this ->_sessions [$ ws_id ]
140
+ "ws_session_data " => $ this ->_sessions [$ ws_id ],
141
+ "callback " => [
142
+ "is_rpc " => true ,
143
+ "method " => "com.example.getonline " ,
144
+ //"args" => [],
145
+ ],
125
146
];
126
147
}else {
127
148
// something went wrong
@@ -143,11 +164,12 @@ public function ws_login($args)
143
164
*/
144
165
public function onSessionJoin ($ args , $ kwArgs , $ options )
145
166
{
167
+ Logger::debug ($ this , "internal client: event onSessionJoin " );
146
168
$ data = self ::toArray ($ args );
147
169
$ ws_session_id = $ data [0 ]["session " ];
148
170
$ realm = $ data [0 ]["realm " ];
149
171
150
- echo "Session {$ data [0 ]['session ' ]} joinned \n" ;
172
+ Logger:: debug ( $ this , "Session {$ data [0 ]['session ' ]} joinned " ) ;
151
173
$ this ->_sessions [$ ws_session_id ] = [
152
174
"ws_session_id " => $ ws_session_id ,
153
175
"realm " => $ realm ,
@@ -166,21 +188,25 @@ public function onSessionJoin($args, $kwArgs, $options)
166
188
*/
167
189
public function onSessionLeave ($ args , $ kwArgs , $ options )
168
190
{
191
+ Logger::debug ($ this , "internal client: event onSessionLeave " );
169
192
$ data = self ::toArray ($ args );
170
193
$ ws_session_id = $ data [0 ]["session " ];
171
194
172
195
if (!empty ($ ws_session_id )) {
173
196
174
- foreach ($ this ->_sessions as $ ws_session_id => $ ws_session_data ){
175
- if ($ ws_session_id == $ ws_session_data [ " ws_session_id " ] ){
176
- echo "Session {$ ws_session_id } leaved \n" ;
197
+ foreach ($ this ->_sessions as $ _session_id => $ _session_data ){
198
+ if ($ ws_session_id == $ _session_id ){
199
+ Logger:: debug ( $ this , "Session {$ ws_session_id } leaved " ) ;
177
200
unset ($ this ->_sessions [$ ws_session_id ]);
178
201
return ;
179
202
}
180
203
}
181
204
}
182
205
}
183
206
207
+ /**
208
+ * @param object|string $object
209
+ */
184
210
private static function toArray ($ object )
185
211
{
186
212
return json_decode (json_encode ($ object ), true );
0 commit comments