14 namespace visualization {
15 namespace webrtc_server {
20 [](
const std::string &entry_point,
const std::string &query_string,
21 const std::string &data) {
23 entry_point, query_string, data);
25 "entry_point"_a,
"query_string"_a =
"",
"data"_a =
"",
26 "Emulates CloudViewer WebRTCWindowSystem's HTTP API calls. This is "
28 "when the HTTP handshake server is disabled (e.g. in Jupyter), and "
29 "handshakes are done by this function.");
33 "Use WebRTC streams to display rendered gui window.");
35 "disable_http_handshake",
37 "Disables the HTTP handshake server. In Jupyter environemnt, "
38 "WebRTC handshake is performed by call_http_api() with "
39 "Jupyter's own COMMS interface, thus the HTTP server shall "
42 "register_data_channel_message_callback",
43 [](
const std::string &class_name,
44 std::function<std::string(
const std::string &)>
callback) {
46 ->RegisterDataChannelMessageCallback(class_name,
49 "class_name"_a,
"callback"_a,
51 Register callback for a data channel message.
53 When the data channel receives a valid JSON string, the ``class_name`` property
54 of the JSON object will be examined and the corresponding callback function will
55 be called. The string return value of the callback will be sent back as a reply,
58 .. note:: Ordering between the message and the reply is not guaranteed, since
59 some messages may take longer to process than others. If ordering is important,
60 use a unique message id for every message and include it in the reply.
64 # Register callback in Python
65 import cloudViewer as cv3d
66 cv3d.visualization.webrtc_server.enable_webrtc()
69 return "Received WebRTC data channel message with data: " + data
71 cv3d.visualization.webrtc_server.register_data_channel_message_callback(
72 "webapp/input", send_ack)
76 /* Send message in JavaScript to trigger callback. this is WebRTCStreamer object */
77 this.dataChannel.send('{"class_name":"webapp/input", "data":"Test event"}')
81 m, "register_data_channel_message_callback",
83 "The value of of the ``class_name`` property of the JSON "
86 "The callback function that will be called when a JSON object "
87 "with the matching ``class_name`` is received via the data "
88 "channel. The function should accept a string argument "
89 "(corresponding to the event data, such as form data or updated "
90 "value of a slider) and not return anything."}});
94 py::module m_submodule = m.def_submodule(
"webrtc_server");
std::function< void(std::shared_ptr< core::Tensor >)> callback
static std::shared_ptr< WebRTCWindowSystem > GetInstance()
void FunctionDocInject(py::module &pybind_module, const std::string &function_name, const std::unordered_map< std::string, std::string > &map_parameter_body_docs)
void pybind_webrtc_server(py::module &m)
static void pybind_webrtc_server_functions(py::module &m)
Generic file read and write utility for python interface.