Pipecat C++ Client SDK 1.3.0
Connect native apps to Pipecat bots
Loading...
Searching...
No Matches
transport.h
Go to the documentation of this file.
1//
2// Copyright (c) 2024-2026, Daily
3//
4// SPDX-License-Identifier: BSD-2-Clause
5//
6
9
10#ifndef PIPECAT_TRANSPORT_H
11#define PIPECAT_TRANSPORT_H
12
14
15#include <nlohmann/json.hpp>
16
17#include <cstddef>
18#include <cstdint>
19#include <string>
20
21namespace pipecat {
22
23struct APIRequest;
24
38
40const char* to_string(TransportState state);
41
45 std::string id;
47 std::string name;
49 bool local = false;
50};
51
57 public:
58 virtual ~TransportObserver() = default;
59
61 virtual void on_transport_message(const nlohmann::json& message) = 0;
62
64 virtual void on_bot_connected(const Participant& bot) = 0;
65
67 virtual void on_bot_disconnected(const Participant& bot) = 0;
68
70 virtual void on_participant_joined(const Participant& participant) = 0;
71
73 virtual void on_participant_left(const Participant& participant) = 0;
74
77 virtual void on_transport_error(const std::string& error, bool fatal) = 0;
78
81 virtual void on_transport_disconnected() = 0;
82};
83
91class Transport {
92 public:
93 virtual ~Transport() = default;
94
97 virtual void initialize(TransportObserver* observer) = 0;
98
105 virtual void set_start_bot_params(const APIRequest& /* request */) {}
106
112 virtual void connect(const nlohmann::json& params) = 0;
113
116 virtual void disconnect() = 0;
117
123 virtual void send_ready_message(const rtvi::Message& message) = 0;
124
126 virtual void send_message(const rtvi::Message& message) = 0;
127
129 virtual size_t max_message_size() const { return 64 * 1024; }
130
133 virtual int32_t
134 send_user_audio(const int16_t* frames, size_t num_frames) = 0;
135
138 virtual int32_t read_bot_audio(int16_t* frames, size_t num_frames) = 0;
139};
140
141} // namespace pipecat
142
143#endif
Definition transport.h:56
virtual void on_transport_disconnected()=0
virtual void on_bot_connected(const Participant &bot)=0
The bot joined the session.
virtual void on_transport_message(const nlohmann::json &message)=0
A message arrived from the bot. message is the RTVI message as JSON.
virtual void on_participant_left(const Participant &participant)=0
Someone other than the bot left the session.
virtual void on_participant_joined(const Participant &participant)=0
Someone other than the bot joined the session.
virtual void on_transport_error(const std::string &error, bool fatal)=0
virtual void on_bot_disconnected(const Participant &bot)=0
The bot left the session.
Definition transport.h:91
virtual void send_ready_message(const rtvi::Message &message)=0
virtual void initialize(TransportObserver *observer)=0
virtual void connect(const nlohmann::json &params)=0
virtual size_t max_message_size() const
The largest message, in bytes, that send_message() accepts.
Definition transport.h:129
virtual void send_message(const rtvi::Message &message)=0
Sends a message to the bot. Returns right away.
virtual void set_start_bot_params(const APIRequest &)
Definition transport.h:105
virtual int32_t read_bot_audio(int16_t *frames, size_t num_frames)=0
virtual void disconnect()=0
virtual int32_t send_user_audio(const int16_t *frames, size_t num_frames)=0
The Pipecat C++ client SDK.
Definition client.h:29
TransportState
The state of the connection to the bot.
Definition transport.h:26
@ Disconnecting
Disconnecting from the bot.
@ Connected
Connected, waiting for the bot to be ready.
@ Initializing
The transport is getting ready.
@ Initialized
The transport is ready to connect.
@ Error
Starting or connecting to the bot failed.
@ Authenticated
The bot was started.
@ Connecting
Connecting to the bot.
@ Ready
The bot is ready.
@ Authenticating
Starting the bot.
@ Disconnected
Not connected.
const char * to_string(TransportState state)
The name of a state, e.g. "ready".
Definition client.h:223
Someone in the session, like the bot or another user.
Definition transport.h:43
std::string id
Unique ID of the participant.
Definition transport.h:45
bool local
Whether this is the local user.
Definition transport.h:49
std::string name
Display name. Can be empty.
Definition transport.h:47
Definition messages.h:379