open3d.visualization.webrtc_server.register_data_channel_message_callback#

open3d.visualization.webrtc_server.register_data_channel_message_callback(class_name, callback)#

Register callback for a data channel message.

When the data channel receives a valid JSON string, the class_name property of the JSON object will be examined and the corresponding callback function will be called. The string return value of the callback will be sent back as a reply, if it is not empty.

Note

Ordering between the message and the reply is not guaranteed, since some messages may take longer to process than others. If ordering is important, use a unique message id for every message and include it in the reply.

# Register callback in Python
import open3d as o3d
o3d.visualization.webrtc_server.enable_webrtc()
def send_ack(data):
    print(data)
    return "Received WebRTC data channel message with data: " + data

o3d.visualization.webrtc_server.register_data_channel_message_callback(
    "webapp/input", send_ack)
/* Send message in JavaScript to trigger callback. this is WebRTCStreamer object */
this.dataChannel.send('{"class_name":"webapp/input", "data":"Test event"}')
Parameters:
  • class_name (str) – The value of of the class_name property of the JSON object.

  • callback (Callable[[str], str]) – The callback function that will be called when a JSON object with the matching class_name is received via the data channel. The function should accept a string argument (corresponding to the event data, such as form data or updated value of a slider) and return a string.

Returns:

None