Exemple #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);
        }
Exemple #2
0
        /*
         * /confirm-key
         * POST https://{na,eu,ap}-api.teamspeaksdk.com/confirm-key
         *
         * Allows the developer to ping the api to see if the api key is valid with the expected permissions.
         *
         * e.g.
         * Request body:
         * {
         * }
         *
         * Response:
         * {
         *  "Message": "Access is granted with no limitations.",
         *  "Limitaions": "UNLIMITED"
         * }
         *
         * {
         *  "Message": "Access is granted with FastPass limitations.",
         *  "Limitaions": "LIMITED"
         * }
         */
        public bool ConfirmKey()
        {
            string url  = BASE_URL_EU + "/confirm-key";
            string body = String.Empty;

            string response = RESTHelper.DoWebRequest(url, POST, body);

            if (response != null)
            {
                return(true);
            }

            return(false);
        }
Exemple #3
0
        /*
         * /session-list
         * 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:
         * {
         * }
         *
         * Response:
         * [
         *  {
         *      "SessionId": "na-406cae-d1017a-5d7076-7f83ec-134050",
         *      "Region": "na",
         *      "Password": "******",
         *      "Hostname": "144.217.11.226",
         *      "UDPPort": "13195",
         *      "DateCreated": "1524077298",
         *      "CustomerLabel": "demo session",
         *      "MaxUsers": "2",
         *      "ApiKey": "04abfe-fb3e09-d915e5-ad09f3-d0388",
         *      "VirtualServerClientsOnline": 0,
         *      "VirtualServerCreatedTimestamp": 1524077298,
         *      "VirtualServerMaxUsers": 2,
         *  },
         *  {
         *      "SessionId": "na-865ba9-9bb14a-a8ffc2-20d008-e0cf84",
         *      "Region": "na",
         *      "Password": "******",
         *      "Hostname": "144.217.11.226",
         *      "UDPPort": "14776",
         *      "DateCreated": "1524537320",
         *      "CustomerLabel": "demo session 2",
         *      "MaxUsers": "6",
         *      "ApiKey": "04abfe-fb3e09-d915e5-ad09f3-d0388",
         *      "VirtualServerClientsOnline": 0,
         *      "VirtualServerCreatedTimestamp": 1524537320,
         *      "VirtualServerMaxUsers": 6,
         *  }
         * ]
         *
         * Error Response:
         * {
         *  "Message": "Failed to retrieve voice sessions."
         * }
         */
        public string SessionList()
        {
            string url  = BASE_URL_EU + "/session-list";
            string body = String.Empty;

            string response = RESTHelper.DoWebRequest(url, POST, body);

            if (response != null)
            {
                return(response.ToString());
            }

            return(null);
        }
Exemple #4
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);
        }
Exemple #5
0
        /*
         * /session-destroy
         * POST https://{na,eu,ap}-api.teamspeaksdk.com/session-destroy
         *
         * Destroy's a voice session on the region associated with the api endpoint you are posting to.
         * For example, we need to post to the https://na-api.teamspeaksdk.com/session-destroy endpoint because this session starts with "na".
         *
         * e.g.
         * Request body:
         * {
         *  "SessionId": "na-64a6a6-e10b38-d8bb48-5be140-92cdf4"
         * }
         *
         * Response:
         * {
         *  "Message": "Session destroyed."
         * }
         */
        public bool SessionDestroy()
        {
            if (CurrentSession != null)
            {
                string url  = BASE_URL_EU + "/session-destroy";
                string body = "{\"SessionId\":\"" + CurrentSession.SessionId + "\"}";

                string response = RESTHelper.DoWebRequest(url, POST, body);

                if (response != null)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #6
0
        /*
         * /session-info
         * POST https://{na,eu,ap}-api.teamspeaksdk.com/session-info
         *
         * Gets the information for a voice session on the region associated with the api endpoint you are posting to.
         * For example, we need to post to the https://na-api.teamspeaksdk.com/session-info endpoint because this session starts with "na".
         *
         * e.g.
         * Request body:
         * {
         *  "SessionId": "na-406cae-d1017a-5d7076-7f83ec-134050"
         * }
         *
         * Response:
         * {
         *  "SessionId": "na-406cae-d1017a-5d7076-7f83ec-134050",
         *  "Region": "na",
         *  "Password": "******",
         *  "Hostname": "144.217.11.226",
         *  "UDPPort": "13195",
         *  "CustomerLabel": "demo session",
         *  "MaxUsers": "2",
         *  "VirtualServerClientsOnline": 0,
         *  "VirtualServerCreatedTimestamp": 1524077298,
         *  "VirtualServerMaxUsers": 2,
         * }
         */
        public TsSdkSessionInfo SessionInfo()
        {
            if (CurrentSession != null)
            {
                string url  = BASE_URL_EU + "/session-info";
                string body = "{\"SessionId\":\"" + CurrentSession.SessionId + "\"}";

                string response = RESTHelper.DoWebRequest(url, POST, body);

                if (response != null)
                {
                    return(TsSdkSessionInfo.FromJson(response));
                }
            }
            return(null);
        }
Exemple #7
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);
            }
        }