docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    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
            };
        }
    }

    See Also

    OnError
    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)