/// <summary> /// Open websocket connection. /// </summary> /// <returns>The async.</returns> /// <param name="secure">If set to <c>true</c> secure.</param> /// <param name="subprotocol">Subprotocol.</param> /// <param name="enforce">If set to <c>true</c> enforce.</param> /// <param name="cancellationToken">Cancellation token.</param> public Task <bool> OpenAsync(bool secure, string subprotocol = null, bool enforce = false, CancellationToken cancellationToken = default(CancellationToken)) { _secure = secure; if (state == Status.Online && !enforce) { AVRealtime.PrintLog("state is Status.Online."); return(Task.FromResult(true)); } if (CurrentConfiguration.RealtimeServer != null) { _wss = CurrentConfiguration.RealtimeServer.ToString(); AVRealtime.PrintLog("use configuration realtime server with url: " + _wss); return(OpenAsync(_wss, subprotocol, enforce)); } var routerUrl = CurrentConfiguration.RTMRouter != null?CurrentConfiguration.RTMRouter.ToString() : (AVClient.CurrentConfiguration.PushServer != null ? AVClient.CurrentConfiguration.PushServer.ToString() : null); return(RouterController.GetAsync(routerUrl, secure, cancellationToken).OnSuccess(r => { var routerState = r.Result; if (routerState == null) { return Task.FromResult(false); } _wss = routerState.server; _secondaryWss = routerState.secondary; state = Status.Connecting; AVRealtime.PrintLog("push router give a url :" + _wss); return OpenAsync(routerState.server, subprotocol, enforce); }).Unwrap()); }
/// <summary> /// Opens WebSocket connection with LeanCloud Push server. /// </summary> /// <returns>The async.</returns> /// <param name="cancellationToken">Cancellation token.</param> public Task OpenAsync(CancellationToken cancellationToken = default(CancellationToken)) { if (state == Status.Online) { return(Task.FromResult(true)); } return(RouterController.GetAsync(cancellationToken).OnSuccess(_ => { _wss = _.Result.server; state = Status.Connecting; return OpenAsync(_.Result.server, cancellationToken); }).Unwrap()); }
/// <summary> /// fetch wss address from push router and open the websocket connection. /// </summary> /// <param name="secure">if use ssl encrept</param> /// <param name="subprotocol">subprotocol</param> /// <param name="cancellationToken"></param> /// <returns></returns> public Task OpenAsync(bool secure = true, string subprotocol = null, CancellationToken cancellationToken = default(CancellationToken)) { if (state == Status.Online) { AVRealtime.PrintLog("state is Status.Online."); return(Task.FromResult(true)); } if (CurrentConfiguration.RealtimeServer != null) { AVRealtime.PrintLog("use configuration websocket url:" + _wss); return(OpenAsync(CurrentConfiguration.RealtimeServer.ToString(), subprotocol, cancellationToken)); } return(RouterController.GetAsync(CurrentConfiguration.PushRouterServer.ToString(), secure, cancellationToken).OnSuccess(_ => { _wss = _.Result.server; state = Status.Connecting; AVRealtime.PrintLog("push router give a url :" + _wss); return OpenAsync(_.Result.server, subprotocol, cancellationToken); }).Unwrap()); }