Class: Google::Genai::Session
- Inherits:
-
Object
- Object
- Google::Genai::Session
- Defined in:
- lib/google/genai/live.rb
Instance Method Summary collapse
-
#initialize(websocket) ⇒ Session
constructor
A new instance of Session.
- #receive ⇒ Object
- #send_client_content(turns:, turn_complete: true) ⇒ Object
Constructor Details
#initialize(websocket) ⇒ Session
Returns a new instance of Session.
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/google/genai/live.rb', line 51 def initialize(websocket) @ws = websocket @message_queue = Queue.new @ws.on :message do |msg| @message_queue.push(JSON.parse(msg.data)) end @ws.on :error do |err| # For now, just print the error. A more robust error handling can be added. puts "WebSocket Error: #{err.}" end end |
Instance Method Details
#receive ⇒ Object
75 76 77 |
# File 'lib/google/genai/live.rb', line 75 def receive @message_queue.pop end |
#send_client_content(turns:, turn_complete: true) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/google/genai/live.rb', line 65 def send_client_content(turns:, turn_complete: true) = { clientContent: { turns: turns, turnComplete: turn_complete } } @ws.send(.to_json) end |