-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.py
58 lines (39 loc) · 1.29 KB
/
client.py
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
from util import Singleton
class ClientManager(Singleton):
clients = []
def find(self, uuid):
for element in self.clients:
if element.uuid == uuid:
return element
return None
def find_users(self, uuid):
result = []
for element in self.clients:
if element.__class__.__name__ == 'UserClient':
if element.target_id == uuid:
result.append(element)
return result
def delete(self, uuid):
for element in self.clients:
if element.uuid == uuid:
self.clients.remove(element)
def all(self):
return self.clients
class Client:
id = ''
type = ''
uuid = ''
def __init__(self, client_id, client_type, uuid):
self.id = client_id # socket session id
self.type = client_type # bridge, user
self.uuid = uuid # base62 identifier
ClientManager.instance().clients.append(self)
class BridgeClient(Client):
def __init__(self, client_id, uuid):
super().__init__(client_id, 'bridge', uuid)
class UserClient(Client):
target_id = ''
rooms = []
def __init__(self, client_id, uuid, target_id):
self.target_id = target_id
super().__init__(client_id, 'user', uuid)