Delegate DelegateOnError
Represents the method that will be invoked when an error occurs on the data channel.
Namespace: Unity.WebRTC
Assembly: Unity.WebRTC.dll
Syntax
public delegate void DelegateOnError(RTCError error)
Parameters
Type | Name | Description |
---|---|---|
RTCError | error | The RTCError object that contains details about the error. |
Remarks
The DelegateOnError
is executed whenever an error arises within the data channel, allowing applications to handle various error scenarios gracefully.
It provides detailed information about the error, enabling developers to implement corrective measures or issue notifications to users.
Handling such errors is crucial for maintaining robust and reliable peer-to-peer communication.
This delegate is typically assigned to the OnError property.
Examples
using UnityEngine;
using Unity.WebRTC;
public class DataChannelErrorHandlingExample : MonoBehaviour
{
private void Start()
{
var initOption = new RTCDataChannelInit();
var peerConnection = new RTCPeerConnection();
var dataChannel = peerConnection.CreateDataChannel("test channel", initOption);
// Assign the delegate to handle the OnError event
dataChannel.OnError = (error) =>
{
Debug.LogError("DataChannel error occurred: " + error.message);
// Additional error handling logic can be implemented here
};
}
}