2 * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 namespace Tizen.Multimedia.Remoting
23 /// Provides the ability to control WebRTC data channel.
25 /// <since_tizen> 9 </since_tizen>
26 public partial class WebRTCDataChannel
28 private NativeDataChannel.OpenedCallback _webRtcDataChannelOpenedCallback;
29 private NativeDataChannel.ClosedCallback _webRtcDataChannelClosedCallback;
30 private NativeDataChannel.MessageReceivedCallback _webRtcDataChannelMsgRecvCallback;
31 private NativeDataChannel.ErrorOccurredCallback _webRtcDataChannelErrorOccurredCallback;
34 /// Occurs when the data channel's underlying data transport is established.
36 /// <since_tizen> 9 </since_tizen>
37 public event EventHandler<EventArgs> Opened;
40 /// Occurs when the data channel has closed down.
42 /// <since_tizen> 9 </since_tizen>
43 public event EventHandler<EventArgs> Closed;
46 /// Occurs when a message is received from the remote peer.
48 /// <since_tizen> 9 </since_tizen>
49 public event EventHandler<WebRTCDataChannelMessageReceivedEventArgs> MessageReceived;
52 /// Occurs when an error occurs on the data channel.
54 /// <since_tizen> 9 </since_tizen>
55 public event EventHandler<WebRTCDataChannelErrorOccurredEventArgs> ErrorOccurred;
57 private void RegisterEvents()
59 RegisterDataChannelOpenedCallback();
60 RegisterDataChannelClosedCallback();
61 RegisterDataChannelMsgRecvCallback();
62 RegisterDataChannelErrorOccurredCallback();
65 private void RegisterDataChannelOpenedCallback()
67 _webRtcDataChannelOpenedCallback = (dataChannelHandle, _) =>
69 Opened?.Invoke(this, new EventArgs());
72 NativeDataChannel.SetOpenedCb(_handle, _webRtcDataChannelOpenedCallback).
73 ThrowIfFailed("Failed to set data channel opened callback.");
76 private void RegisterDataChannelMsgRecvCallback()
78 _webRtcDataChannelMsgRecvCallback = (dataChannelHandle, type, message, _) =>
80 MessageReceived?.Invoke(this, new WebRTCDataChannelMessageReceivedEventArgs(type, message));
83 NativeDataChannel.SetMessageReceivedCb(_handle, _webRtcDataChannelMsgRecvCallback).
84 ThrowIfFailed("Failed to set data channel message received callback.");
87 private void RegisterDataChannelErrorOccurredCallback()
89 _webRtcDataChannelErrorOccurredCallback = (dataChannelHandle, error, _) =>
91 ErrorOccurred?.Invoke(this, new WebRTCDataChannelErrorOccurredEventArgs((WebRTCError)error));
94 NativeDataChannel.SetErrorOccurredCb(_handle, _webRtcDataChannelErrorOccurredCallback).
95 ThrowIfFailed("Failed to set data channel error callback.");
98 private void RegisterDataChannelClosedCallback()
100 _webRtcDataChannelClosedCallback = (dataChannelHandle, _) =>
102 Closed?.Invoke(this, new EventArgs());
105 NativeDataChannel.SetClosedCb(_handle, _webRtcDataChannelClosedCallback).
106 ThrowIfFailed("Failed to set data channel closed callback.");