Skip to content

Commit

Permalink
尝试修复无限递归获取房间列表(破站爆炸),修复增量更新的一个小bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mscststs committed Jul 7, 2018
1 parent b2e1cae commit 3762222
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 50 deletions.
2 changes: 1 addition & 1 deletion dist/electron/renderer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/electron/styles.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bls",
"version": "0.1.2",
"version": "0.1.3",
"author": "十字 <mscststs@qq.com>",
"description": "Bilibili Live Super",
"license": null,
Expand Down
99 changes: 54 additions & 45 deletions src/renderer/components/DanmakuAddons/MultiaddsListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,56 +56,59 @@ class dm {
}

let roomid = await this.getOnlineRoom();
this.roomid = roomid;
this.dm = new DmService({
roomId: roomid
});
this.dm.on("connected", () => {
this.status = true;
eve.emit("success", `${this.name}分区: 直播间 ${roomid} 连接成功`);
});
this.dm.connect();
this.dm.on("data", data => {
switch (data.type) {
case "comment":
break;
case "SYS_MSG":
/* 绘马没有roomid参数,小电视+摩天大楼等绿色通知 */
if (data.roomid) {
if (data.msg.indexOf("摩天大楼")>=0) {
//仅提取摩天大楼
if(this.allow){
eve.emit("dm_SmallTv", data);
if(roomid!=0){
this.roomid = roomid;
this.dm = new DmService({
roomId: roomid
});
this.dm.on("connected", () => {
this.status = true;
eve.emit("success", `${this.name}分区: 直播间 ${roomid} 连接成功`);
});
this.dm.connect();
this.dm.on("data", data => {
switch (data.type) {
case "comment":
break;
case "SYS_MSG":
/* 绘马没有roomid参数,小电视+摩天大楼等绿色通知 */
if (data.roomid) {
if (data.msg.indexOf("摩天大楼")>=0) {
//仅提取摩天大楼
if(this.allow){
eve.emit("dm_SmallTv", data);
}
}
//console.log(data);
}
//console.log(data);
}
break;
case "SYS_GIFT":
break;
case "SYS_GIFT":

break;
case "online":
if(data.type!="online"||data.number<=10){
//number为0时即为下播
break;
case "online":
if(data.type!="online"||data.number<=10){
//number为0时即为下播
this.disconnect();
this.connect();
//当直播下线时自动切换到其他主播
eve.emit("info",`${this.name}分区: 检测到下播,自动切换其他房间 ...`);
}
//console.log(data);
break;
case "gift":
break;
case "ROOM_SILENT_OFF":
this.disconnect();
this.connect();
//当直播下线时自动切换到其他主播
eve.emit("info",`${this.name}分区: 检测到下播,自动切换其他房间 ...`);
}
//console.log(data);
break;
case "gift":
break;
case "ROOM_SILENT_OFF":
this.disconnect();
this.connect();
//当直播下线时自动切换到其他主播
eve.emit("info",`${this.name}分区: 检测到下播,自动切换其他房间 ...`);
break;
default:
break;
}
});
break;
default:
break;
}
});
}

this._initConnect = true; //设置initConnect的值,用于监听器判断当前是正在工作中状态
}
disconnect() {
Expand All @@ -115,7 +118,7 @@ class dm {
}
this.dm = {};
}
async getOnlineRoom() {
async getOnlineRoom(retry = 0) {
let roomid ;
try{
let rq = await api.send("room/v1/area/getRoomList", {
Expand All @@ -142,7 +145,13 @@ class dm {
}
catch(e){
eve.emit("info",`${this.name} :获取直播房间:${e.message}`);
roomid = this.getOnlineRoom();
if(retry>=5){
roomid = 0;
}else{
eve.emit("info",`获取房间列表出错,第${retry+1}次尝试`);
roomid = await this.getOnlineRoom(retry+1);
}

}
finally{
return roomid;
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/stocks/About.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default {
if(content){
await fs.WriteString(f.localPath,content);
}else{
new Error("更新失败,无法获取增量更新文件");
throw new Error("更新失败,无法获取增量更新文件");
}
}
this.$eve.emit("restart","更新完成,即将重启以升级新版本");
Expand Down Expand Up @@ -133,7 +133,7 @@ export default {
return result;
}catch(e){
if(retry<remoteBaseLink.length){
return this.getRemoteFile(tag,name,retry-(-1));
return this.getRemoteFile(tag,f,retry-(-1));
}else{
this.$eve.emit("error","获取增量更新文件时: "+e.message);
return false;
Expand Down

0 comments on commit 3762222

Please sign in to comment.