@@ -24,7 +24,7 @@ public function __construct($io, $logger){
24
24
}
25
25
26
26
public function getClient ($ socket ){
27
- $ client = $ socket ->client ;
27
+ $ client = $ socket ->ppsClient ;
28
28
if ($ this ->clients ->hasKey ($ client ->getId ())){
29
29
return $ client ;
30
30
}
@@ -33,16 +33,16 @@ public function getClient($socket){
33
33
34
34
public function connect ($ socket ){
35
35
$ client = new Client ($ socket ->id , $ socket );
36
- $ socket ->client = $ client ;
36
+ $ socket ->ppsClient = $ client ;
37
37
$ this ->clients ->add ($ client );
38
38
39
- $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " . $ socket ->conn ->remoteAddress .": connected with ID: " + $ socket ->id );
39
+ $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " . $ socket ->conn ->remoteAddress .": connected with ID: " . $ socket ->id . " (ONLINE: " . sizeof ( $ this -> clients ) . " ) " );
40
40
}
41
41
42
42
public function disconnect ($ client ){
43
43
$ this ->clients ->remove ($ client );
44
44
45
- $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " + $ client ->getId () + ": disconnected " );
45
+ $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " . $ client ->getId () . ": disconnected (ONLINE: " . sizeof ( $ this -> clients ) . " ) " );
46
46
}
47
47
48
48
public function message ($ client , $ message ){
@@ -57,7 +57,7 @@ public function message($client, $message){
57
57
"message " => $ message
58
58
]);
59
59
60
- $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " + $ client ->getId () + " message in " + $ room ->getId () + ": " + $ message );
60
+ $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " . $ client ->getId () . " message in " . $ room ->getId () . ": " . $ message );
61
61
}
62
62
}
63
63
@@ -74,18 +74,28 @@ public function toggleResource($client, $resource){
74
74
/**
75
75
* Room management
76
76
*/
77
- public function createRoom ($ client ){
77
+ public function createRoom ($ client, $ offer ){
78
78
do {
79
79
$ roomId = bin2hex (random_bytes (ROOM_HASH_LENGTH ));
80
80
}while ($ this ->rooms ->hasKey ($ roomId ));
81
81
82
- $ this ->rooms ->add (new Room ($ id , $ client ));
82
+ $ room = new Room ($ roomId , $ client );
83
+ $ room ->setData ("offer " , $ offer );
84
+ $ this ->rooms ->add ($ room );
83
85
$ client ->getSocket ()->emit ("created " , $ roomId );
84
86
85
- $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " + $ client ->getId () + " created the room " + $ roomId );
87
+ $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " . $ client ->getId () . " created the room " . $ roomId );
86
88
}
87
89
88
- public function joinRoom ($ client , $ roomId ){
90
+ public function getRoom ($ client , $ roomId ){
91
+ $ room = $ this ->rooms ->get ($ roomId );
92
+ if ($ room !== false ){
93
+ // Getting
94
+ $ client ->getSocket ()->emit ("gotten " , $ room ->getData ("offer " ));
95
+ }
96
+ }
97
+
98
+ public function joinRoom ($ client , $ roomId , $ answer ){
89
99
$ room = $ this ->rooms ->get ($ roomId );
90
100
91
101
$ this ->leaveRoom ($ client );
@@ -94,20 +104,21 @@ public function joinRoom($client, $roomId){
94
104
try {
95
105
$ room ->join ($ client );
96
106
// Joined
107
+ $ room ->setData ("answer " , $ answer );
97
108
$ client ->getSocket ()->emit ("joined " , $ room ->getId ());
98
109
$ room ->getSocket ($ this ->io )->emit ("r_joined " , $ client ->getId ());
99
110
100
- $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " + $ client ->getId () + " joined " + $ roomId );
111
+ $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " . $ client ->getId () . " joined " . $ roomId );
101
112
}catch (RoomIsFullException $ e ){
102
113
// Room is full
103
114
$ client ->getSocket ()->emit ("join_full " );
104
115
105
- $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " + $ client ->getId () + " join failed (full) " + $ roomId );
116
+ $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " . $ client ->getId () . " join failed (full) " . $ roomId );
106
117
}catch (ClientIsBannedException $ e ){
107
118
// Client is banned
108
119
$ client ->getSocket ()->emit ("join_banned " );
109
120
110
- $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " + $ client ->getId () + " join failed (banned) " + $ roomId );
121
+ $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " . $ client ->getId () . " join failed (banned) " . $ roomId );
111
122
}
112
123
}
113
124
@@ -120,7 +131,7 @@ public function leaveRoom($client){
120
131
$ client ->getSocket ()->emit ("left " , $ room ->getId ());
121
132
$ room ->getSocket ($ this ->io )->emit ("r_left " , $ client ->getId ());
122
133
123
- $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " + $ client ->getId () + " left " + $ room ->getId ());
134
+ $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " . $ client ->getId () . " left " . $ room ->getId ());
124
135
}
125
136
}
126
137
@@ -134,17 +145,17 @@ public function kickFromRoom($client, $userId){
134
145
$ clientToKick ->getSocket ()->emit ("kicked " , $ room ->getId ());
135
146
$ room ->getSocket ($ this ->io )->emit ("r_kicked " , $ clientToKick ->getId ());
136
147
137
- $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " + $ client ->getId () + " kicked " + $ clientToKick ->getId () + " from " + $ room ->getId ());
148
+ $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " . $ client ->getId () . " kicked " . $ clientToKick ->getId () . " from " . $ room ->getId ());
138
149
}catch (ClientIsNotOwnerException $ e ){
139
150
// Client is not the owner
140
151
$ client ->getSocket ()->emit ("kick_noprivileges " );
141
152
142
- $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " + $ client ->getId () + " failed kicking (privileges) " + $ clientToKick ->getId () + " from " + $ room ->getId ());
153
+ $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " . $ client ->getId () . " failed kicking (privileges) " . $ clientToKick ->getId () . " from " . $ room ->getId ());
143
154
}catch (ClientIsNotInTheRoomException $ e ){
144
155
// ClientToKick is no longuer in the room
145
156
$ client ->getSocket ()->emit ("kick_notin " );
146
157
147
- $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " + $ client ->getId () + " failed kicking (not in) " + $ clientToKick ->getId () + " from " + $ room ->getId ());
158
+ $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " . $ client ->getId () . " failed kicking (not in) " . $ clientToKick ->getId () . " from " . $ room ->getId ());
148
159
}
149
160
}
150
161
}
@@ -159,17 +170,17 @@ public function banFromRoom($client, $userId){
159
170
$ clientToBan ->getSocket ()->emit ("banned " , $ room ->getId ());
160
171
$ room ->getSocket ($ this ->io )->emit ("r_banned " , $ clientToBan ->getId ());
161
172
162
- $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " + $ client ->getId () + " banned " + $ clientToBan ->getId () + " from " + $ room ->getId ());
173
+ $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " . $ client ->getId () . " banned " . $ clientToBan ->getId () . " from " . $ room ->getId ());
163
174
}catch (ClientIsNotOwnerException $ e ){
164
175
// Client is not the owner
165
176
$ client ->getSocket ()->emit ("ban_noprivileges " );
166
177
167
- $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " + $ client ->getId () + " failed banning (privileges) " + $ clientToBan ->getId () + " from " + $ room ->getId ());
178
+ $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " . $ client ->getId () . " failed banning (privileges) " . $ clientToBan ->getId () . " from " . $ room ->getId ());
168
179
}catch (ClientIsBannedException $ e ){
169
180
// ClientToBan is already banned
170
181
$ client ->getSocket ()->emit ("ban_already " );
171
182
172
- $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " + $ client ->getId () + " failed banning (already) " + $ clientToBan ->getId () + " from " + $ room ->getId ());
183
+ $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " . $ client ->getId () . " failed banning (already) " . $ clientToBan ->getId () . " from " . $ room ->getId ());
173
184
}
174
185
}
175
186
}
@@ -184,15 +195,15 @@ public function unbanFromRoom($client, $userId){
184
195
$ clientToUnban ->getSocket ()->emit ("unbanned " , $ room ->getId ());
185
196
$ room ->getSocket ($ this ->io )->emit ("r_unbanned " , $ clientToUnban ->getId ());
186
197
187
- $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " + $ client ->getId () + " unbanned " + $ clientToUnban ->getId () + " from " + $ room ->getId ());
198
+ $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " . $ client ->getId () . " unbanned " . $ clientToUnban ->getId () . " from " . $ room ->getId ());
188
199
}catch (ClientIsNotOwnerException $ e ){
189
200
// Client is not the owner
190
201
$ client ->getSocket ()->emit ("unban_noprivileges " );
191
- $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " + $ client ->getId () + " failed unbanning (privileges) " + $ clientToUnban ->getId () + " from " + $ room ->getId ());
202
+ $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " . $ client ->getId () . " failed unbanning (privileges) " . $ clientToUnban ->getId () . " from " . $ room ->getId ());
192
203
}catch (ClientIsNotBannedException $ e ){
193
204
// ClientToUnban is not banned
194
205
$ client ->getSocket ()->emit ("unban_notbanned " );
195
- $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " + $ client ->getId () + " failed unbanning (not banned) " + $ clientToUnban ->getId () + " from " + $ room ->getId ());
206
+ $ this ->logger ->info (__FUNCTION__ .": " .__LINE__ .": " . $ client ->getId () . " failed unbanning (not banned) " . $ clientToUnban ->getId () . " from " . $ room ->getId ());
196
207
}
197
208
}
198
209
}
0 commit comments