Skip to content

Commit 5fb349a

Browse files
committed
source code cleanup
1 parent b10f37d commit 5fb349a

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

demos/publish_and_reply.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import os
2+
import logging
3+
import asyncio
4+
25
from dotenv import load_dotenv
3-
from realtime_pubsub_client import *
6+
from realtime_pubsub_client import RealtimeClient
47

58
# Load variables from .env into os.environ
69
load_dotenv()
@@ -26,16 +29,19 @@ async def get_url():
2629
}
2730
client = RealtimeClient(config)
2831

29-
# Connect to the WebSocket server
30-
await client.connect()
31-
3232
# Define a message handler
3333
async def handle_session_started(message):
3434
print('Session started:', message)
3535
await client.subscribe_remote_topic('chat')
3636

3737
client.on('session.started', handle_session_started)
3838

39+
# Connect to the WebSocket server
40+
await client.connect()
41+
42+
# Wait for the session.started event
43+
await client.wait_for('session.started')
44+
3945
# Send a message
4046
wait_for = await client.send('Hello, world!', {
4147
'messageType': 'text-message'

demos/rpc/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ async def get_url():
3333
# Connect to the WebSocket server
3434
await client.connect()
3535

36-
3736
# Define a message handler
3837
async def handle_session_started(message):
3938
client.logger.info('Requesting server time...')
@@ -51,5 +50,6 @@ async def handle_session_started(message):
5150
while client.ws and not client.ws.closed:
5251
await asyncio.sleep(1)
5352

53+
5454
# Run the main coroutine
5555
asyncio.run(main())

0 commit comments

Comments
 (0)