可删除未发言用户
							parent
							
								
									5a6e5c6820
								
							
						
					
					
						commit
						cec4fb1469
					
				
							
								
								
									
										11
									
								
								js/custom.js
								
								
								
								
							
							
						
						
									
										11
									
								
								js/custom.js
								
								
								
								
							|  | @ -153,7 +153,7 @@ function exitEv(id){ | ||||||
| 	$(`${id}`).remove(); | 	$(`${id}`).remove(); | ||||||
| } | } | ||||||
| // 进入广场
 | // 进入广场
 | ||||||
| function peopleObj(name,uid,say,action){ | function peopleObj(name,uid,say,action,active_time){ | ||||||
| 	let yspHtml = ''; | 	let yspHtml = ''; | ||||||
| 	let yspData = [ | 	let yspData = [ | ||||||
| 		{ | 		{ | ||||||
|  | @ -166,11 +166,12 @@ function peopleObj(name,uid,say,action){ | ||||||
| 			peopleImg:`people-img0${Math.floor(Math.random()*6+1)}`,//人物图片
 | 			peopleImg:`people-img0${Math.floor(Math.random()*6+1)}`,//人物图片
 | ||||||
| 			ying_guang:`stick-0${Math.floor(Math.random()*5+1)}`,//荧光棒
 | 			ying_guang:`stick-0${Math.floor(Math.random()*5+1)}`,//荧光棒
 | ||||||
| 			dancin:action, | 			dancin:action, | ||||||
|  | 			active_time: active_time | ||||||
| 		} | 		} | ||||||
| 	] | 	] | ||||||
| 	$.each(yspData, function (commentIndex, comment) { | 	$.each(yspData, function (commentIndex, comment) { | ||||||
| 			yspHtml += ` | 			yspHtml += ` | ||||||
| 			<div id="${comment.uid}" class="dance-people data${peopleId}" style="top: ${comment.top}; left: ${comment.left};"> | 			<div id="${comment.uid}" data-time="${comment.active_time}" class="dance-people data${peopleId}" style="top: ${comment.top}; left: ${comment.left};"> | ||||||
| 				<div class="speak ">${comment.say}</div> | 				<div class="speak ">${comment.say}</div> | ||||||
| 				<div class="people-img ${comment.peopleImg} ${comment.dancin}"> | 				<div class="people-img ${comment.peopleImg} ${comment.dancin}"> | ||||||
| 					<div class="stick ${comment.ying_guang}"></div> | 					<div class="stick ${comment.ying_guang}"></div> | ||||||
|  | @ -227,6 +228,12 @@ $(function(){ | ||||||
| 			changeMusic() | 			changeMusic() | ||||||
| 		}, false); | 		}, false); | ||||||
| 	} | 	} | ||||||
|  | 
 | ||||||
|  | 	// 60s检测一次  十分钟没发言的删除
 | ||||||
|  | 	setInterval(function () { | ||||||
|  | 		delExpireDiv() | ||||||
|  | 	}, 60000) | ||||||
|  | 	 | ||||||
| 	//烟花
 | 	//烟花
 | ||||||
| 	// setInterval(()=>{
 | 	// setInterval(()=>{
 | ||||||
| 	// 	setTimeout(function() {
 | 	// 	setTimeout(function() {
 | ||||||
|  |  | ||||||
							
								
								
									
										70
									
								
								js/handle.js
								
								
								
								
							
							
						
						
									
										70
									
								
								js/handle.js
								
								
								
								
							|  | @ -1,4 +1,13 @@ | ||||||
|  | // 对象uid=>最近弹幕时间
 | ||||||
| let uidObj = {} | let uidObj = {} | ||||||
|  | 
 | ||||||
|  | // 歌曲库地址
 | ||||||
|  | let musicUrl = 'https://bili.scdxtc.cn' | ||||||
|  | 
 | ||||||
|  | // 自动删除不说话用户
 | ||||||
|  | let autoDel = true | ||||||
|  | // 多少秒不说话删除
 | ||||||
|  | let speakExpireTime = 10*60 | ||||||
| // 歌曲列表
 | // 歌曲列表
 | ||||||
| var musicList = [] | var musicList = [] | ||||||
| 
 | 
 | ||||||
|  | @ -79,22 +88,22 @@ function getLeader() { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function music() { | function music() { | ||||||
|     $.get('https://bili.scdxtc.cn', function (res) { |     $.get(musicUrl, function (res) { | ||||||
|         musicList = res |         musicList = res | ||||||
|         if (musicList.length > 0) { |         if (musicList.length > 0) { | ||||||
|             $('#music source').attr('src', 'https://bili.scdxtc.cn/music/'+musicList[0]) |             $('#music source').attr('src', musicUrl+'/music/'+musicList[0]) | ||||||
|         } |         } | ||||||
|     }) |     }) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // 切歌
 | // 切歌
 | ||||||
| function changeMusic() { | function changeMusic() { | ||||||
|     $.get('https://bili.scdxtc.cn', function (res) { |     $.get(musicUrl, function (res) { | ||||||
|         musicList = res |         musicList = res | ||||||
|         if (musicList.length > 0) { |         if (musicList.length > 0) { | ||||||
|             let index = Math.floor(Math.random()*(musicList.length-1)) |             let index = Math.floor(Math.random()*(musicList.length-1)) | ||||||
|             $('#music').data('song', musicList[index]) |             $('#music').data('song', musicList[index]) | ||||||
|             $('#music source').attr('src', 'https://bili.scdxtc.cn/music/'+musicList[index]) |             $('#music source').attr('src', musicUrl+'/music/'+musicList[index]) | ||||||
|             $('#music')[0].load() |             $('#music')[0].load() | ||||||
|         } |         } | ||||||
|     }) |     }) | ||||||
|  | @ -107,10 +116,24 @@ function peopleHan(val){ | ||||||
| function dancer(val){ | function dancer(val){ | ||||||
| 	return allEventList.includes(val); | 	return allEventList.includes(val); | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | // 删除久未说话的人
 | ||||||
|  | function delExpireDiv() { | ||||||
|  |     if (!autoDel) { | ||||||
|  |         return false | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     let timestamp = parseInt(new Date().getTime()/1000) | ||||||
|  |     let delList = $(".dance-people").filter(function() { | ||||||
|  |         return  $(this).attr("data-time") < timestamp - speakExpireTime; | ||||||
|  |     }) | ||||||
|  |     console.log(delList.length, speakExpireTime+'秒未说话人数') | ||||||
|  |     delList.remove(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| // 接受消息处理
 | // 接受消息处理
 | ||||||
| function receiveMessage(event) | function receiveMessage(event) | ||||||
| { | { | ||||||
|      |  | ||||||
|     // console.log(event.data, '接受弹幕')
 |     // console.log(event.data, '接受弹幕')
 | ||||||
|     // 我们能信任信息来源吗?
 |     // 我们能信任信息来源吗?
 | ||||||
|     if (event.origin !== "https://live.bilibili.com") { |     if (event.origin !== "https://live.bilibili.com") { | ||||||
|  | @ -119,7 +142,9 @@ function receiveMessage(event) | ||||||
| 
 | 
 | ||||||
|     let dataList = JSON.parse(event.data) |     let dataList = JSON.parse(event.data) | ||||||
|     let data = dataList.dm |     let data = dataList.dm | ||||||
|     let adminList = dataList.admin |     // 目前硬编码大航海列表
 | ||||||
|  |     // let adminList = dataList.admin
 | ||||||
|  | 	adminList = ['内有猛犬小心','热心市民阿狄呐','流域_墨绿绿']; | ||||||
| 
 | 
 | ||||||
|     if (data.length <= 0) { |     if (data.length <= 0) { | ||||||
|         return false |         return false | ||||||
|  | @ -129,7 +154,6 @@ function receiveMessage(event) | ||||||
|     if (data.ct === '') { |     if (data.ct === '') { | ||||||
|         return false |         return false | ||||||
|     } |     } | ||||||
| 	adminList = ['内有猛犬小心','热心市民阿狄呐','流域_墨绿绿']; |  | ||||||
| 
 | 
 | ||||||
|     // 大航海列表
 |     // 大航海列表
 | ||||||
|     if (adminList.length > 0) { |     if (adminList.length > 0) { | ||||||
|  | @ -164,10 +188,15 @@ function receiveMessage(event) | ||||||
|     // uid是否存在 不存在则存入uidObj
 |     // uid是否存在 不存在则存入uidObj
 | ||||||
|     let isNew = 0 |     let isNew = 0 | ||||||
| 	// console.log(uidObj[data.uid],'uidObj[data.uid]');
 | 	// console.log(uidObj[data.uid],'uidObj[data.uid]');
 | ||||||
|     if (!uidObj[data.uid]) { |     let speakTime = uidObj[data.uid]; | ||||||
|  |     if (!speakTime) { | ||||||
|         isNew = 1 |         isNew = 1 | ||||||
|         uidObj[data.uid] = data.uname |     } else if (autoDel && speakTime < parseInt(new Date().getTime()/1000) - speakExpireTime){ | ||||||
|  |         //存在 但是最近弹幕时间已在过期时间外。
 | ||||||
|  |         isNew = 1; | ||||||
|     } |     } | ||||||
|  |     // 记录uid最近弹幕时间
 | ||||||
|  |     uidObj[data.uid] = data.ts | ||||||
| 
 | 
 | ||||||
|     // console.log(isNew, data.uname + ' 是否存在')
 |     // console.log(isNew, data.uname + ' 是否存在')
 | ||||||
| 
 | 
 | ||||||
|  | @ -180,7 +209,7 @@ function receiveMessage(event) | ||||||
|     let isLeader = data.uname == leaderInfo ? 1 : 0 |     let isLeader = data.uname == leaderInfo ? 1 : 0 | ||||||
|     let dm = {text: data.danmaku, uid: data.uid, uname: data.uname,  |     let dm = {text: data.danmaku, uid: data.uid, uname: data.uname,  | ||||||
|         event: eventName,  |         event: eventName,  | ||||||
|         is_new: isNew, is_admin: 0, is_leader: isLeader} |         is_new: isNew, is_admin: 0, is_leader: isLeader,active_time: data.ts} | ||||||
|     let leader = { |     let leader = { | ||||||
|         uid: 0, uname: leaderInfo, text: '', event: '' |         uid: 0, uname: leaderInfo, text: '', event: '' | ||||||
|     } |     } | ||||||
|  | @ -196,11 +225,13 @@ function receiveMessage(event) | ||||||
| 	// 新用户
 | 	// 新用户
 | ||||||
| 	if(dm.is_new==1){ | 	if(dm.is_new==1){ | ||||||
| 		// if(dm.uname!=leader.uname){//如果弹幕的人的名字不等于领舞者的名字,就创建一个人物
 | 		// if(dm.uname!=leader.uname){//如果弹幕的人的名字不等于领舞者的名字,就创建一个人物
 | ||||||
| 			peopleObj(dm.uname,dm.uid,dm.text,dm.event); | 			peopleObj(dm.uname,dm.uid,dm.text,dm.event,dm.active_time); | ||||||
| 		// }
 | 		// }
 | ||||||
| 	} else { | 	} else { | ||||||
| 		// 老用户
 | 		// 老用户
 | ||||||
| 		$(`#${dm.uid} .speak`).html(dm.text); | 		$(`#${dm.uid} .speak`).html(dm.text); | ||||||
|  |         //更新最近时间
 | ||||||
|  | 		$(`#${dm.uid}`).attr('data-time', dm.active_time); | ||||||
| 		$(`#${dm.uid} .speak`).removeClass("dn"); | 		$(`#${dm.uid} .speak`).removeClass("dn"); | ||||||
| 		setTimeout(()=>{ | 		setTimeout(()=>{ | ||||||
| 			$(`#${dm.uid} .speak`).addClass("dn"); | 			$(`#${dm.uid} .speak`).addClass("dn"); | ||||||
|  | @ -211,6 +242,10 @@ function receiveMessage(event) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|     num++; |     num++; | ||||||
|  | 
 | ||||||
|  |     // console.log(Object.keys(uidObj).length, 'uid 长度')
 | ||||||
|  |     // console.log(uidObj, 'uid')
 | ||||||
|  |     // console.log(num, '人物渲染个数')
 | ||||||
| 	// 显示领舞的昵称
 | 	// 显示领舞的昵称
 | ||||||
|     $('.lingname').text(leader.uname); |     $('.lingname').text(leader.uname); | ||||||
|     if (!isLeader) { |     if (!isLeader) { | ||||||
|  | @ -264,19 +299,6 @@ function receiveMessage(event) | ||||||
| 		} | 		} | ||||||
|     } |     } | ||||||
|     // -------------------- 每条弹幕处理 end -----------------------
 |     // -------------------- 每条弹幕处理 end -----------------------
 | ||||||
| 
 |  | ||||||
|     // event.source 就当前弹出页的来源页面
 |  | ||||||
|     // event.data 是 "hello there!"
 |  | ||||||
| 
 |  | ||||||
|     // 假设你已经验证了所受到信息的origin (任何时候你都应该这样做), 一个很方便的方式就是把event.source
 |  | ||||||
|     // 作为回信的对象,并且把event.origin作为targetOrigin
 |  | ||||||
|     // event.source.postMessage("hi there yourself!  the secret response " +
 |  | ||||||
|     // 						"is: rheeeeet!",
 |  | ||||||
|     // 					event.origin);
 |  | ||||||
| 
 |  | ||||||
|     // 数据是否为空
 |  | ||||||
|     // 弹幕类型判断 事件弹幕、内容弹幕
 |  | ||||||
|      |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| music(); | music(); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue