// Use this for initialization void Start() { connection = new HubConnection(ServerURL); proxy = connection.CreateProxy("DungeonHub"); // subscribe to event proxy.Subscribe("placeEnemy").Data += data => { Debug.Log("new enemy drop"); enemyDto = MapDrop.CreateFromJSON(data[0].ToString()); }; proxy.Subscribe("sayHello").Data += data => { Debug.Log("Hello!"); }; try { connection.Start(); } catch (Exception ex) { Debug.Log(ex.Message); } // store instance of Player player = GameObject.Find("Player"); InvokeRepeating("PlayerMove", movePlayerEvery, movePlayerEvery); }
private async void SetupHub() { _hubConnection = new Microsoft.AspNet.SignalR.Client.HubConnection("http://localhost:1331/"); _auctionProxy = _hubConnection.CreateHubProxy("AuctionHub"); _auctionProxy.Subscribe("UpdateBid").Received += UpdateBid_auctionProxy; _auctionProxy.Subscribe("CloseBid").Received += CloseBid_auctionProxy; _auctionProxy.Subscribe("CloseBidWin").Received += CloseBidWin_auctionProxy; await _hubConnection.Start(); }
async void StartHub() { _hubConnection = new HubConnection("http://192.168.1.148:1331/signalr"); _auctionProxy = _hubConnection.CreateHubProxy("AuctionHub"); _auctionProxy.Subscribe("UpdateBid").Received += UpdateBid_auctionProxy; _auctionProxy.Subscribe("CloseBid").Received += CloseBid_auctionProxy; _auctionProxy.Subscribe("CloseBidWin").Received += CloseBidWin_auctionProxy; await _hubConnection.Start(); }
private async void SetupHub() { _updateDelegate = new UpdateBid(UpdateBidMethod); _updateButtonsDelegate = new UpdateButtons(UpdateButtonsMethod); _hubConnection = new HubConnection("http://192.168.1.148:1331/"); _auctionProxy = _hubConnection.CreateHubProxy("AuctionHub"); _auctionProxy.Subscribe("UpdateBid").Received += UpdateBid_auctionProxy; _auctionProxy.Subscribe("CloseBid").Received += CloseBid_auctionProxy; _auctionProxy.Subscribe("CloseBidWin").Received += CloseBidWin_auctionProxy; await _hubConnection.Start(); }
private bool WaitForConnection() { lock (connectionLock) { if (connection == null) { if (this.ProxyHost != "" && this.ProxyPort != 0) { connection = ConnectionFactory.Create(SocketAddress, this.ProxyHost, this.ProxyPort); } else { connection = ConnectionFactory.Create(SocketAddress); } proxy = connection.CreateHubProxy(HubName); connection.Closed += SocketClosed; connection.Error += SocketError; connection.ConnectionSlow += SocketSlow; connection.StateChanged += SocketStateChange; Subscription sub = proxy.Subscribe(UpdateEvent); sub.Received += SocketMessage; // regular updates Subscription subExchangeState = proxy.Subscribe("updateExchangeState"); subExchangeState.Received += SocketMessageExchangeState; } // Try to start if (TryStart()) { return(true); } // If failed, try to get CloudFlare bypass log.Write(LogVerbosity.Warning, "Couldn't connect to Bittrex server, going to try CloudFlare bypass"); var cookieContainer = CloudFlareAuthenticator.GetCloudFlareCookies(BaseAddress, GetUserAgentString(), CloudFlareRetries); if (cookieContainer == null) { log.Write(LogVerbosity.Error, $"CloudFlareAuthenticator didn't gave us the cookies"); return(false); } connection.Cookies = cookieContainer; connection.UserAgent = GetUserAgentString(); log.Write(LogVerbosity.Debug, "CloudFlare cookies retrieved, retrying connection"); // Try again with cookies return(TryStart()); } }
private async void SetupHub() { _updateDelegate = UpdateBidMethod; _updateButtonsDelegate = UpdateButtonsMethod; _hubConnection = new HubConnection("http://localhost:4558"); _auctionProxy = _hubConnection.CreateHubProxy("AuctionHub"); _auctionProxy.Subscribe("updateBid").Received += OnUpdateBid; _auctionProxy.Subscribe("CloseBid").Received += OnCloseBid; _auctionProxy.Subscribe("CloseBidWin").Received += OnCloseBidWin; await _hubConnection.Start().ConfigureAwait(false); }
public static IDisposable On(this IHubProxy proxy, string eventName, Action <JSONArray> onData) { if (proxy == null) { throw new ArgumentNullException("proxy"); } if (String.IsNullOrEmpty(eventName)) { throw new ArgumentNullException("eventName"); } if (onData == null) { throw new ArgumentNullException("onData"); } Subscription subscription = proxy.Subscribe(eventName); Action <JSONArray> handler = args => { onData(args); }; subscription.Received += handler; return(new DisposableAction(() => subscription.Received -= handler)); }
/// <summary> /// Registers for an event with the specified name and callback /// </summary> /// <param name="proxy">The <see cref="IHubProxy"/>.</param> /// <param name="eventName">The name of the event.</param> /// <param name="onData">The callback</param> /// <returns>An <see cref="IDisposable"/> that represents this subscription.</returns> internal static IDisposable On <T1, T2, T3, T4, T5, T6>(this IHubProxy proxy, string eventName, Action <T1, T2, T3, T4, T5, T6> onData) { if (proxy == null) { throw new ArgumentNullException("proxy"); } if (string.IsNullOrEmpty(eventName)) { throw new ArgumentNullException("eventName"); } if (onData == null) { throw new ArgumentNullException("onData"); } var subscription = proxy.Subscribe(eventName); Action <IList <JToken> > handler = args => { onData ( proxy.JsonSerializer.Convert <T1>(args[0]), proxy.JsonSerializer.Convert <T2>(args[1]), proxy.JsonSerializer.Convert <T3>(args[2]), proxy.JsonSerializer.Convert <T4>(args[3]), proxy.JsonSerializer.Convert <T5>(args[4]), proxy.JsonSerializer.Convert <T6>(args[5]) ); }; subscription.Received += handler; return(Disposable.Create(() => subscription.Received -= handler)); }
/// <summary> /// Registers for an event with the specified name and callback /// </summary> /// <param name="proxy">The <see cref="IHubProxy"/>.</param> /// <param name="eventName">The name of the event.</param> /// <param name="onData">The callback</param> /// <returns>An <see cref="IDisposable"/> that represents this subscription.</returns> public static IDisposable On <T1, T2, T3, T4, T5>(this IHubProxy proxy, string eventName, Action <T1, T2, T3, T4, T5> onData) { if (proxy == null) { throw new ArgumentNullException("proxy"); } if (String.IsNullOrEmpty(eventName)) { throw new ArgumentNullException("eventName"); } if (onData == null) { throw new ArgumentNullException("onData"); } Subscription subscription = proxy.Subscribe(eventName); Action <IList <JToken> > handler = args => { ExecuteCallback(eventName, args.Count, 5, () => { onData(Convert <T1>(args[0], proxy.JsonSerializer), Convert <T2>(args[1], proxy.JsonSerializer), Convert <T3>(args[2], proxy.JsonSerializer), Convert <T4>(args[3], proxy.JsonSerializer), Convert <T5>(args[4], proxy.JsonSerializer)); }); }; subscription.Received += handler; return(new DisposableAction(() => subscription.Received -= handler)); }
/// <summary> /// Registers for an event with the specified name and callback /// </summary> /// <param name="proxy">The <see cref="IHubProxy"/>.</param> /// <param name="eventName">The name of the event.</param> /// <param name="onData">The callback</param> /// <returns>An <see cref="IDisposable"/> that represents this subscription.</returns> public static IDisposable On <T1, T2, T3, T4, T5, T6, T7>(this IHubProxy proxy, string eventName, Action <T1, T2, T3, T4, T5, T6, T7> onData) { if (proxy == null) { throw new ArgumentNullException("proxy"); } if (String.IsNullOrEmpty(eventName)) { throw new ArgumentNullException("eventName"); } if (onData == null) { throw new ArgumentNullException("onData"); } Subscription subscription = proxy.Subscribe(eventName); Action <JToken[]> handler = args => { onData(Convert <T1>(args[0]), Convert <T2>(args[1]), Convert <T3>(args[2]), Convert <T4>(args[3]), Convert <T5>(args[4]), Convert <T6>(args[5]), Convert <T7>(args[6])); }; subscription.Data += handler; return(new DisposableAction(() => subscription.Data -= handler)); }
/// <summary> /// Registers for an event with the specified name and callback /// </summary> /// <param name="proxy">The <see cref="IHubProxy"/>.</param> /// <param name="eventName">The name of the event.</param> /// <param name="onData">The callback</param> /// <returns>An <see cref="IDisposable"/> that represents this subscription.</returns> public static IDisposable On <T>(this IHubProxy proxy, string eventName, Action <T> onData) { if (proxy == null) { throw new ArgumentNullException("proxy"); } if (String.IsNullOrEmpty(eventName)) { throw new ArgumentNullException("eventName"); } if (onData == null) { throw new ArgumentNullException("onData"); } Subscription subscription = proxy.Subscribe(eventName); Action <IList <JToken> > handler = args => { onData(Convert <T>(args[0], proxy.JsonSerializer)); }; subscription.Received += handler; return(new DisposableAction(() => subscription.Received -= handler)); }
void StartSignalR() { if (_hubConnection == null) { _hubConnection = new HubConnection(_baseUrl); _hubConnection.Error += hubConnection_Error; _hubProxy = _hubConnection.CreateProxy("LobbyHub"); _subscriptionPos = _hubProxy.Subscribe("broadcastPosition"); _subscriptionPos.Data += subscriptionPos_Data; _subscriptionRegClient = _hubProxy.Subscribe("broadcastRegClient"); _subscriptionRegClient.Data += subscriptionReg_Data; _subscriptionInitClientInScene = _hubProxy.Subscribe("initClientInScene"); _subscriptionInitClientInScene.Data += subscriptionInit_Data; Task.Run(ConnectToHub); } }
void StartSignalR() { if (_hubConnection == null) { _hubConnection = new HubConnection(signalRUrl); _hubProxy = _hubConnection.CreateProxy("MyHub"); _subscription = _hubProxy.Subscribe("executeCommand"); _subscription.Data += data => { Debug.Log(data[0].ToString()); var message = Newtonsoft.Json.JsonConvert.DeserializeObject<Message>(data[0].ToString()); ActionTrigger = message; }; try { _hubConnection.Start(); } catch (Exception ex) { } } else { Debug.Log("Signalr already connected..."); } }
/// <summary> /// Registers for an event with the specified name and callback /// </summary> /// <param name="proxy">The <see cref="IHubProxy"/>.</param> /// <param name="eventName">The name of the event.</param> /// <param name="onData">The callback</param> /// <returns>An <see cref="IDisposable"/> that represents this subscription.</returns> public static IDisposable On(this IHubProxy proxy, string eventName, Action onData) { if (proxy == null) { throw new ArgumentNullException("proxy"); } if (String.IsNullOrEmpty(eventName)) { throw new ArgumentNullException("eventName"); } if (onData == null) { throw new ArgumentNullException("onData"); } Subscription subscription = proxy.Subscribe(eventName); Action <IList <JToken> > handler = args => { ExecuteCallback(eventName, args.Count, 0, onData); }; subscription.Received += handler; return(new DisposableAction(() => subscription.Received -= handler)); }
static void Main(string[] args) { // uncomment below to stream debug into console // Debug.Listeners.Add(new ConsoleTraceListener()); // this is an optional query parameters to sent with each message var query = new Dictionary <string, string>(); query.Add("version", "1.0"); // initialize connection and its proxy HubConnection connection = new HubConnection("https://quisutdeus.in", query); IHubProxy proxy = connection.CreateProxy("GeneralHub"); // subscribe to event proxy.Subscribe("addNewMessageToPage").Data += data => { /* * var _first = data[0] as JToken; * Console.WriteLine(string.Format("Received: [{0}] from {1}", * _first["message"].ToString(), _first["from"].ToString())); */ }; connection.Closed += () => Console.WriteLine("Closed"); connection.Error += x => Console.WriteLine("Error: " + x.Message); connection.Received += x => Console.WriteLine("Recived: " + x); connection.Reconnected += () => Console.WriteLine("Reconected"); Console.Write("Connecting... "); connection.Start(); Console.WriteLine("done. Hit: "); Console.WriteLine("1:\tSend hello message"); Console.WriteLine("2:\tRequest => Reply with dynamic reply"); Console.WriteLine("3:\tRequest => Reply with value type"); Console.WriteLine("Esc:\tExit"); Console.WriteLine(""); var _exit = false; while (!_exit) { switch (Console.ReadKey(true).Key) { case ConsoleKey.F1: Console.Write("Sending hi... "); proxy.Invoke("SendChatMessage", "JS CLient", "I am working").Finished += (sender, e) => { Console.WriteLine("done"); }; break; case ConsoleKey.Escape: _exit = true; break; } } }
public static IDisposable On(this IHubProxy hubProxy, string eventName, Action onData) { Subscription subscription = hubProxy.Subscribe(eventName); Action <IList <JToken> > received = data => onData(); subscription.Received += received; return(new DisposableAction(() => subscription.Received -= received)); }
public static IDisposable On <T1, T2, T3, T4, T5, T6, T7>(this IHubProxy hubProxy, string eventName, Action <T1, T2, T3, T4, T5, T6, T7> onData) { Subscription subscription = hubProxy.Subscribe(eventName); Action <IList <JToken> > received = data => onData(data[0].ToObject <T1>(), data[1].ToObject <T2>(), data[2].ToObject <T3>(), data[3].ToObject <T4>(), data[4].ToObject <T5>(), data[5].ToObject <T6>(), data[6].ToObject <T7>()); subscription.Received += received; return(new DisposableAction(() => subscription.Received -= received)); }
private void Connect() { hub = new HubConnection(url); proxy = hub.CreateProxy("Game"); //подписки, что-то вроде каналов передачи Subscription sub = proxy.Subscribe("updateModel"); sub.Data += Sub_Update_Data; Subscription sub_create = proxy.Subscribe("createModel"); sub_create.Data += sub_create_Data; Subscription sub_debug = proxy.Subscribe("debug"); Subscription sub_cri = proxy.Subscribe("CriSend"); Subscription sub_leave = proxy.Subscribe("playerleave"); Subscription sub_skill = proxy.Subscribe("skilldata"); Subscription sub_Pos = proxy.Subscribe("Pos"); sub_Pos.Data += Sub_Pos_Data; sub_skill.Data += Sub_skill_Data; sub_cri.Data += Sub_cri_Data; sub_debug.Data += Sub_debug_Data; sub_leave.Data += Sub_leave_Data; StartCoroutine("HubConnect"); StartCoroutine("getmap"); StartCoroutine("sendpos"); StartCoroutine("netcheck"); //proxy.Invoke("CheckConnection"); //proxy.Invoke("GetMap", 0, 0); }
/// <summary> /// Bind a subscription to an event name, and prepare it for disposal. /// </summary> private void BindInnerHandler(MethodCallInfo eventToBind, Action <IList <JToken> > innerHandler) { var subscription = _proxy.Subscribe(eventToBind.MethodName); subscription.Received += innerHandler; DisposalActions.Add(() => { subscription.Received -= innerHandler; }); }
private bool WaitForConnection() { lock (connectionLock) { if (connection == null) { connection = ConnectionFactory.Create(socketAddress); if (apiProxy != null) { connection.SetProxy(apiProxy.Host, apiProxy.Port); } proxy = connection.CreateHubProxy(HubName); connection.Closed += SocketClosed; connection.Error += SocketError; connection.ConnectionSlow += SocketSlow; connection.StateChanged += SocketStateChange; connection.UserAgent = UserAgent; proxy.Subscribe(MarketDeltaEvent).Received += SocketMessageMarketDeltas; proxy.Subscribe(ExchangeStateEvent).Received += SocketMessageExchangeState; } // If failed, try to get CloudFlare bypass log.Write(LogVerbosity.Warning, "Getting CloudFlare cookies"); var sw = Stopwatch.StartNew(); var cookieContainer = CloudFlareAuthenticator.GetCloudFlareCookies(cloudFlareAuthenticationAddress, UserAgent, cloudFlareRetries).ConfigureAwait(false).GetAwaiter().GetResult(); sw.Stop(); log.Write(LogVerbosity.Debug, $"CloudFlare cookie retrieving done in {sw.ElapsedMilliseconds}ms"); if (cookieContainer == null) { log.Write(LogVerbosity.Error, "CloudFlareAuthenticator didn't give us the cookies, trying to start without"); } else { connection.Cookies = cookieContainer; } // Try connecting return(TryStart().ConfigureAwait(false).GetAwaiter().GetResult()); } }
public IDisposable Subscribe(IObserver<IList<JToken>> observer) { var subscription = _proxy.Subscribe(_eventName); subscription.Received += observer.OnNext; return new DisposableAction(() => { subscription.Received -= observer.OnNext; }); }
void Start() { string url = string.Empty; ServerInfo.SetUrl(ref url); connection = new HubConnection(url); proxy = connection.CreateProxy("NotificationsHub"); proxy.Subscribe("FriendNotification").Data += data => { Debug.Log("Notification"); if (OnFriendNotification != null) { var parameters = data[0] as JToken; Notifications.Add(new NotificationObject(parameters["UserId"].ToObject <int>(), parameters["UserNickname"].ToString(), NotificationType.FriendRequest)); } }; proxy.Subscribe("TradeNotification").Data += data => { Debug.Log("Trade not"); if (OnTradeNotification != null) { var parameters = data[0] as JToken; Notifications.Add(new NotificationObject(parameters["UserId"].ToObject <int>(), parameters["UserNickname"].ToString(), NotificationType.TradeRequest)); } }; proxy.Subscribe("DuelNotification").Data += data => { Debug.Log("Duel not"); if (OnDuelNotification != null) { var parameters = data[0] as JToken; Notifications.Add(new NotificationObject(parameters["UserId"].ToObject <int>(), parameters["UserNickname"].ToString(), NotificationType.DuelRequest)); } }; connection.Start(); _connectionStarted = true; StartCoroutine(CheckNotifications()); }
public static Subscription On <T>(this IHubProxy proxy, string eventName, Action <T> onData) { Subscription subscription = proxy.Subscribe(eventName); subscription.Data += args => { onData(Convert <T>(args[0])); }; return(subscription); }
public static Subscription On(this IHubProxy proxy, string eventName, Action onData) { Subscription subscription = proxy.Subscribe(eventName); subscription.Data += args => { onData(); }; return(subscription); }
private static void Subscribe <T>(IHubProxy proxy, T instance, MethodInfo method, ICollection <Action> disposer) { var subscription = proxy.Subscribe(method.Name); var parmTypes = method.GetParameters().Select(i => i.ParameterType).ToArray(); var fastMethod = FastInvokeHandler.Create(method); var invokeHandler = new Action <object[]>(parm => fastMethod.Invoke(instance, parm)); Action <IList <JToken> > handler = args => OnData(parmTypes, args, proxy.JsonSerializer, invokeHandler); subscription.Received += handler; disposer.Add(() => subscription.Received -= handler); }
public IDisposable Subscribe(IObserver <JSONArray> observer) { var subscription = _proxy.Subscribe(_eventName); subscription.Received += observer.OnNext; return(new DisposableAction(() => { subscription.Received -= observer.OnNext; })); }
public IDisposable Subscribe(IObserver <JToken[]> observer) { var subscription = _proxy.Subscribe(_eventName); subscription.Data += observer.OnNext; return(new DisposableAction(() => { subscription.Data -= observer.OnNext; })); }
private async void InitHub() { Logger.Log.Info("Intialzing signalr connection"); _hubConnection = new HubConnection(Shared._ApiUrl); _hubConnection.Headers.Add("Authorization", Shared._Parser.AuthString); _hubProxy = _hubConnection.CreateHubProxy("NotificationHub"); _hubProxy.Subscribe("Notify").Received += HubNotificationReceiver; await _hubConnection.Start(); Logger.Log.Info("signalr connection started"); }
private void btnSend_Click(object sender, EventArgs e) { _hub.Invoke("Send", TbName.Text, TbMessage.Text); _hub.On <string, string>("addMessage", (_name, _message) => Invoke((Action)(() => RtbShow.Text += _name + " " + _message + "\r"))); TbMessage.Text = string.Empty; RtbShow.Text = string.Empty; TbMessage.Focus(); _hub.Subscribe("addMessage"); }
void StartSignalR() { if (_hubConnection == null) { _hubConnection = new HubConnection(_baseUrl); _hubConnection.Error += hubConnection_Error; _hubProxy = _hubConnection.CreateProxy("LobbyHub"); _subscription = _hubProxy.Subscribe("broadcastMess"); _subscription.Data += subscription_Data; Task.Run(ConnectToHub); } }
/// <summary> /// Registers for an event with the specified name and callback /// </summary> /// <param name="proxy">The <see cref="IHubProxy"/>.</param> /// <param name="eventName">The name of the event.</param> /// <param name="onData">The callback</param> /// <returns>An <see cref="IDisposable"/> that represents this subscription.</returns> public static IDisposable On <T>(this IHubProxy proxy, string eventName, Action <T> onData) { Subscription subscription = proxy.Subscribe(eventName); Action <JToken[]> handler = args => { onData(Convert <T>(args[0])); }; subscription.Data += handler; return(new DisposableAction(() => subscription.Data -= handler)); }
/// <summary> /// Registers for an event with the specified name and callback /// </summary> /// <param name="proxy">The <see cref="IHubProxy"/>.</param> /// <param name="eventName">The name of the event.</param> /// <param name="onData">The callback</param> /// <returns>An <see cref="IDisposable"/> that represents this subscription.</returns> public static IDisposable On(this IHubProxy proxy, string eventName, Action onData) { Subscription subscription = proxy.Subscribe(eventName); Action <object[]> handler = args => { onData(); }; subscription.Data += handler; return(new DisposableAction(() => subscription.Data -= handler)); }
private async void Init() { _connection = new HubConnection("http://localhost:54506"); _hub = _connection.CreateHubProxy("chatty"); _hub.Subscribe("spoke").Data += tokens => { var name = tokens[0].ToString(); var message = tokens[1].ToString(); AddMessage(name, message); }; await _connection.Start(); await _hub.Invoke("setName", "Win8Tomas"); }
public static Subscription On <T1, T2, T3, T4>(this IHubProxy proxy, string eventName, Action <T1, T2, T3, T4> onData) { Subscription subscription = proxy.Subscribe(eventName); subscription.Data += args => { onData(Convert <T1>(args[0]), Convert <T2>(args[1]), Convert <T3>(args[2]), Convert <T4>(args[3])); }; return(subscription); }
/// <summary> /// Registers for an event with the specified name and callback /// </summary> /// <param name="proxy">The <see cref="IHubProxy"/>.</param> /// <param name="eventName">The name of the event.</param> /// <param name="onData">The callback</param> /// <returns>An <see cref="IDisposable"/> that represents this subscription.</returns> public static IDisposable On <T1, T2, T3>(this IHubProxy proxy, string eventName, Action <T1, T2, T3> onData) { Subscription subscription = proxy.Subscribe(eventName); Action <object[]> handler = args => { onData(Convert <T1>(args[0]), Convert <T2>(args[1]), Convert <T3>(args[2])); }; subscription.Data += handler; return(new DisposableAction(() => subscription.Data -= handler)); }
void StartSignalR() { if (_hubConnection == null) { _hubConnection = new HubConnection(signalRUrl); _hubProxy = _hubConnection.CreateProxy("SignalRSampleHub"); _subscription = _hubProxy.Subscribe("broadcastMessage"); _subscription.Data += data => { Debug.Log("signalR called us back"); }; _hubConnection.Start(); } else Debug.Log("Signalr already connected..."); }
private void Form1_Load(object sender, EventArgs e) { SetStatus("Connecting"); connection = new HubConnection("http://localhost:8080/chatserver", false); myHub = connection.CreateHubProxy("ChatHub"); frmLogin login = new frmLogin(myHub); login.ShowDialog(); connection.Start().ContinueWith(task => { if (task.IsFaulted == false) { if (connection.State == Microsoft.AspNet.SignalR.Client.ConnectionState.Connected) { SetStatus("Connected"); myHub.Invoke("Join", login.Username).ContinueWith(task_join => { if (task_join.IsFaulted) { MessageBox.Show("Error during joining the server!"); } else { Subscription sub = myHub.Subscribe("addMessage"); sub.Data += args => { Message(args[0].ToString()); }; UpdateUsers(); timer1.Enabled = true; } }); } } }); }
public async static void Connect() { var connection = new HubConnection("http://pbclone.azurewebsites.net/"); //var connection = new HubConnection("http://localhost:4341/"); _mainHub = connection.CreateHubProxy("imghub"); await connection.Start().ContinueWith(_ => { _mainHub.Invoke("Create", "test"); //_mainHub.Invoke("SendMsg", "test ok"); //_mainHub.Subscribe("receiveMsg").Data += tokens => Console.WriteLine(tokens[0]); _mainHub.Subscribe("ReceiveImage").Data += tokens => { byte[] convertedFromBase64 = Convert.FromBase64String(tokens[0].ToString()); Console.WriteLine (convertedFromBase64.Length); }; _mainHub.Invoke("ShareImage", new object[] { new byte[] { 1, 2 }, "test" }); }); }
protected override void SubscribeToMessages(IHubProxy proxy) { proxy.Subscribe("RoomEntered").Data += RoomChange; proxy.Subscribe("RoomExited").Data += RoomChange; proxy.Subscribe("OnPlayerTrapped").Data += (object[] args) => { CaughtMessages.Enqueue(new HeistCaughtMessage() { Tag = IncomingMessageType.OpponentTrapped, PlayerId = args[0] as string, OpponentId = args[1] as string }); }; proxy.Subscribe("OpponentCaught").Data += (object[] args) => { CaughtMessages.Enqueue(new HeistCaughtMessage() { Tag = IncomingMessageType.OpponentCaught, PlayerId = args[0] as string, OpponentId = args[1] as string, }); }; proxy.Subscribe("NeedUpdate").Data += (object[] args) => { NeedsUpdate(); }; proxy.Subscribe("GameFinished").Data += (object[] args) => { UnityEngine.Debug.Log("GAME FINISHED!"); CaughtMessages.Enqueue(new HeistCaughtMessage() { Tag = IncomingMessageType.OpponentCaught, PlayerId = args[0] as string }); }; proxy.Subscribe("GameReady").Data += (object[] args) => { UnityEngine.Debug.Log("EVERYONE JOINED!"); CaughtMessages.Enqueue(new HeistCaughtMessage() { Tag = IncomingMessageType.GameReady, StartTime = ((DateTime)args[0]) }); }; }
public override void SetupHandlers(IHubProxy proxy) { proxy.Subscribe("send").Received += EchoUser_Received; }
async private void makeConnection() { try { // Pass parameter form client to server. var querystringData = new Dictionary<string, string>(); querystringData.Add("chatversion", "1.1"); var hubConnection = new HubConnection("http://localhost:53748",querystringData); // Windows authentication. hubConnection.Credentials = CredentialCache.DefaultCredentials; // Connection Header. // hubConnection.Headers.Add("myauthtoken", /* token data */); //// Auth(Certificate). //hubConnection.AddClientCertificate(X509Certificate.CreateFromCertFile("MyCert.cer")); chat = hubConnection.CreateHubProxy("ChatHub"); chatShow.Text = ""; Context = SynchronizationContext.Current; chat.On<string, string>("broadcastMessage", (name, message) => Context.Post(delegate { this.chatShow.Text += name + ": "; this.chatShow.Text += message + "\n"; }, null) ); chat.Subscribe("notifyWrongVersion").Received += notifyWrongVersion_chat; await hubConnection.Start(); await chat.Invoke("Notify", chatName.Text, hubConnection.ConnectionId); } catch (HubException ex) { } catch (Exception ex) { } }