//
        // GET: /Home/

        public ActionResult Index()
        {
            NameValueCollection appSettings = ConfigurationManager.AppSettings;

            ViewBag.APIKey = appSettings["opentok_key"];

            OpenTokSDK opentok = new OpenTokSDK();

            string sessionId = opentok.CreateSession(Request.ServerVariables["REMOTE_ADDR"]);

            Dictionary <string, object> tokenOptions = new Dictionary <string, object>();

            tokenOptions.Add(TokenPropertyConstants.ROLE, RoleConstants.MODERATOR);
            ViewBag.Token = opentok.GenerateToken(sessionId, tokenOptions);
            return(View());
        }
        //Connecting Video Chat for Both(patient and Doctor)
        public void VidoeChat()
        {
            lblPatientMobileNo.Text = string.Empty;
            if (Request.QueryString["session"] != null)
            {
                //sessionId = Request.QueryString["session"].ToString();
                //token = opentok.GenerateToken(sessionId);
                hdsession.Value = Request.QueryString["session"].ToString();
                hdtoken.Value   = opentok.GenerateToken(hdsession.Value);

                try
                {
                    Hashtable htSearch = new Hashtable();
                    DataSet   dsList   = new DataSet();
                    myonline.Biz.ADM.VideoChat objBiz = null;
                    objBiz = new myonline.Biz.ADM.VideoChat();
                    htSearch.Add("flag", 7);
                    htSearch.Add("Session", hdsession.Value);
                    if (System.Web.HttpContext.Current.Session["TimeZone"] != null && Convert.ToString(Session["TimeZone"]) != "-")
                    {
                        htSearch.Add("Time", System.Web.HttpContext.Current.Session["TimeZone"]);
                    }
                    else
                    {
                        htSearch.Add("Time", "+5:30");
                    }
                    dsList = objBiz.GetTrainerAndTranieeName(htSearch);
                    if (dsList.Tables["ERR_TABLE"] == null || dsList.Tables["ERR_TABLE"].Rows.Count == 0)
                    {
                        string session_id = hdsession.Value;
                        string token_id   = hdtoken.Value;
                        if (dsList.Tables[0] != null && dsList.Tables[0].Rows.Count > 0)
                        {
                            if (dsList.Tables[0].Rows[0][0].ToString() != "0")
                            {
                                //lbltrainer.Text = dsList.Tables[0].Rows[0]["DoctorName"].ToString();
                                //lbltrainee.Text = dsList.Tables[0].Rows[0]["PatientName"].ToString();

                                lbltrainer.Text = dsList.Tables[0].Rows[0]["PatientName"].ToString().ToLower();
                                lbltrainee.Text = dsList.Tables[0].Rows[0]["DoctorName"].ToString().ToLower();

                                hdnPatientName.Value = dsList.Tables[0].Rows[0]["PatientName"].ToString().ToLower();
                                PatientId            = dsList.Tables[0].Rows[0][2].ToString();
                                DoctorId             = dsList.Tables[0].Rows[0][3].ToString();
                                AppointMentId        = dsList.Tables[0].Rows[0][4].ToString();
                                AppontMentId.Value   = AppointMentId;
                            }
                            else
                            {
                                Response.Redirect(ResolveUrl("DoctorVideoChat.aspx?Request=false"));
                            }
                        }
                        else if (dsList.Tables[0] == null || dsList.Tables[0].Rows.Count == 0)
                        {
                        }
                    }
                }
                catch (Exception ex)
                { Response.Write(ex.InnerException); }
                //Gettime();
                //Page.ClientScript.RegisterStartupScript(Page.GetType(), "onload", "StartVideo();", true);

                ScriptManager.RegisterStartupScript(this, this.GetType(), "onload", "StartVideo();", true);
            }
            else
            {
                string     msg             = string.Empty;
                string     sessionId       = string.Empty;
                string     token           = string.Empty;
                OpenTokSDK opentok         = new OpenTokSDK();
                Hashtable  htSearch        = new Hashtable();
                DataSet    dsList          = new DataSet();
                string     ReturnStatusMsg = string.Empty;
                string     sTransMsg       = String.Empty;
                try
                {
                    //sessionId = opentok.CreateSession("Global-Training");
                    //token = opentok.GenerateToken(sessionId);
                    string abcdsession = opentok.CreateSession("Global-Training");
                    string abcdtoken   = opentok.GenerateToken(abcdsession);

                    hdsession.Value = abcdsession;
                    hdtoken.Value   = abcdtoken;

                    myonline.Biz.ADM.VideoChat objBiz = null;
                    objBiz = new myonline.Biz.ADM.VideoChat();
                    htSearch.Clear();
                    htSearch.Add("flag", 2);
                    htSearch.Add("doctorId", HttpContext.Current.Session["USER_SEQ"]);
                    htSearch.Add("Chat_Status", "Pending");
                    htSearch.Add("AppointMentId", Request.QueryString["AppointMentId"]);

                    htSearch.Add("Session_Id", hdsession.Value);
                    htSearch.Add("Generate_Date", DateTime.UtcNow.ToString());
                    htSearch.Add("Expire_Date", DateTime.UtcNow.AddMinutes(15));
                    if (System.Web.HttpContext.Current.Session["TimeZone"] != null && Convert.ToString(Session["TimeZone"]) != "-")
                    {
                        htSearch.Add("Time", System.Web.HttpContext.Current.Session["TimeZone"]);
                    }
                    else
                    {
                        htSearch.Add("Time", "+5:30");
                    }
                    dsList = objBiz.Send_request(htSearch, ref ReturnStatusMsg);

                    if (dsList.Tables["ERR_TABLE"] == null || dsList.Tables["ERR_TABLE"].Rows.Count == 0)
                    {
                        string session_id = hdsession.Value;
                        string token_id   = hdtoken.Value;
                        if (dsList.Tables[0] != null && dsList.Tables[0].Rows.Count > 0)
                        {
                            if (dsList.Tables[0].Rows[0][0].ToString() != "0")
                            {
                                AppontMentId.Value      = dsList.Tables[0].Rows[0][1].ToString();
                                lbltrainer.Text         = dsList.Tables[0].Rows[0]["DoctorName"].ToString().ToLower();
                                lbltrainee.Text         = dsList.Tables[0].Rows[0]["PatientName"].ToString().ToLower();
                                hdnDoctorName.Value     = dsList.Tables[0].Rows[0]["DoctorName"].ToString().ToLower();
                                DoctorId                = dsList.Tables[0].Rows[0][4].ToString();
                                PatientId               = dsList.Tables[0].Rows[0][5].ToString();
                                AppointMentId           = dsList.Tables[0].Rows[0][1].ToString();
                                lblPatientMobileNo.Text = dsList.Tables[0].Rows[0]["MobileNumber"].ToString();

                                //Page.ClientScript.RegisterStartupScript(Page.GetType(), "onload", "StartVideo();", true);

                                ScriptManager.RegisterStartupScript(this, this.GetType(), "onload", "StartVideo();", true);
                            }
                            else
                            {
                                Response.Redirect(ResolveUrl("DoctorVideoChat.aspx?Request=false"));
                            }
                        }
                        else if (dsList.Tables[0] == null || dsList.Tables[0].Rows.Count == 0)
                        {
                        }
                    }
                    else if (dsList.Tables["ERR_TABLE"] != null && dsList.Tables["ERR_TABLE"].Rows.Count != 0)
                    {
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }