File tree Expand file tree Collapse file tree 2 files changed +11
-5
lines changed
Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change 11import os
2+ import logging
3+ import asyncio
4+
25from 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
69load_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'
Original file line number Diff line number Diff 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
5555asyncio .run (main ())
You can’t perform that action at this time.
0 commit comments