Delegate DelegateOnClose
Represents the method that will be invoked when the data channel has been closed and is no longer available for communication.
Namespace: Unity.WebRTC
Assembly: Unity.WebRTC.dll
Syntax
public delegate void DelegateOnClose()
Remarks
The DelegateOnClose
is triggered when the data channel's underlying transport is terminated, signaling that no further messages can be sent or received.
Useful for cleaning up resources or notifying the application that the data channel is no longer in use.
This marks a transition to a non-operational state, and to resume communication, a new data channel must be established.
This delegate is typically assigned to the OnClose property.
Examples
using UnityEngine;
using Unity.WebRTC;
public class DataChannelCloseExample : 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 OnClose event
dataChannel.OnClose = () =>
{
Debug.Log("DataChannel has been closed.");
};
}
}