Skip to content

Commit b567f3d

Browse files
authored
Refactoring project and publish/send API (#1)
* refactoring project and publish/send API
1 parent e6c537a commit b567f3d

File tree

9 files changed

+232
-235
lines changed

9 files changed

+232
-235
lines changed

README.md

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,7 @@ client.on('topic1.*', handle_message)
101101
Publish messages to a topic:
102102

103103
```python
104-
await client.publish('topic1', 'Hello, world!', {
105-
'messageType': 'text-message',
106-
})
104+
await client.publish('topic1', 'Hello, world!', message_type='text-message')
107105
```
108106

109107
### Responding to Incoming Messages
@@ -130,9 +128,7 @@ client.on('topic1.text-message', handle_message)
130128
Wait for the Realtime Gateway acknowledgement after publishing a message:
131129

132130
```python
133-
waiter = await client.publish('secure/peer-to-peer1', 'Hi', {
134-
'messageType': 'greeting',
135-
})
131+
waiter = await client.publish('secure/peer-to-peer1', 'Hi', message_type='text-message')
136132
await waiter.wait_for_ack()
137133
```
138134

@@ -141,9 +137,7 @@ Wait for the Realtime Gateway acknowledgement after sending a message:
141137
```python
142138
waiter = await client.send({
143139
# Message payload
144-
}, {
145-
'messageType': 'create',
146-
})
140+
}, message_type='create')
147141
await waiter.wait_for_ack()
148142
```
149143

@@ -152,9 +146,7 @@ Wait for a reply with a timeout:
152146
```python
153147
waiter = await client.send({
154148
# Message payload
155-
}, {
156-
'messageType': 'create',
157-
})
149+
}, message_type='create')
158150
await waiter.wait_for_reply(timeout=5) # Wait for up to 5 seconds
159151
```
160152

@@ -217,15 +209,15 @@ Creates a new `RealtimeClient` instance.
217209
await client.unsubscribe_remote_topic(topic)
218210
```
219211

220-
- **`publish(topic, payload, options=None)`**: Publishes a message to a topic.
212+
- **`publish(topic, payload, message_type="broadcast", compress=False, message_id=None)`**: Publishes a message to a topic.
221213

222214
```python
223-
waiter = await client.publish(topic, payload, options)
215+
waiter = await client.publish(topic, payload)
224216
```
225217

226218
Returns a `WaitFor` instance to wait for acknowledgements or replies.
227219

228-
- **`send(payload, options=None)`**: Sends a message to the server.
220+
- **`send(payload, compress=False, message_id=None)`**: Sends a message to the server.
229221

230222
```python
231223
waiter = await client.send(payload, options)

demos/publish_and_reply.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ async def handle_session_started(message):
4343
await client.wait_for('session.started')
4444

4545
# Send a message
46-
wait_for = await client.send('Hello, world!', {
47-
'messageType': 'text-message'
48-
})
46+
wait_for = await client.send('Hello, world!', message_type='text-message')
4947
await wait_for.wait_for_ack()
5048

5149
# Define a message handler
@@ -59,9 +57,7 @@ def handle_message(message, reply_fn):
5957
# Subscribe to chat.text-message events
6058
client.on('chat.text-message', handle_message)
6159

62-
wait_for = await client.publish('chat', 'Hello out there!', {
63-
'messageType': 'text-message'
64-
})
60+
wait_for = await client.publish('chat', 'Hello out there!', message_type='text-message')
6561
response = await wait_for.wait_for_reply()
6662
print('Reply:', response)
6763

demos/rpc/client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ async def get_url():
3535
# Define a message handler
3636
async def handle_session_started(message):
3737
client.logger.info('Requesting server time...')
38-
waiter = await client.send('', {
39-
'messageType': 'gettime'
40-
})
38+
waiter = await client.send('', message_type='gettime')
4139

4240
response, = await waiter.wait_for_reply(timeout=5)
4341
client.logger.info(f"Server time: {response['data']['time']}")

0 commit comments

Comments
 (0)