@@ -12,14 +12,16 @@ def __init__(self):
12
12
self .event = asyncio .Event ()
13
13
self .queue = []
14
14
15
- async def send (self , data , event = None ):
15
+ async def send (self , data , event = None , event_id = None ):
16
16
"""Send an event to the client.
17
17
18
18
:param data: the data to send. It can be given as a string, bytes, dict
19
19
or list. Dictionaries and lists are serialized to JSON.
20
20
Any other types are converted to string before sending.
21
21
:param event: an optional event name, to send along with the data. If
22
22
given, it must be a string.
23
+ :param event_id: an optional event id, to send along with the data. If
24
+ given, it must be a string.
23
25
"""
24
26
if isinstance (data , (dict , list )):
25
27
data = json .dumps (data ).encode ()
@@ -28,6 +30,8 @@ async def send(self, data, event=None):
28
30
elif not isinstance (data , bytes ):
29
31
data = str (data ).encode ()
30
32
data = b'data: ' + data + b'\n \n '
33
+ if event_id :
34
+ data = b'id: ' + event_id .encode () + b'\n ' + data
31
35
if event :
32
36
data = b'event: ' + event .encode () + b'\n ' + data
33
37
self .queue .append (data )
0 commit comments