forked from wkjagt/Extendible-Web-Socket-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.class.php
More file actions
67 lines (60 loc) · 1.39 KB
/
Copy pathuser.class.php
File metadata and controls
67 lines (60 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
class WSBaseUser{
public $id;
public $socket;
public $handshake;
public $idle;
/**
* Maximum number of seconds a client may be idle before being disconnected
*/
protected $maxIdle = 60;//seconds
/**
* Setup new user
*
* @param $id
* Unique id
* @param $socket
* This users socket
*/
public function __construct($id, $socket){
$this->id = $id;
$this->socket = $socket;
$this->resetIdle();
}
/**
* Check if client has been idle too long
*
* @return
* if client has been idle too long (boolean)
*/
public function isIdle(){
return time() - $this->idle > $this->maxIdle;
}
private final function resetIdle(){
$this->idle = time();
}
/**
* Notify that a message was reveived for this user
*/
public function messageReceived($msg){
$this->resetIdle();
}
/**
* Find the owner of a socket
*
* @param
* The socket for which we want to find the owner
* @return
* The owner of the socket
*/
static function getUserBySocket($socket, $users){
$found = null;
foreach($users as $user){
if($user->socket == $socket){
$found = $user;
break;
}
}
return $found;
}
}