-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathpubsub.py
More file actions
117 lines (85 loc) · 3.56 KB
/
pubsub.py
File metadata and controls
117 lines (85 loc) · 3.56 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
from pubnub.models.consumer.message_actions import PNMessageAction
class PNMessageResult(object):
def __init__(self, message, subscription, channel, timetoken, user_metadata=None, publisher=None, message_type=None,
type=None, space_id=None):
if subscription is not None:
assert isinstance(subscription, str)
if channel is not None:
assert isinstance(channel, str)
if publisher is not None:
assert isinstance(publisher, str)
assert isinstance(timetoken, int)
if user_metadata is not None:
assert isinstance(user_metadata, object)
self.message = message
# DEPRECATED: subscribed_channel and actual_channel properties are deprecated
# self.subscribed_channel = subscribed_channel <= now known as subscription
# self.actual_channel = actual_channel <= now known as channel
self.channel = channel
self.subscription = subscription
self.timetoken = timetoken
self.user_metadata = user_metadata
self.publisher = publisher
self.message_type = message_type
self.type = type
self.space_id = space_id
class PNSignalMessageResult(PNMessageResult):
pass
class PNFileMessageResult(PNMessageResult):
def __init__(
self, message, subscription,
channel, timetoken, publisher,
file_url, file_id, file_name
):
super(PNFileMessageResult, self).__init__(message, subscription, channel, timetoken, publisher=publisher)
self.file_url = file_url
self.file_id = file_id
self.file_name = file_name
class PNPresenceEventResult(object):
def __init__(self, event, uuid, timestamp, occupancy, subscription, channel,
timetoken, state, join, leave, timeout, user_metadata=None):
assert isinstance(event, str)
assert isinstance(timestamp, int)
assert isinstance(occupancy, int)
assert isinstance(channel, str)
assert isinstance(timetoken, int)
if user_metadata is not None:
assert isinstance(user_metadata, object)
if state is not None:
assert isinstance(state, dict)
self.event = event
self.uuid = uuid
self.timestamp = timestamp
self.occupancy = occupancy
self.state = state
self.join = join
self.leave = leave
self.timeout = timeout
# DEPRECATED: subscribed_channel and actual_channel properties are deprecated
# self.subscribed_channel = subscribed_channel <= now known as subscription
# self.actual_channel = actual_channel <= now known as channel
self.subscription = subscription
self.channel = channel
self.timetoken = timetoken
self.user_metadata = user_metadata
class PNMessageActionResult(PNMessageAction):
def __init__(self, result):
super(PNMessageActionResult, self).__init__(result)
class PNPublishResult(object):
def __init__(self, envelope, timetoken):
"""
Representation of publish server response
:param timetoken: of publish operation
"""
self.timetoken = timetoken
def __str__(self):
return "Publish success with timetoken %s" % self.timetoken
class PNFireResult(object):
def __init__(self, envelope, timetoken):
"""
Representation of fire server response
:param timetoken: of fire operation
"""
self.timetoken = timetoken
def __str__(self):
return "Fire success with timetoken %s" % self.timetoken