From 6ebea07f93556c04d879e56c42c84b63687cacde Mon Sep 17 00:00:00 2001 From: luyuan <1162963624@qq.com> Date: Fri, 27 Nov 2020 11:37:44 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=9F=BA=E6=9C=AC?= =?UTF-8?q?=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/common.js | 15 +++++++--- public/js/iminit.js | 65 ++++++++++++++++++++++++++++++++++++++++- public/js/rtc-client.js | 1 + public/zhibo.html | 6 ++-- 4 files changed, 79 insertions(+), 8 deletions(-) diff --git a/public/js/common.js b/public/js/common.js index d48e956..9d2578a 100644 --- a/public/js/common.js +++ b/public/js/common.js @@ -273,25 +273,32 @@ function addVideoView(id, isLocal = false) { function addMemberView(id) { let memberElm = $('#member-me').clone(); memberElm.attr('id', id); - memberElm.find('div.member-id').html(id); + // memberElm.attr('class', id); memberElm.css('display', 'flex'); memberElm.find("#video-btn").click((el)=>{ console.log(el) - console.log($(el.target).attr("src")) + const src = $(el.target).attr("src") == "img/camera-on.png" ? 1 : 0 console.log("video" + id); + sendsx(id,src) }) memberElm.find("#mic-btn").click((el)=>{ - console.log($(el.target).attr("src")) + const src = $(el.target).attr("src") == "img/mic-on.png" ? 1 : 0 console.log("mic" + id); + sendjinyan(id,src) }) memberElm.find("#video-btn").removeAttr("id") memberElm.find("#mic-btn").removeAttr("id") console.log("移除") - memberElm.appendTo($('#member-list')); + getname(id).then((res)=>{ + $("#" + id).find('div.member-id').html(res); + // console.log(.length) + }) + memberElm.appendTo($('#member-list')); } function removeView(id) { + console.log("被删除") if ($('#' + id)[0]) { $('#' + id).remove(); //将video-grid中第一个div设为main-video diff --git a/public/js/iminit.js b/public/js/iminit.js index 0074a6a..00bb585 100644 --- a/public/js/iminit.js +++ b/public/js/iminit.js @@ -1,9 +1,31 @@ let options = { SDKAppID: 1400435767 // 接入时需要将0替换为您的即时通信 IM 应用的 SDKAppID }; -let tim = TIM.create(options); +window.tim = TIM.create(options); tim.setLogLevel(0); +function getname(id){ + return new Promise((res, rej)=>{ + let promise = tim.getGroupMemberProfile({ + groupID:window.roomid, + userIDList:[id], + memberCustomFieldFilter:["nick"] + }) + promise.then(function(imResponse) { + console.log(imResponse.data.memberList); // 群成员列表 + res(imResponse.data.memberList[0].nick) + }).catch(function(imError) { + console.warn('getGroupMemberProfile error:', imError); + setTimeout(()=>{ + getname(id).then((e)=>{ + res(e) + }) + },1000) + }); + }) + +} function formatDateTime (inputTime) { + inputTime = inputTime * 1000 var date = new Date(inputTime); var y = date.getFullYear(); var m = date.getMonth() + 1; @@ -28,6 +50,9 @@ function formatDateTime (inputTime) { if(!event.data[i].payload.text){ break; } + if(event.data[i].payload.text.includes("beelinkMuteUserId") || event.data[i].payload.text.includes("inkTurnOffTheCameraUserId")){ + break; + } const list = $("#liaotianliebiao") const html = `
${formatDateTime(event.data[i].time)}
@@ -204,4 +229,42 @@ function formatDateTime (inputTime) { }); +function sendjinyan(id,type){ + const m = tim.createTextMessage({ + to: window.roomid, + conversationType: TIM.TYPES.CONV_GROUP, + payload: { + text: `beelinkMuteUserId:${id},isClose:${type}` + } + }) + const promise = tim.sendMessage(m); + promise.then(function(imResponse) { + // 发送成功 + console.log(imResponse); + + }).catch(function(imError) { + // 发送失败 + console.warn('sendMessage error:', imError); + }); +} + +function sendsx(id,type){ + const m = tim.createTextMessage({ + to: window.roomid, + conversationType: TIM.TYPES.CONV_GROUP, + payload: { + text: `beelinkTurnOffTheCameraUserId:${id},isClose:${type}` + } + }) + const promise = tim.sendMessage(m); + promise.then(function(imResponse) { + // 发送成功 + console.log(imResponse); + + }).catch(function(imError) { + // 发送失败 + console.warn('sendMessage error:', imError); + }); +} + // 开始登录 \ No newline at end of file diff --git a/public/js/rtc-client.js b/public/js/rtc-client.js index 12d5052..4d2f97e 100644 --- a/public/js/rtc-client.js +++ b/public/js/rtc-client.js @@ -205,6 +205,7 @@ class RtcClient { const userId = evt.userId; removeView(userId); console.log('peer-leave ' + userId); + }); // fired when a remote stream is added this.client_.on('stream-added', evt => { diff --git a/public/zhibo.html b/public/zhibo.html index 0b760b2..fb0f534 100644 --- a/public/zhibo.html +++ b/public/zhibo.html @@ -422,8 +422,10 @@ $('body').bootstrapMaterialDesign(); }); - + + + @@ -432,8 +434,6 @@ - -