Beispiel #1
0
        public JsonResult CreateSessionIDAndToken(string therapistId)
        {
            try
            {
                int    ApiKey    = ConfigVars.NewInstance.OpenTokAPIKey;       //46201082
                string ApiSecret = ConfigVars.NewInstance.OpenTokAPISecretKey; // "fbef52398143449c9b269e1357d797c64ae945be";
                var    OpenTok   = new OpenTok(ApiKey, ApiSecret);
                var    session   = OpenTok.CreateSession(mediaMode: MediaMode.ROUTED);
                //var session=OpenTok.CreateSession();
                // Store this sessionId in the database for later use:
                string sessionId = session.Id;
                //string token = OpenTok.GenerateToken(sessionId);
                double    inOneMonth = (DateTime.UtcNow.Add(TimeSpan.FromDays(30)).Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                string    token      = session.GenerateToken(role: Role.MODERATOR, expireTime: inOneMonth);
                Vtransact ltranact   = new Vtransact();
                ltranact.SessionId   = sessionId;
                ltranact.TherapistId = therapistId;
                ltranact.Status      = 0;
                ltranact.Token       = token;
                Vtransact _result = lVTransactRepository.insertVTransact(ltranact);

                return(Json(new { Status = (int)HttpStatusCode.OK, result = "success", VTransact = _result, TimeZone = DateTime.UtcNow.ToString("s") }));
            }
            catch (Exception ex)
            {
                return(Json(new { Status = (int)HttpStatusCode.InternalServerError, result = "failed", TimeZone = DateTime.UtcNow.ToString("s") }));
            }
        }
 public IActionResult VideoCallTherapist(string patientId)
 {
     try
     {
         if (!string.IsNullOrEmpty(HttpContext.Session.GetString("UserId")) && !string.IsNullOrEmpty(patientId))
         {
             Vtransact lgetOpenSession = lVTransactRepository.getVTransactDetails(HttpContext.Session.GetString("UserId"), patientId);
             if (lgetOpenSession != null)
             {
                 HttpContext.Session.SetString("VideoSessionId", lgetOpenSession.SessionId);
                 HttpContext.Session.SetString("Token", lgetOpenSession.Token);
             }
             else
             {
                 int    ApiKey    = ConfigVars.NewInstance.OpenTokAPIKey;       //46201082
                 string ApiSecret = ConfigVars.NewInstance.OpenTokAPISecretKey; // "fbef52398143449c9b269e1357d797c64ae945be";
                 var    OpenTok   = new OpenTok(ApiKey, ApiSecret);
                 var    session   = OpenTok.CreateSession(mediaMode: MediaMode.ROUTED);
                 //var session = OpenTok.CreateSession();
                 // Store this sessionId in the database for later use:
                 string sessionId = session.Id;
                 //string token = OpenTok.GenerateToken(sessionId);
                 double    inOneMonth = (DateTime.UtcNow.Add(TimeSpan.FromDays(30)).Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                 string    token      = session.GenerateToken(role: Role.MODERATOR, expireTime: inOneMonth);
                 Vtransact ltranact   = new Vtransact();
                 ltranact.SessionId   = sessionId;
                 ltranact.TherapistId = HttpContext.Session.GetString("UserId");
                 ltranact.Status      = 0;
                 ltranact.Token       = token;
                 Vtransact _result = lVTransactRepository.insertVTransact(ltranact);
                 if (_result != null)
                 {
                     HttpContext.Session.SetString("VideoSessionId", _result.SessionId);
                     HttpContext.Session.SetString("Token", _result.Token);
                 }
             }
         }
     }
     catch (Exception ex)
     {
     }
     return(View());
 }