public override bool OnMessageReceived(ProtocolMessage message) { switch (message.Action) { case ProtocolMessage.MessageAction.Connected: { if (context.Transport.State == TransportState.Connected) { ConnectionInfo info = new ConnectionInfo(message.ConnectionId, message.ConnectionSerial ?? -1, message.ConnectionKey); this.TransitionState(new ConnectionConnectedState(this.context, info)); } return(true); } case ProtocolMessage.MessageAction.Disconnected: { ConnectionState nextState; if (this.ShouldSuspend()) { nextState = new ConnectionSuspendedState(this.context, message.Error); } else { nextState = new ConnectionDisconnectedState(this.context, message.Error) { UseFallbackHost = ShouldUseFallbackHost(message.Error) }; } this.TransitionState(nextState); return(true); } case ProtocolMessage.MessageAction.Error: { if (ShouldUseFallbackHost(message.Error)) { this.context.Connection.Key = null; this.TransitionState(new ConnectionDisconnectedState(this.context) { UseFallbackHost = true }); } this.TransitionState(new ConnectionFailedState(this.context, message.Error)); return(true); } } return(false); }
public override void OnTransportStateChanged(TransportStateInfo state) { if (state.Error != null || state.State == TransportState.Closed) { ConnectionState nextState; if (this.ShouldSuspend()) { nextState = new ConnectionSuspendedState(this.context); } else { nextState = new ConnectionDisconnectedState(this.context, state) { UseFallbackHost = state.Error != null && AblyRealtime.CanConnectToAbly() }; } this.TransitionState(nextState); } }