Pipecat C++ Client SDK 1.0.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
36
38const char* to_string(TransportState state);
39
43 std::string id;
45 std::string name;
47 bool local = false;
48};
49
55 public:
56 virtual ~TransportObserver() = default;
57
59 virtual void on_transport_message(const nlohmann::json& message) = 0;
60
62 virtual void on_bot_connected(const Participant& bot) = 0;
63
65 virtual void on_bot_disconnected(const Participant& bot) = 0;
66
68 virtual void on_participant_joined(const Participant& participant) = 0;
69
71 virtual void on_participant_left(const Participant& participant) = 0;
72
75 virtual void on_transport_error(const std::string& error, bool fatal) = 0;
76
79 virtual void on_transport_disconnected() = 0;
80};
81
88class Transport {
89 public:
90 virtual ~Transport() = default;
91
94 virtual void initialize(TransportObserver* observer) = 0;
95
101 virtual void connect(const nlohmann::json& params) = 0;
102
105 virtual void disconnect() = 0;
106
112 virtual void send_ready_message(const rtvi::Message& message) = 0;
113
115 virtual void send_message(const rtvi::Message& message) = 0;
116
118 virtual size_t max_message_size() const { return 64 * 1024; }
119
122 virtual int32_t
123 send_user_audio(const int16_t* frames, size_t num_frames) = 0;
124
127 virtual int32_t read_bot_audio(int16_t* frames, size_t num_frames) = 0;
128};
129
130} // namespace pipecat
131
132#endif
Definition transport.h:54
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:88
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:118
virtual void send_message(const rtvi::Message &message)=0
Sends a message to the bot. Returns right away.
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:24
@ 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".
Someone in the session, like the bot or another user.
Definition transport.h:41
std::string id
Unique ID of the participant.
Definition transport.h:43
bool local
Whether this is the local user.
Definition transport.h:47
std::string name
Display name. Can be empty.
Definition transport.h:45
Definition messages.h:280