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.
18 using System.Runtime.InteropServices;
21 namespace Tizen.Multimedia.Remoting
24 /// Provides data for the <see cref="WebRTCDataChannel.MessageReceived"/> event.
26 /// <since_tizen> 9 </since_tizen>
27 public class WebRTCDataChannelMessageReceivedEventArgs : EventArgs
29 internal WebRTCDataChannelMessageReceivedEventArgs(DataChannelType type, IntPtr message)
33 if (type == DataChannelType.Strings)
35 Message = Marshal.PtrToStringAnsi(message);
39 NativeDataChannel.GetData(message, out IntPtr data, out ulong size).
40 ThrowIfFailed("Failed to get data");
42 Data = new byte[(int)size];
43 Marshal.Copy(data, Data, 0, (int)size);
48 /// Gets the data channel type.
50 /// <value>The data channel type.</value>
51 /// <since_tizen> 9 </since_tizen>
52 public DataChannelType Type { get; }
55 /// Gets the string message from remote peer.
58 /// If <see cref="WebRTCDataChannelMessageReceivedEventArgs.Type"/> is <see cref="DataChannelType.Bytes"/>, this property is null.
60 /// <value>The message.</value>
61 /// <since_tizen> 9 </since_tizen>
62 public string Message { get; }
64 #pragma warning disable CA1819 // the purpose of this member is to pass received data to user, no need to protect it from changes
66 /// Gets the byte data from remote peer.
69 /// If <see cref="WebRTCDataChannelMessageReceivedEventArgs.Type"/> is <see cref="DataChannelType.Strings"/>, this property is null.
71 /// <value>The message.</value>
72 /// <since_tizen> 9 </since_tizen>
73 public byte[] Data { get; }
74 #pragma warning restore CA1819
77 /// Returns a string that represents the current object.
79 /// <returns>A string that represents the current object.</returns>
80 /// <since_tizen> 9 </since_tizen>
81 public override string ToString() => $"Channel type={Type}, Message={Message}";