//从聊天室队列中添加连麦请求 private void RequestPushMicLink(string roomid, string uid, string ext, BypassLSCommon.InactionType type) { string url = "https://app.netease.im/api/chatroom/pushMicLink"; string app_key = "6f49e3f759ccd47810b445444eebc090"; string body = "roomid=" + roomid + "&uid=" + uid + "&ext=" + ext; int bodySize = body.Length; NIMHttp.NimHttpDef.ResponseCb responseCb = (userData, result, responseCode, responseContent) => { JObject jo = (JObject)JsonConvert.DeserializeObject(responseContent); if (responseCode == ResponseCode.kNIMResSuccess) { Action act = () => { rt_prompt_info.Text += Helper.UserHelper.SelfId + "加入麦序队列成功\n"; if (video_interaction_) { btn_video_interact.Text = "取消视频互动"; video_interaction_ = true; } if (audio_interaction_) { btn_audio_interact.Text = "取消音频互动"; audio_interaction_ = true; } }; this.BeginInvoke(act); } else { if (video_interaction_) { btn_video_interact.Text = "视频互动"; video_interaction_ = false; } if (audio_interaction_) { audio_interaction_ = false; btn_audio_interact.Text = "音频互动"; } } }; IntPtr request = NIMHttp.HttpAPI.CreateRequest(url, body, bodySize, responseCb, IntPtr.Zero); NIMHttp.HttpAPI.AddHeader(request, "Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); NIMHttp.HttpAPI.AddHeader(request, "appKey", app_key); NIMHttp.HttpAPI.PostRequest(request); }
//查询聊天室地址 private void RequestAddress(string roomid, string uid) { string url = "https://app.netease.im/api/chatroom/requestAddress"; string app_key = "6f49e3f759ccd47810b445444eebc090"; StringWriter sw = new StringWriter(); JsonWriter writer = new JsonTextWriter(sw); writer.WriteStartObject(); writer.WritePropertyName("roomid"); writer.WriteValue(roomid); writer.WritePropertyName("uid"); writer.WriteValue(uid); writer.WriteEndObject(); writer.Flush(); string body = sw.GetStringBuilder().ToString(); int bodySize = body.Length; NIMHttp.NimHttpDef.ResponseCb responseCb = (userData, result, responseCode, responseContent) => { try { if (responseCode == ResponseCode.kNIMResSuccess) { JObject jo = (JObject)JsonConvert.DeserializeObject(responseContent); int json_res = Convert.ToInt32(jo["res"]); if (json_res == Convert.ToInt32(ResponseCode.kNIMResSuccess)) { rt_pull_url_ = jo["msg"]["live"]["rtmpPullUrl"].ToString(); Action act = () => { rt_pull_url.Text = rt_pull_url_; }; if (IsDisposed || !this.IsHandleCreated) { return; } this.Invoke(act); } } } catch (Exception ex) { } }; IntPtr request = NIMHttp.HttpAPI.CreateRequest(url, body, bodySize, responseCb, IntPtr.Zero); NIMHttp.HttpAPI.AddHeader(request, "Content-Type", "application/json;charset=utf-8"); NIMHttp.HttpAPI.AddHeader(request, "appKey", app_key); NIMHttp.HttpAPI.PostRequest(request); }
private void CreateMyRoomInfo() { string roomname = Guid.NewGuid().ToString("N"); string api_addr = "https://app.netease.im/api/chatroom/hostEntrance"; string app_key = "6f49e3f759ccd47810b445444eebc090"; string ext = ""; StringWriter sw = new StringWriter(); JsonWriter writer = new JsonTextWriter(sw); writer.WriteStartObject(); if (rb_audio.Checked) { writer.WritePropertyName("type"); writer.WriteValue(Convert.ToInt16(BypassLSCommon.InactionType.kAudio)); } else { writer.WritePropertyName("type"); writer.WriteValue(Convert.ToInt16(BypassLSCommon.InactionType.kVedio)); } writer.WritePropertyName("meetingName"); writer.WriteValue(roomname); writer.WriteEndObject(); writer.Flush(); ext = sw.GetStringBuilder().ToString(); string body = "uid=" + Helper.UserHelper.SelfId + "&ext=" + ext; int bodySize = body.Length; NIMHttp.NimHttpDef.ResponseCb responseCb = (userData, result, responseCode, responseContent) => { if (!result || responseCode != NIM.ResponseCode.kNIMResSuccess) { Action action = () => { MessageBox.Show("进入房间失败"); }; this.Invoke(action); } else { JObject jo = (JObject)JsonConvert.DeserializeObject(responseContent); int res = Convert.ToInt16(jo["res"]); if (res != 200) { Action action = () => { MessageBox.Show("进入房间出错,errorcode:" + res.ToString()); }; this.Invoke(action); } else { string roomid = jo["msg"]["roomid"].ToString(); string rtmpPullUrl = jo["msg"]["live"]["rtmpPullUrl"].ToString(); string pushUrl = jo["msg"]["live"]["pushUrl"].ToString(); Action action = () => { BypassLivingStreamForm form = new BypassLivingStreamForm(true); form.SetPullUrl(rtmpPullUrl); Action act = () => { form.ShowDialog(); }; this.BeginInvoke(act); form.RequestEnter(roomid); }; this.BeginInvoke(action); } } }; IntPtr request = NIMHttp.HttpAPI.CreateRequest(api_addr, body, bodySize, responseCb, IntPtr.Zero); NIMHttp.HttpAPI.AddHeader(request, "Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); NIMHttp.HttpAPI.AddHeader(request, "appKey", app_key); NIMHttp.HttpAPI.PostRequest(request); }