forked from pusher/pusher-websocket-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathApp.cs
40 lines (33 loc) · 1.25 KB
/
App.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
using UnityEngine;
using System.Collections;
public class App : MonoBehaviour {
// isntance of pusher client
PusherClient.Pusher pusherClient = null;
PusherClient.Channel pusherChannel = null;
// Initialize
void Start () {
// TODO: Replace these with your app values
PusherSettings.Verbose = true;
PusherSettings.AppKey = "";
PusherSettings.HttpAuthUrl = "http://richmond.kingdoms.metamoki.com/bin/pusher-auth.php";
pusherClient = new PusherClient.Pusher();
pusherClient.Connected += HandleConnected;
pusherClient.ConnectionStateChanged += HandleConnectionStateChanged;
pusherClient.Connect();
}
void HandleConnected (object sender) {
Debug.Log ( "Pusher client connected, now subscribing to private channel" );
pusherChannel = pusherClient.Subscribe( "private-testchannel" );
pusherChannel.BindAll( HandleChannelEvent );
}
void OnDestroy() {
if( pusherClient != null )
pusherClient.Disconnect();
}
void HandleChannelEvent( string eventName, object evData ) {
Debug.Log ( "Received event on channel, event name: " + eventName + ", data: " + JsonHelper.Serialize(evData) );
}
void HandleConnectionStateChanged (object sender, PusherClient.ConnectionState state) {
Debug.Log ( "Pusher connection state changed to: " + state );
}
}