コード例 #1
0
        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);
        }
コード例 #2
0
        /*
         * /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);
        }
コード例 #3
0
        private void SetCurrentSesssion()
        {
            CouchPortal  couchPortal   = new CouchPortal();
            TSSdkSession sessionFromDB = couchPortal.GetCurrentSession();

            if (!SessionIsActive(sessionFromDB))
            {
                CurrentSession = SessionCreate();
                couchPortal.UpdateCurrentSession(CurrentSession);
            }
            else
            {
                CurrentSession = sessionFromDB;
            }
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
 public static string ToJson(this TSSdkSession self) => JsonConvert.SerializeObject(self, Converter.Settings);
コード例 #6
0
        private bool SessionIsActive(TSSdkSession tSSdkSession)
        {
            string sessionList = SessionList();

            return(sessionList != null && sessionList.Contains(tSSdkSession.SessionId));
        }