public TSSdkSession GetCurrentSession() { JObject json = JObject.Parse(RESTHelper.DoWebRequest(BASE_URL + DB + "/" + CURRENT_SESSION_DOC_ID, "GET", string.Empty)); json.Remove("_id"); json.Remove("_rev"); TSSdkSession sessionFromDB = TSSdkSession.FromJson(json.ToString()); return(sessionFromDB); }
/* * /session-create * POST https://{na,eu,ap}-api.teamspeaksdk.com/session-create * * Creates a voice session on the region associated with the api endpoint you are posting to. * * e.g. * Request body: * { * "CustomerLabel": "Raid #208052098", * "MaxUsers": "10", * "SDKVersion": "3.0.4" * } * * Response: * { * "CustomerLabel": "Raid #208052098", * "MaxUsers": 10, * "ApiKey": "******", * "SessionId": "na-64a6a6-e10b38-d8bb48-5be140-92cdf4", * "Password": "******", * "UDPPort": 13808, * "Region": "na", * "Hostname": "144.217.11.226", * "Message": "Created session." * } * * Error Response: * { * "Message": "Bad request - paramater not set." * } * * { * "Message": "Cannot have greater than 10 MaxUsers per voice server on a limited account." * } * * { * "Message": "No Instances available hosting that SDKVersion." * } * * { * "Message": "Failed to create voice session." * } */ private TSSdkSession SessionCreate() { string url = BASE_URL_EU + "/session-create"; string body = "{\"CustomerLabel\":\"" + CustomerLabel + "\",\"MaxUsers\":\"" + MaxUsers.ToString() + "\",\"SDKVersion\":\"" + SDKVersion + "\"}"; string response = RESTHelper.DoWebRequest(url, POST, body); if (response != null) { return(TSSdkSession.FromJson(response)); } return(null); }
private void SetCurrentSesssion() { CouchPortal couchPortal = new CouchPortal(); TSSdkSession sessionFromDB = couchPortal.GetCurrentSession(); if (!SessionIsActive(sessionFromDB)) { CurrentSession = SessionCreate(); couchPortal.UpdateCurrentSession(CurrentSession); } else { CurrentSession = sessionFromDB; } }
public void UpdateCurrentSession(TSSdkSession session) { string json = RESTHelper.DoWebRequest(BASE_URL + DB + "/" + CURRENT_SESSION_DOC_ID, "GET", string.Empty); JDocument doc = new JDocument(json); JDocument newDoc = new JDocument(Serialize.ToJson(session)); newDoc.Id = doc.Id; newDoc.Rev = doc.Rev; System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); Byte[] data = encoding.GetBytes(newDoc.ToString()); using (var client = new System.Net.WebClient()) { client.UseDefaultCredentials = true; client.Credentials = new NetworkCredential("admin", "9d12b2051b87"); client.UploadData(BASE_URL + DB + CURRENT_SESSION_DOC_ID, "PUT", data); } }
public static string ToJson(this TSSdkSession self) => JsonConvert.SerializeObject(self, Converter.Settings);
private bool SessionIsActive(TSSdkSession tSSdkSession) { string sessionList = SessionList(); return(sessionList != null && sessionList.Contains(tSSdkSession.SessionId)); }