#if !BESTHTTP_DISABLE_SIGNALR_CORE
using System;
using System.Collections.Generic;
namespace BestHTTP.SignalRCore.Messages
{
public sealed class SupportedTransport
{
///
/// Name of the transport.
///
public string Name { get; private set; }
///
/// Supported transfer formats of the transport.
///
public List SupportedFormats { get; private set; }
internal SupportedTransport(string transportName, List transferFormats)
{
this.Name = transportName;
this.SupportedFormats = transferFormats;
}
}
///
/// Negotiation result of the /negotiation request.
///
///
public sealed class NegotiationResult
{
public int NegotiateVersion { get; private set; }
///
/// The connectionToken which is required by the Long Polling and Server-Sent Events transports (in order to correlate sends and receives).
///
public string ConnectionToken { get; private set; }
///
/// The connectionId which is required by the Long Polling and Server-Sent Events transports (in order to correlate sends and receives).
///
public string ConnectionId { get; private set; }
///
/// The availableTransports list which describes the transports the server supports. For each transport, the name of the transport (transport) is listed, as is a list of "transfer formats" supported by the transport (transferFormats)
///
public List SupportedTransports { get; private set; }
///
/// The url which is the URL the client should connect to.
///
public Uri Url { get; private set; }
///
/// The accessToken which is an optional bearer token for accessing the specified url.
///
public string AccessToken { get; private set; }
public HTTPResponse NegotiationResponse { get; internal set; }
internal static NegotiationResult Parse(HTTPResponse resp, out string error, HubConnection hub)
{
error = null;
Dictionary response = BestHTTP.JSON.Json.Decode(resp.DataAsText) as Dictionary;
if (response == null)
{
error = "Json decoding failed!";
return null;
}
try
{
NegotiationResult result = new NegotiationResult();
result.NegotiationResponse = resp;
object value;
if (response.TryGetValue("negotiateVersion", out value))
{
int version;
if (int.TryParse(value.ToString(), out version))
result.NegotiateVersion = version;
}
if (response.TryGetValue("connectionId", out value))
result.ConnectionId = value.ToString();
if (response.TryGetValue("connectionToken", out value))
result.ConnectionToken = value.ToString();
if (response.TryGetValue("availableTransports", out value))
{
List