public OpenTokService()
        {
            int apiKey = 0;
            string apiSecret = null;
            try
            {
                string apiKeyString = ConfigurationManager.AppSettings["API_KEY"];
                apiSecret = ConfigurationManager.AppSettings["API_SECRET"];
                apiKey = Convert.ToInt32(apiKeyString);
            }

            catch (Exception ex)
            {
                if (!(ex is ConfigurationErrorsException || ex is FormatException || ex is OverflowException))
                {
                    throw ex;
                }
            }

            finally
            {
                if (apiKey == 0 || apiSecret == null)
                {
                    Console.WriteLine(
                        "The OpenTok API Key and API Secret were not set in the application configuration. " +
                        "Set the values in App.config and try again. (apiKey = {0}, apiSecret = {1})", apiKey, apiSecret);
                    Console.ReadLine();
                    Environment.Exit(-1);
                }
            }

            this.OpenTok = new OpenTok(apiKey, apiSecret);

            this.Session = this.OpenTok.CreateSession(mediaMode: MediaMode.ROUTED);
        }
Esempio n. 2
0
        public void CreateP2pSessionTest()
        {
            string sessionId = "SESSIONID";
            string returnString = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><sessions><Session><" +
                                "session_id>" + sessionId + "</session_id><partner_id>123456</partner_id><create_dt>" +
                                "Mon Mar 17 00:41:31 PDT 2014</create_dt></Session></sessions>";
            var expectedUrl = "session/create";

            var mockClient = new Mock<HttpClient>();
            mockClient.Setup(httpClient => httpClient.Post(It.IsAny<string>(), It.IsAny<Dictionary<string, string>>(), It.IsAny<Dictionary<string, object>>())).Returns(returnString);

            HttpClient client = mockClient.Object;

            OpenTok opentok = new OpenTok(apiKey, apiSecret);
            opentok.Client = client;
            Session session = opentok.CreateSession(p2p: true);

            Assert.NotNull(session);
            Assert.Equal(this.apiKey, session.ApiKey);
            Assert.Equal(sessionId, session.Id);
            Assert.True(session.P2p);
            Assert.Equal(session.Location, "");

            mockClient.Verify(httpClient => httpClient.Post(It.Is<string>(url => url.Equals(expectedUrl)), It.IsAny<Dictionary<string, string>>(), It.IsAny<Dictionary<string, object>>()), Times.Once());
        }
Esempio n. 3
0
 protected void Application_Start()
 {
     AreaRegistration.RegisterAllAreas();
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     OpenTok opentok = new OpenTok(Convert.ToInt32(ConfigurationManager.AppSettings["opentok_key"]),
                 ConfigurationManager.AppSettings["opentok_secret"]);
     Application["sessionId"] = opentok.CreateSession().Id;
 }
Esempio n. 4
0
        public void GenerateComplexTokenTest()
        {
            OpenTok opentok = new OpenTok(apiKey, apiSecret);
            Session session = opentok.CreateSession();
            double expireTime = OpenTokUtils.GetCurrentUnixTimeStamp() + 10;

            string token = session.GenerateToken(role: Role.MODERATOR, expireTime: expireTime, data: "Connection data");
            CheckToken(token, apiKey);
        }
Esempio n. 5
0
        public void CreateP2pSessionTest()
        {
            OpenTok opentok = new OpenTok(apiKey, apiSecret);
            Session session = opentok.CreateSession(p2p: true);

            Assert.NotNull(session);
            Assert.Equal(session.ApiKey, apiKey);
            Assert.Equal(session.ApiSecret, apiSecret);
            Assert.Equal(session.P2p, true);
            Assert.Equal(session.Location, "");
            Assert.True(ValidateSession(session.Id));
        }
Esempio n. 6
0
        public void CreateSessionWithLocationTest()
        {
            OpenTok opentok = new OpenTok(apiKey, apiSecret);
            Session session = opentok.CreateSession(location: "0.0.0.0");

            Assert.NotNull(session);
            Assert.Equal(session.ApiKey, apiKey);
            Assert.Equal(session.ApiSecret, apiSecret);
            Assert.Equal(session.P2p, false);
            Assert.Equal(session.Location, "0.0.0.0");
            Assert.True(ValidateSession(session.Id));
        }
Esempio n. 7
0
 public void CreateLocationSessionTest()
 {
     OpenTok opentok = new OpenTok(apiKey, apiSecret);
     Session session;
     try
     {
         session = opentok.CreateSession(location: "A location");
         Assert.True(false);
     }
     catch(OpenTokArgumentException)
     {
         Assert.True(true);
     }
 }
Esempio n. 8
0
        public void CreateInvalidSessionLocationTest()
        {
            var mockClient = new Mock<HttpClient>();
            mockClient.Setup(httpClient => httpClient.Post(It.IsAny<string>(), It.IsAny<Dictionary<string, string>>(), It.IsAny<Dictionary<string, object>>())).Returns("This function should not return anything");

            OpenTok opentok = new OpenTok(apiKey, apiSecret);
            Session session;
            try
            {
                session = opentok.CreateSession(location: "A location");
                Assert.True(false);
            }
            catch (OpenTokArgumentException)
            {
                Assert.True(true);
            }
        }
Esempio n. 9
0
        public ActionResult Index()
        {
            var OpenTok = new OpenTok(ApiKey, ApiSecret);

            //// Create a session that will attempt to transmit streams directly between clients
            //var session = OpenTok.CreateSession();
            //// Store this sessionId in the database for later use:
            //string sessionId = session.Id;

            // Create a session that uses the OpenTok Media Router (which is required for archiving)
            var session =  OpenTok.CreateSession(mediaMode: MediaMode.ROUTED);
            // Store this sessionId in the database for later use:
               // string sessionId = session.Id;

            //// Create an automatically archived session:
            //var session = OpenTok.CreateSession(mediaMode: MediaMode.ROUTED, ArchiveMode.ALWAYS);
            // Store this sessionId in the database for later use:
            ViewBag.sessionId = session.Id;
            return View();
        }
Esempio n. 10
0
        public void GetArchiveTest()
        {
            string archiveId = "936da01f-9abd-4d9d-80c7-02af85c822a8";
            string returnString = "{\n" +
                                    " \"createdAt\" : 1395187836000,\n" +
                                    " \"duration\" : 62,\n" +
                                    " \"id\" : \"" + archiveId + "\",\n" +
                                    " \"name\" : \"\",\n" +
                                    " \"partnerId\" : 123456,\n" +
                                    " \"reason\" : \"\",\n" +
                                    " \"sessionId\" : \"SESSIONID\",\n" +
                                    " \"size\" : 8347554,\n" +
                                    " \"status\" : \"available\",\n" +
                                    " \"url\" : \"http://tokbox.com.archive2.s3.amazonaws.com/123456%2F" +
                                    archiveId + "%2Farchive.mp4?Expires=1395194362&AWSAccessKeyId=AKIAI6LQCPIXYVWCQV6Q&Si" +
                                    "gnature=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"\n" + " }";
            var mockClient = new Mock<HttpClient>();
            mockClient.Setup(httpClient => httpClient.Get(It.IsAny<string>())).Returns(returnString);

            OpenTok opentok = new OpenTok(apiKey, apiSecret);
            opentok.Client = mockClient.Object;
            Archive archive = opentok.GetArchive(archiveId);

            Assert.NotNull(archive);
            Assert.Equal(this.apiKey, archive.PartnerId);
            Assert.Equal(archiveId, archive.Id.ToString());
            Assert.Equal(1395187836000L, archive.CreatedAt);
            Assert.Equal(62, archive.Duration);
            Assert.Equal("", archive.Name);
            Assert.Equal("SESSIONID", archive.SessionId);
            Assert.Equal(8347554, archive.Size);
            Assert.Equal(ArchiveState.AVAILABLE, archive.Status);
            Assert.Equal("http://tokbox.com.archive2.s3.amazonaws.com/123456%2F" + archiveId + "%2Farchive.mp4?Expires=13951" +
                    "94362&AWSAccessKeyId=AKIAI6LQCPIXYVWCQV6Q&Signature=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", archive.Url);

            mockClient.Verify(httpClient => httpClient.Get(It.Is<string>(url => url.Equals("v2/partner/"+this.apiKey+"/archive/"+archiveId))), Times.Once());
        }
Esempio n. 11
0
 public void OpenTokTest()
 {
     OpenTok opentok = new OpenTok(apiKey, apiSecret);
     Assert.Equal(opentok.ApiKey, apiKey);
     Assert.Equal(opentok.ApiSecret, apiSecret);
 }
Esempio n. 12
0
 public void GenerateTokenWithInvalidExpiryTimeTest()
 {
     OpenTok opentok = new OpenTok(apiKey, apiSecret);
     Session session = opentok.CreateSession();
     double expireTime = OpenTokUtils.GetCurrentUnixTimeStamp() - 1;
     string token;
     try
     {
         token = session.GenerateToken(role: Role.MODERATOR, expireTime: expireTime, data: "Connection data");
         Assert.False(true);
     }
     catch(OpenTokArgumentException)
     {
         Assert.True(true);
     }
 }
Esempio n. 13
0
        public void GenerateTokenWithExpireTimeTest()
        {
            OpenTok opentok = new OpenTok(apiKey, apiSecret);
            Session session = opentok.CreateSession(p2p: true);
            double expireTime = OpenTokUtils.GetCurrentUnixTimeStamp() + 10;

            string token = session.GenerateToken(expireTime: expireTime);
            CheckToken(token, apiKey);
        }
Esempio n. 14
0
        public void GenerateTokenWithDataTest()
        {
            OpenTok opentok = new OpenTok(apiKey, apiSecret);
            Session session = opentok.CreateSession(p2p: true);
            string token = session.GenerateToken(data: "This is some data");

            CheckToken(token, apiKey);
        }
Esempio n. 15
0
        public void GenerateTokenTest()
        {
            OpenTok opentok = new OpenTok(apiKey, apiSecret);
            Session session = opentok.CreateSession(p2p: true);
            string token = session.GenerateToken();

            CheckToken(token, apiKey);
        }
Esempio n. 16
0
        public void GetArchiveWithUnknownPropertiesTest()
        {
            string archiveId = "936da01f-9abd-4d9d-80c7-02af85c822a8";
            string returnString = "{\n" +
                                    " \"createdAt\" : 1395187836000,\n" +
                                    " \"duration\" : 62,\n" +
                                    " \"id\" : \"" + archiveId + "\",\n" +
                                    " \"name\" : \"\",\n" +
                                    " \"partnerId\" : 123456,\n" +
                                    " \"reason\" : \"\",\n" +
                                    " \"sessionId\" : \"SESSIONID\",\n" +
                                    " \"size\" : 8347554,\n" +
                                    " \"status\" : \"expired\",\n" +
                                    " \"notarealproperty\" : \"not a real value\",\n" +
                                    " \"url\" : null\n" + " }";
            var mockClient = new Mock<HttpClient>();
            mockClient.Setup(httpClient => httpClient.Get(It.IsAny<string>())).Returns(returnString);

            OpenTok opentok = new OpenTok(apiKey, apiSecret);
            opentok.Client = mockClient.Object;
            Archive archive = opentok.GetArchive(archiveId);

            Assert.NotNull(archive);

            mockClient.Verify(httpClient => httpClient.Get(It.Is<string>(url => url.Equals("v2/partner/" + this.apiKey + "/archive/" + archiveId))), Times.Once());
        }
Esempio n. 17
0
 internal Archive(OpenTok opentok)
 {
     this.opentok = opentok;
 }
Esempio n. 18
0
 internal Broadcast(OpenTok opentok)
 {
     this.opentok = opentok;
 }
Esempio n. 19
0
        public void GenerateTokenWithRoleTest()
        {
            OpenTok opentok = new OpenTok(apiKey, apiSecret);

            String sessionId = "1_MX4xMjM0NTZ-flNhdCBNYXIgMTUgMTQ6NDI6MjMgUERUIDIwMTR-MC40OTAxMzAyNX4";
            string token = opentok.GenerateToken(sessionId, role:Role.SUBSCRIBER);

            Assert.NotNull(token);
            var data = CheckToken(token, apiKey);

            Assert.Equal(data["partner_id"], apiKey.ToString());
            Assert.NotNull(data["sig"]);
            Assert.NotNull(data["create_time"]);
            Assert.NotNull(data["nonce"]);
            Assert.Equal(data["role"], Role.SUBSCRIBER.ToString());
        }
Esempio n. 20
0
        public void GenerateTokenWithExpireTimeTest()
        {
            OpenTok opentok = new OpenTok(apiKey, apiSecret);
            double expireTime = OpenTokUtils.GetCurrentUnixTimeStamp() + 10;

            String sessionId = "1_MX4xMjM0NTZ-flNhdCBNYXIgMTUgMTQ6NDI6MjMgUERUIDIwMTR-MC40OTAxMzAyNX4";
            string token = opentok.GenerateToken(sessionId, expireTime: expireTime);

            Assert.NotNull(token);
            var data = CheckToken(token, apiKey);

            Assert.Equal(data["partner_id"], apiKey.ToString());
            Assert.NotNull(data["sig"]);
            Assert.NotNull(data["create_time"]);
            Assert.NotNull(data["nonce"]);
            Assert.Equal(data["role"], Role.PUBLISHER.ToString());
            Assert.Equal(data["expire_time"], ((long) expireTime).ToString());
        }
Esempio n. 21
0
        public void GenerateInvalidTokensTest()
        {
            string token;
            OpenTok opentok = new OpenTok(apiKey, apiSecret);
            var exceptions = new List<Exception>();
            try
            {
                // Generate token with empty sessionId
                token = opentok.GenerateToken(null);
            }
            catch(OpenTokArgumentException e)
            {
                exceptions.Add(e);
            }

            try
            {
                // Generate token with empty sessionId
                token = opentok.GenerateToken("");
            }
            catch (OpenTokArgumentException e)
            {
                exceptions.Add(e);
            }

            try
            {
                // Generate token with empty sessionId
                token = opentok.GenerateToken("NOT A VALID SESSION ID");
            }
            catch (OpenTokArgumentException e)
            {
                exceptions.Add(e);
            }

            Assert.Equal(exceptions.Count, 3);
            foreach(Exception exception in exceptions)
            {
                Assert.True(exception is OpenTokArgumentException);
            }
        }
Esempio n. 22
0
        public void DeleteArchiveTest()
        {
            string archiveId = "30b3ebf1-ba36-4f5b-8def-6f70d9986fe9";

            var mockClient = new Mock<HttpClient>();
            mockClient.Setup(httpClient => httpClient.Delete(It.IsAny<string>(),
                It.IsAny<Dictionary<string, string>>(),
                It.IsAny<Dictionary<string, object>>()));

            OpenTok opentok = new OpenTok(apiKey, apiSecret);
            opentok.Client = mockClient.Object;
            opentok.DeleteArchive(archiveId);

            mockClient.Verify(httpClient => httpClient.Delete(It.Is<string>(
                url => url.Equals("v2/partner/" + apiKey + "/archive/" + archiveId)),
                It.IsAny<Dictionary<string, string>>(),
                It.IsAny<Dictionary<string, object>>()), Times.Once());
        }
Esempio n. 23
0
        public void ListArchivesTest()
        {
            string returnString = "{\n" +
                                " \"count\" : 6,\n" +
                                " \"items\" : [ {\n" +
                                " \"createdAt\" : 1395187930000,\n" +
                                " \"duration\" : 22,\n" +
                                " \"id\" : \"ef546c5a-4fd7-4e59-ab3d-f1cfb4148d1d\",\n" +
                                " \"name\" : \"\",\n" +
                                " \"partnerId\" : 123456,\n" +
                                " \"reason\" : \"\",\n" +
                                " \"sessionId\" : \"SESSIONID\",\n" +
                                " \"size\" : 2909274,\n" +
                                " \"status\" : \"available\",\n" +
                                " \"url\" : \"http://tokbox.com.archive2.s3.amazonaws.com/123456%2Fef546c5" +
                                "a-4fd7-4e59-ab3d-f1cfb4148d1d%2Farchive.mp4?Expires=1395188695&AWSAccessKeyId=AKIAI6" +
                                "LQCPIXYVWCQV6Q&Signature=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"\n" +
                                " }, {\n" +
                                " \"createdAt\" : 1395187910000,\n" +
                                " \"duration\" : 14,\n" +
                                " \"id\" : \"5350f06f-0166-402e-bc27-09ba54948512\",\n" +
                                " \"name\" : \"\",\n" +
                                " \"partnerId\" : 123456,\n" +
                                " \"reason\" : \"\",\n" +
                                " \"sessionId\" : \"SESSIONID\",\n" +
                                " \"size\" : 1952651,\n" +
                                " \"status\" : \"available\",\n" +
                                " \"url\" : \"http://tokbox.com.archive2.s3.amazonaws.com/123456%2F5350f06" +
                                "f-0166-402e-bc27-09ba54948512%2Farchive.mp4?Expires=1395188695&AWSAccessKeyId=AKIAI6" +
                                "LQCPIXYVWCQV6Q&Signature=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"\n" +
                                " }, {\n" +
                                " \"createdAt\" : 1395187836000,\n" +
                                " \"duration\" : 62,\n" +
                                " \"id\" : \"f6e7ee58-d6cf-4a59-896b-6d56b158ec71\",\n" +
                                " \"name\" : \"\",\n" +
                                " \"partnerId\" : 123456,\n" +
                                " \"reason\" : \"\",\n" +
                                " \"sessionId\" : \"SESSIONID\",\n" +
                                " \"size\" : 8347554,\n" +
                                " \"status\" : \"available\",\n" +
                                " \"url\" : \"http://tokbox.com.archive2.s3.amazonaws.com/123456%2Ff6e7ee5" +
                                "8-d6cf-4a59-896b-6d56b158ec71%2Farchive.mp4?Expires=1395188695&AWSAccessKeyId=AKIAI6" +
                                "LQCPIXYVWCQV6Q&Signature=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"\n" +
                                " }, {\n" +
                                " \"createdAt\" : 1395183243000,\n" +
                                " \"duration\" : 544,\n" +
                                " \"id\" : \"30b3ebf1-ba36-4f5b-8def-6f70d9986fe9\",\n" +
                                " \"name\" : \"\",\n" +
                                " \"partnerId\" : 123456,\n" +
                                " \"reason\" : \"\",\n" +
                                " \"sessionId\" : \"SESSIONID\",\n" +
                                " \"size\" : 78499758,\n" +
                                " \"status\" : \"available\",\n" +
                                " \"url\" : \"http://tokbox.com.archive2.s3.amazonaws.com/123456%2F30b3ebf" +
                                "1-ba36-4f5b-8def-6f70d9986fe9%2Farchive.mp4?Expires=1395188695&AWSAccessKeyId=AKIAI6" +
                                "LQCPIXYVWCQV6Q&Signature=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"\n" +
                                " }, {\n" +
                                " \"createdAt\" : 1394396753000,\n" +
                                " \"duration\" : 24,\n" +
                                " \"id\" : \"b8f64de1-e218-4091-9544-4cbf369fc238\",\n" +
                                " \"name\" : \"showtime again\",\n" +
                                " \"partnerId\" : 123456,\n" +
                                " \"reason\" : \"\",\n" +
                                " \"sessionId\" : \"SESSIONID\",\n" +
                                " \"size\" : 2227849,\n" +
                                " \"status\" : \"available\",\n" +
                                " \"url\" : \"http://tokbox.com.archive2.s3.amazonaws.com/123456%2Fb8f64de" +
                                "1-e218-4091-9544-4cbf369fc238%2Farchive.mp4?Expires=1395188695&AWSAccessKeyId=AKIAI6" +
                                "LQCPIXYVWCQV6Q&Signature=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"\n" +
                                " }, {\n" +
                                " \"createdAt\" : 1394321113000,\n" +
                                " \"duration\" : 1294,\n" +
                                " \"id\" : \"832641bf-5dbf-41a1-ad94-fea213e59a92\",\n" +
                                " \"name\" : \"showtime\",\n" +
                                " \"partnerId\" : 123456,\n" +
                                " \"reason\" : \"\",\n" +
                                " \"sessionId\" : \"SESSIONID\",\n" +
                                " \"size\" : 42165242,\n" +
                                " \"status\" : \"available\",\n" +
                                " \"url\" : \"http://tokbox.com.archive2.s3.amazonaws.com/123456%2F832641b" +
                                "f-5dbf-41a1-ad94-fea213e59a92%2Farchive.mp4?Expires=1395188695&AWSAccessKeyId=AKIAI6" +
                                "LQCPIXYVWCQV6Q&Signature=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"\n" +
                                " } ]\n" +
                                " }";
            var mockClient = new Mock<HttpClient>();
            mockClient.Setup(httpClient => httpClient.Get(It.IsAny<string>())).Returns(returnString);

            OpenTok opentok = new OpenTok(apiKey, apiSecret);
            opentok.Client = mockClient.Object;
            ArchiveList archives = opentok.ListArchives();

            Assert.NotNull(archives);
            Assert.Equal(6, archives.Count);

            mockClient.Verify(httpClient => httpClient.Get(It.Is<string>(url => url.Equals("v2/partner/"+apiKey + "/archive?offset=0"))), Times.Once());
        }
Esempio n. 24
0
        public void CreateInvalidAlwaysArchivedReplayedSessionTest()
        {
            var mockClient = new Mock<HttpClient>();
            mockClient.Setup(httpClient => httpClient.Post(It.IsAny<string>(), It.IsAny<Dictionary<string, string>>(), It.IsAny<Dictionary<string, object>>())).Returns("This function should not return anything");

            OpenTok opentok = new OpenTok(apiKey, apiSecret);
            Session session;
            try
            {
                session = opentok.CreateSession(mediaMode: MediaMode.RELAYED, archiveMode: ArchiveMode.ALWAYS);
                Assert.True(false);
            }
            catch (OpenTokArgumentException)
            {
                Assert.True(true);
            }
        }
Esempio n. 25
0
        public void GenerateSubscriberTokenTest()
        {
            OpenTok opentok = new OpenTok(apiKey, apiSecret);
            Session session = opentok.CreateSession(p2p: true);
            string token = session.GenerateToken(role: Role.SUBSCRIBER);

            CheckToken(token, apiKey);
        }
Esempio n. 26
0
        public void StopArchiveTest()
        {
            string archiveId = "30b3ebf1-ba36-4f5b-8def-6f70d9986fe9";
            string returnString = "{\n" +
                                " \"createdAt\" : 1395183243556,\n" +
                                " \"duration\" : 0,\n" +
                                " \"id\" : \"30b3ebf1-ba36-4f5b-8def-6f70d9986fe9\",\n" +
                                " \"name\" : \"\",\n" +
                                " \"partnerId\" : 123456,\n" +
                                " \"reason\" : \"\",\n" +
                                " \"sessionId\" : \"SESSIONID\",\n" +
                                " \"size\" : 0,\n" +
                                " \"status\" : \"started\",\n" +
                                " \"url\" : null\n" +
                                " }";
            var mockClient = new Mock<HttpClient>();
            mockClient.Setup(httpClient => httpClient.Post(It.IsAny<string>(),
                It.IsAny<Dictionary<string, string>>(),
                It.IsAny<Dictionary<string, object>>())).Returns(returnString);

            OpenTok opentok = new OpenTok(apiKey, apiSecret);
            opentok.Client = mockClient.Object;
            Archive archive = opentok.StopArchive(archiveId);

            Assert.NotNull(archive);
            Assert.Equal("SESSIONID", archive.SessionId);
            Assert.Equal(archiveId, archive.Id.ToString());

            mockClient.Verify(httpClient => httpClient.Post(It.Is<string>(
                url => url.Equals("v2/partner/" + apiKey + "/archive/" + archiveId +"/stop")),
                It.IsAny<Dictionary<string, string>>(),
                It.IsAny<Dictionary<string, object>>()), Times.Once());
        }
Esempio n. 27
0
 internal Archive(OpenTok opentok)
 {
     this.opentok = opentok;
 }
Esempio n. 28
0
 public void InitializationTest()
 {
     var opentok = new OpenTok(apiKey, apiSecret);
     Assert.IsType(typeof(OpenTok), opentok);
 }