/// <summary> /// This will try and remove a given room by the id. If no room is found, the response will contain an error code. /// </summary> /// <param name="room_id">The room id to remove</param> /// <returns>Verify success by checking error code</returns> public JanusVideoRoomResponse RemoveRoom(int room_id, string _secret = null) { if (janus_video_plugin_ref.IncRef()) { if (InitializeVideoRoomConnection()) { if (JanusVideoRoomPluginHandle > 0) { dynamic obj = new ExpandoObject(); obj.request = "destroy"; obj.room = room_id; if (_secret.HasValue()) { obj.secret = _secret; } dynamic msg = new ExpandoObject(); msg.janus = "message"; msg.transaction = GetNewRandomTransaction(); if (api_secret.HasValue()) { msg.apisecret = api_secret; } msg.body = obj; var request = new RestRequest(Method.POST); request.RequestFormat = DataFormat.Json; request.Resource = "{SessionToken}/" + JanusVideoRoomPluginHandle; request.AddBody(msg); JanusVideoRoomResponse response = Execute <JanusVideoRoomResponse>(request); if (response != null && response.plugindata.data.room > 0) { delay_timeout.ResetDelay(29); } janus_video_plugin_ref.DecRef(); return(response); } } else { janus_video_plugin_ref.DecRef(); } } return(JanusRoomSessionShuttingDownError()); }
private JanusVideoRoomResponse JanusRoomSessionShuttingDownError() { var error_resp = new JanusVideoRoomResponse { janus = "failure", plugindata = new JanusVideoRoomPluginData { plugin = "janus.plugin.videoroom", data = new JanusVideoRoomPluginDataInternal { videoroom = "none", room = 0, error_code = (int)JanusRoomErrorCodes.JANUS_VIDEOROOM_ERROR_UNKNOWN_ERROR, error = "We seem to be in the middle of shutting down" } } }; return(error_resp); }
/// <summary> /// Creates a room against the janus video room plugin. /// Will automatically attach the plugin if it is not already attached. /// However, it will not initialize the default session /// </summary> /// <param name="roomid">Mandatory unique room id to create</param> /// <param name="_description">Optional, room description</param> /// <param name="_secret">Optional, room secret for room access/modifications</param> /// <param name="_bitrate">Optional, bitrate what the streams will be</param> /// <param name="_publishers">Optional, the default number of publishers allowed</param> /// <param name="_record">Optional, whether to record the room or not</param> /// <param name="_rec_dir">Optional, the recording directory</param> /// <param name="_fir_freq">Optional, the frequency of FIR requests for the room...also sends PLI requests at the same time</param> /// <param name="_private">Optional, whether the room is private or not...defaults to not</param> /// <returns>Janus room response object. Will contain errors if not successful</returns> public JanusVideoRoomResponse CreateRoom(int roomid, string _description = null, string _secret = null, int _bitrate = 0, string _publishers = null, bool _record = false, string _rec_dir = null, int _fir_freq = 0, bool _private = false) { if (janus_video_plugin_ref.IncRef()) { if (!IsRestClientInitialized()) { var resp = new JanusVideoRoomResponse { janus = "failure", plugindata = new JanusVideoRoomPluginData { plugin = "janus.plugin.videoroom", data = new JanusVideoRoomPluginDataInternal { videoroom = "none", room = 0, error_code = (int)JanusRoomErrorCodes.JANUS_VIDEOROOM_ERROR_NO_SESSION, error = "Initialize the API client first" } } }; janus_video_plugin_ref.DecRef(); return(resp); } if (!InitializeVideoRoomConnection()) { var resp = new JanusVideoRoomResponse { janus = "failure", plugindata = new JanusVideoRoomPluginData { plugin = "janus.plugin.videoroom", data = new JanusVideoRoomPluginDataInternal { videoroom = "none", room = 0, error_code = (int)JanusRoomErrorCodes.JANUS_VIDEOROOM_ERROR_NO_SESSION, error = "Could not attach the plugin" } } }; janus_video_plugin_ref.DecRef(); return(resp); } var room_request = new RestRequest(Method.POST); room_request.Resource = "{SessionToken}/" + JanusVideoRoomPluginHandle; room_request.RequestFormat = DataFormat.Json; dynamic obj = new ExpandoObject(); obj.request = "create"; obj.room = roomid; obj.record = _record; obj.is_private = _private; if (_bitrate > 0) { obj.bitrate = _bitrate; } if (_fir_freq > 0) { obj.fir_freq = _fir_freq; } if (_description.HasValue()) { obj.description = _description; } if (_secret.HasValue()) { obj.secret = _secret; } if (_rec_dir.HasValue()) { obj.rec_dir = _rec_dir; } dynamic msg = new ExpandoObject(); if (api_secret.HasValue()) { msg.apisecret = api_secret; } msg.janus = "message"; msg.transaction = GetNewRandomTransaction(); msg.body = obj; room_request.AddBody(msg); JanusVideoRoomResponse response = Execute <JanusVideoRoomResponse>(room_request); if (response != null && response.plugindata.data.room > 0) { delay_timeout.ResetDelay(29); } janus_video_plugin_ref.DecRef(); return(response); } return(JanusRoomSessionShuttingDownError()); }