forked from microsoft/MixedRealityToolkit-Unity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NetworkConnectionAdapter.cs
59 lines (53 loc) · 2.09 KB
/
NetworkConnectionAdapter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
namespace HoloToolkit.Sharing
{
/// <summary>
/// Allows users of NetworkConnection to register to receive event callbacks without
/// having their classes inherit directly from NetworkConnectionListener
/// </summary>
public class NetworkConnectionAdapter : NetworkConnectionListener
{
public event System.Action<NetworkConnection> ConnectedCallback;
public event System.Action<NetworkConnection> ConnectionFailedCallback;
public event System.Action<NetworkConnection> DisconnectedCallback;
public event System.Action<NetworkConnection, NetworkInMessage> MessageReceivedCallback;
public NetworkConnectionAdapter() { }
public override void OnConnected(NetworkConnection connection)
{
Profile.BeginRange("OnConnected");
if (this.ConnectedCallback != null)
{
this.ConnectedCallback(connection);
}
Profile.EndRange();
}
public override void OnConnectFailed(NetworkConnection connection)
{
Profile.BeginRange("OnConnectFailed");
if (this.ConnectionFailedCallback != null)
{
this.ConnectionFailedCallback(connection);
}
Profile.EndRange();
}
public override void OnDisconnected(NetworkConnection connection)
{
Profile.BeginRange("OnDisconnected");
if (this.DisconnectedCallback != null)
{
this.DisconnectedCallback(connection);
}
Profile.EndRange();
}
public override void OnMessageReceived(NetworkConnection connection, NetworkInMessage message)
{
Profile.BeginRange("OnMessageReceived");
if (this.MessageReceivedCallback != null)
{
this.MessageReceivedCallback(connection, message);
}
Profile.EndRange();
}
}
}