Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring project and publish/send API #1

Merged
merged 2 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ client.on('topic1.*', handle_message)
Publish messages to a topic:

```python
await client.publish('topic1', 'Hello, world!', {
'messageType': 'text-message',
})
await client.publish('topic1', 'Hello, world!', message_type='text-message')
```

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

```python
waiter = await client.publish('secure/peer-to-peer1', 'Hi', {
'messageType': 'greeting',
})
waiter = await client.publish('secure/peer-to-peer1', 'Hi', message_type='text-message')
await waiter.wait_for_ack()
```

Expand All @@ -141,9 +137,7 @@ Wait for the Realtime Gateway acknowledgement after sending a message:
```python
waiter = await client.send({
# Message payload
}, {
'messageType': 'create',
})
}, message_type='create')
await waiter.wait_for_ack()
```

Expand All @@ -152,9 +146,7 @@ Wait for a reply with a timeout:
```python
waiter = await client.send({
# Message payload
}, {
'messageType': 'create',
})
}, message_type='create')
await waiter.wait_for_reply(timeout=5) # Wait for up to 5 seconds
```

Expand Down Expand Up @@ -217,15 +209,15 @@ Creates a new `RealtimeClient` instance.
await client.unsubscribe_remote_topic(topic)
```

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

```python
waiter = await client.publish(topic, payload, options)
waiter = await client.publish(topic, payload)
```

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

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

```python
waiter = await client.send(payload, options)
Expand Down
8 changes: 2 additions & 6 deletions demos/publish_and_reply.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ async def handle_session_started(message):
await client.wait_for('session.started')

# Send a message
wait_for = await client.send('Hello, world!', {
'messageType': 'text-message'
})
wait_for = await client.send('Hello, world!', message_type='text-message')
await wait_for.wait_for_ack()

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

wait_for = await client.publish('chat', 'Hello out there!', {
'messageType': 'text-message'
})
wait_for = await client.publish('chat', 'Hello out there!', message_type='text-message')
response = await wait_for.wait_for_reply()
print('Reply:', response)

Expand Down
4 changes: 1 addition & 3 deletions demos/rpc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ async def get_url():
# Define a message handler
async def handle_session_started(message):
client.logger.info('Requesting server time...')
waiter = await client.send('', {
'messageType': 'gettime'
})
waiter = await client.send('', message_type='gettime')

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