LiveKit ESP32 SDK v0.3.3
Loading...
Searching...
No Matches
livekit_rpc.h
1/*
2 * Copyright 2025 LiveKit, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <stdbool.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
27#define LIVEKIT_RPC_MAX_PAYLOAD_BYTES 15360 // 15 KB
28
30typedef enum {
32 LIVEKIT_RPC_RESULT_OK = 0,
33
35 LIVEKIT_RPC_RESULT_APPLICATION = 1500,
36
38 LIVEKIT_RPC_RESULT_CONNECTION_TIMEOUT = 1501,
39
41 LIVEKIT_RPC_RESULT_RESPONSE_TIMEOUT = 1502,
42
44 LIVEKIT_RPC_RESULT_RECIPIENT_DISCONNECTED = 1503,
45
47 LIVEKIT_RPC_RESULT_RESPONSE_PAYLOAD_TOO_LARGE = 1504,
48
50 LIVEKIT_RPC_RESULT_SEND_FAILED = 1505,
51
53 LIVEKIT_RPC_RESULT_UNSUPPORTED_METHOD = 1400,
54
56 LIVEKIT_RPC_RESULT_RECIPIENT_NOT_FOUND = 1401,
57
59 LIVEKIT_RPC_RESULT_REQUEST_PAYLOAD_TOO_LARGE = 1402,
60
62 LIVEKIT_RPC_RESULT_UNSUPPORTED_SERVER = 1403,
63
65 LIVEKIT_RPC_RESULT_UNSUPPORTED_VERSION = 1404
66} livekit_rpc_result_code_t;
67
69typedef struct {
71 char* id;
72
75 livekit_rpc_result_code_t code;
76
79
81 char* payload;
83
85typedef struct {
87 char* id;
88
90 char* method;
91
94
100 char* payload;
101
103 bool (*send_result)(const livekit_rpc_result_t* res, void* ctx);
104
106 void *ctx;
108
111typedef void (*livekit_rpc_handler_t)(const livekit_rpc_invocation_t* invocation, void* ctx);
112
117#define livekit_rpc_return_ok(_payload) \
118 invocation->send_result(&(livekit_rpc_result_t){ \
119 .id = invocation->id, \
120 .code = LIVEKIT_RPC_RESULT_OK, \
121 .payload = (_payload), \
122 .error_message = NULL \
123 }, invocation->ctx)
124
129#define livekit_rpc_return_error(_error_message) \
130 invocation->send_result(&(livekit_rpc_result_t){ \
131 .id = invocation->id, \
132 .code = LIVEKIT_RPC_RESULT_APPLICATION, \
133 .payload = NULL, \
134 .error_message = (_error_message) \
135 }, invocation->ctx);
136
137#ifdef __cplusplus
138}
139#endif
void(* livekit_rpc_handler_t)(const livekit_rpc_invocation_t *invocation, void *ctx)
Handler for an RPC invocation.
Definition livekit_rpc.h:111
char * id
Invocation identifier.
Definition livekit_rpc.h:71
char * payload
Payload returned to the caller.
Definition livekit_rpc.h:81
char * payload
Caller provided payload.
Definition livekit_rpc.h:100
char * method
The name of the method being invoked.
Definition livekit_rpc.h:90
char * id
Invocation identifier.
Definition livekit_rpc.h:87
void * ctx
Context for the callback.
Definition livekit_rpc.h:106
livekit_rpc_result_code_t code
The error code if the RPC method failed.
Definition livekit_rpc.h:75
char * error_message
Optional, textual description of the error that occurred.
Definition livekit_rpc.h:78
char * caller_identity
Participant identity of the caller.
Definition livekit_rpc.h:93
bool(* send_result)(const livekit_rpc_result_t *res, void *ctx)
Sends the result of the invocation to the caller.
Definition livekit_rpc.h:103
Details about an RPC method invocation.
Definition livekit_rpc.h:85
The result of an RPC method invocation.
Definition livekit_rpc.h:69