Class: Google::Genai::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/google/genai/live.rb

Instance Method Summary collapse

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.message}"
  end
end

Instance Method Details

#receiveObject



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)
  message = {
    clientContent: {
      turns: turns,
      turnComplete: turn_complete
    }
  }
  @ws.send(message.to_json)
end