forked from ringcentral/RingCentral.Net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefinitions.cs
121 lines (101 loc) · 2.83 KB
/
Definitions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
namespace RingCentral.Net.WebSocket
{
public class WebSocketOptions
{
public static readonly WebSocketOptions DefaultInstance = new WebSocketOptions();
public bool autoRecover = true;
/// <summary>
/// Will print logs for debugging purpose
/// </summary>
public bool debugMode = false;
}
public class WsToken
{
public int expires_in;
public string uri;
public string ws_access_token;
}
public class Wsc
{
public int sequence;
public string token;
}
public enum MessageType
{
ClientRequest,
ServerNotification,
Error,
ConnectionDetails,
Heartbeat
}
public class WsgMeta
{
public Dictionary<string, string> headers;
public string messageId;
public int status;
[JsonConverter(typeof(StringEnumConverter))]
public MessageType type;
public Wsc wsc;
}
public class WsgMessage
{
public dynamic body;
public WsgMeta meta;
public static WsgMessage Parse(string message)
{
if (message.Contains(",--Boundary"))
{
var index = message.IndexOf(",--Boundary", StringComparison.Ordinal);
return new WsgMessage
{
meta = JsonConvert.DeserializeObject<WsgMeta>(message.Substring(1, index)),
body = message.Substring(index + 1, message.Length - 1)
};
}
var parsed = JsonConvert.DeserializeObject<dynamic>(message) as JArray;
return new WsgMessage
{
meta = parsed[0].ToObject<WsgMeta>(),
body = parsed.Count > 1 ? parsed[1] : null
};
}
}
public enum RecoveryState
{
Successful,
Failed
}
public class ConnectionDetails
{
public int absoluteTimeout;
public string creationTime;
public int idleTimeout;
public int maxConnectionsPerSession;
public int recoveryBufferSize;
public string recoveryErrorCode;
[JsonConverter(typeof(StringEnumConverter))]
public RecoveryState recoveryState;
public int recoveryTimeout;
}
public class SubscriptionRequestBody
{
public SubscriptionRequestBodyDeliveryMode deliveryMode;
public string[] eventFilters;
}
public class SubscriptionRequestBodyDeliveryMode
{
public string transportType;
}
public class RestRequestHeaders
{
public string messageId;
public string method;
public string path;
public string type;
}
}