Ejemplo n.º 1
0
        /// <summary>
        /// Tries to initializes the connection with the gateway.
        /// We need a session token given from the gateway for us to send any commands to it.
        /// </summary>
        /// <returns>True on success, false on failure</returns>
        public bool InitializeConnection()
        {
            bool retVal = false;

            lock (janus_core_lock_obj)
            {
                if (SessionToken == 0)
                {
                    RestRequest request = new RestRequest(Method.POST);
                    request.RequestFormat = DataFormat.Json;
                    dynamic obj = new ExpandoObject();
                    if (api_secret.HasValue())
                    {
                        obj.apisecret = api_secret;
                    }
                    obj.janus       = "create";
                    obj.transaction = GetNewRandomTransaction();
                    request.AddBody(obj);
                    JanusBaseResponse resp = Execute <JanusBaseResponse>(request);
                    if (resp == null || resp.janus != "success")
                    {
                        retVal = false;
                    }
                    else
                    {
                        SessionToken = resp.data.id;
                        _client.AddDefaultUrlSegment("SessionToken", SessionToken.ToString());
                        delay_timeout.Start();
                        retVal = true;
                    }
                }
            }
            return(retVal);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This initializes the connection to the video room plugin.
        /// This must be called first so that the plugin can be attached to the janus server session already created.
        /// </summary>
        /// <returns></returns>
        public bool InitializeVideoRoomConnection()
        {
            if (IsRestClientInitialized() && janus_video_plugin_ref.IncRef())
            {
                bool retVal = true;
                lock (video_room_lock_obj)
                {
                    if (JanusVideoRoomPluginHandle == 0)
                    {
                        RestRequest request = new RestRequest(Method.POST);
                        request.Resource = "{SessionToken}";
                        string transaction = GetNewRandomTransaction();
                        request.RequestFormat = DataFormat.Json;
                        dynamic msg = new ExpandoObject();
                        msg.janus       = "attach";
                        msg.plugin      = "janus.plugin.videoroom";
                        msg.transaction = GetNewRandomTransaction();
                        if (api_secret.HasValue())
                        {
                            msg.apisecret = api_secret;
                        }
                        request.AddBody(msg);
                        JanusBaseResponse resp = Execute <JanusBaseResponse>(request);

                        if (resp == (null) || resp.janus == "error")
                        {
                            retVal = false;
                        }
                        else
                        {
                            JanusVideoRoomPluginHandle = resp.data.id;
                            delay_timeout.ResetDelay(29);
                            retVal = true;
                        }
                    }
                }
                janus_video_plugin_ref.DecRef();
                return(retVal);
            }
            return(false);
        }