protected void ProcessHandshake(IMutableMessage handshake) { if (handshake.Successful) { handshake.TryGetValue(MessageFields.SupportedConnectionTypesField, out var serverTransportObject); var serverTransports = JsonConvert.DeserializeObject <IList <object> >(serverTransportObject.ToString()); var negotiatedTransports = _transportRegistry.Negotiate(serverTransports, BayeuxVersion); var newTransport = negotiatedTransports.Count == 0 ? null : negotiatedTransports[0]; if (newTransport == null) { UpdateBayeuxClientState( oldState => new DisconnectedState(this, oldState.Transport), delegate { Receive(handshake); }); // Signal the failure var error = "405:c" + _transportRegistry.AllowedTransports + ",s" + serverTransports + ":no transport"; handshake.Successful = false; handshake[MessageFields.ErrorField] = error; } else { UpdateBayeuxClientState( delegate(BayeuxClientState oldState) { if (newTransport != oldState.Transport) { oldState.Transport.Reset(); newTransport.Init(); } var action = GetAdviceAction(handshake.Advice, MessageFields.ReconnectRetryValue); if (MessageFields.ReconnectRetryValue.Equals(action)) { return(new ConnectingState(this, oldState.HandshakeFields, handshake.Advice, newTransport, handshake.ClientId)); } if (MessageFields.ReconnectNoneValue.Equals(action)) { return(new DisconnectedState(this, oldState.Transport)); } return(null); }, delegate { Receive(handshake); }); } } else { UpdateBayeuxClientState( delegate(BayeuxClientState oldState) { var action = GetAdviceAction(handshake.Advice, MessageFields.ReconnectHandshakeValue); if (MessageFields.ReconnectHandshakeValue.Equals(action) || MessageFields.ReconnectRetryValue.Equals(action)) { return(new RehandshakingState(this, oldState.HandshakeFields, oldState.Transport, oldState.NextBackoff())); } if (MessageFields.ReconnectNoneValue.Equals(action)) { return(new DisconnectedState(this, oldState.Transport)); } return(null); }, delegate { Receive(handshake); }); } }
protected void processHandshake(IMutableMessage handshake) { LogHelper.Log($"BayeauxClient: processHandshake() successful? {handshake.Successful}"); if (handshake.Successful) { // @@ax: I think this should be able to return a list of objects? Object serverTransportObject; handshake.TryGetValue(Message_Fields.SUPPORTED_CONNECTION_TYPES_FIELD, out serverTransportObject); IList <Object> serverTransports = serverTransportObject as IList <Object>; //Console.WriteLine("Supported transport: {0}", serverTransport); //IList<Object> serverTransports = new List<Object>(); //serverTransports.Add(serverTransport); IList <ClientTransport> negotiatedTransports = transportRegistry.Negotiate(serverTransports, BAYEUX_VERSION); ClientTransport newTransport = negotiatedTransports.Count == 0 ? null : negotiatedTransports[0]; if (newTransport == null) { updateBayeuxClientState( delegate(BayeuxClientState oldState) { return(new DisconnectedState(this, oldState.transport)); }, delegate() { receive(handshake); }); // Signal the failure String error = "405:c" + transportRegistry.AllowedTransports + ",s" + serverTransports.ToString() + ":no transport"; handshake.Successful = false; handshake[Message_Fields.ERROR_FIELD] = error; // TODO: also update the advice with reconnect=none for listeners ? } else { updateBayeuxClientState( delegate(BayeuxClientState oldState) { if (newTransport != oldState.transport) { oldState.transport.reset(); newTransport.init(); } String action = getAdviceAction(handshake.Advice, Message_Fields.RECONNECT_RETRY_VALUE); if (Message_Fields.RECONNECT_RETRY_VALUE.Equals(action)) { return(new ConnectingState(this, oldState.handshakeFields, handshake.Advice, newTransport, handshake.ClientId)); } else if (Message_Fields.RECONNECT_NONE_VALUE.Equals(action)) { return(new DisconnectedState(this, oldState.transport)); } return(null); }, delegate() { receive(handshake); }); } } else { updateBayeuxClientState( delegate(BayeuxClientState oldState) { String action = getAdviceAction(handshake.Advice, Message_Fields.RECONNECT_HANDSHAKE_VALUE); if (Message_Fields.RECONNECT_HANDSHAKE_VALUE.Equals(action) || Message_Fields.RECONNECT_RETRY_VALUE.Equals(action)) { return(new RehandshakingState(this, oldState.handshakeFields, oldState.transport, oldState.nextBackoff())); } else if (Message_Fields.RECONNECT_NONE_VALUE.Equals(action)) { return(new DisconnectedState(this, oldState.transport)); } return(null); }, delegate() { receive(handshake); }); } }