floating-live 0.8.4 → 0.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "floating-live",
3
- "version": "0.8.4",
3
+ "version": "0.8.6",
4
4
  "type": "commonjs",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -4,6 +4,7 @@ import LiveRoom from "../../src/types/room/LiveRoom";
4
4
  import AcClient from "acfun-live-danmaku/client";
5
5
  import { EventEmitter } from "events";
6
6
  import { LiveInfo } from "../../src/types/room/LiveInfo";
7
+ import { MessageType } from "../../src/types/message/MessageData";
7
8
  declare class acfunLive extends EventEmitter implements LiveRoom {
8
9
  /** 平台id */
9
10
  readonly platform: string;
@@ -68,7 +69,8 @@ declare class acfunLive extends EventEmitter implements LiveRoom {
68
69
  msg_LiveClosed(): void;
69
70
  msg_LiveBanned(): void;
70
71
  msg_DisplayInfo(data: any): void;
71
- emitMsg(data: any): void;
72
+ emitMsg(data: MessageType): void;
72
73
  emitOrigin(data: any): void;
74
+ emitChange(data: Partial<LiveInfo>): void;
73
75
  }
74
76
  export default acfunLive;
@@ -203,8 +203,8 @@ class acfunLive extends events_1.EventEmitter {
203
203
  status: "off"
204
204
  }
205
205
  };
206
- this.live.status = "off";
207
206
  this.client = null;
207
+ this.emit("change", { status: "off" });
208
208
  this.emitMsg(off);
209
209
  }
210
210
  msg_LiveBanned() {
@@ -217,8 +217,8 @@ class acfunLive extends events_1.EventEmitter {
217
217
  message: ""
218
218
  }
219
219
  };
220
- this.live.status = "off";
221
220
  this.client = null;
221
+ this.emit("change", { status: "off" });
222
222
  this.emitMsg(cut);
223
223
  }
224
224
  msg_DisplayInfo(data) {
@@ -232,5 +232,10 @@ class acfunLive extends events_1.EventEmitter {
232
232
  // 源消息
233
233
  this.emit("origin", data);
234
234
  }
235
+ emitChange(data) {
236
+ this.live = Object.assign(this.live, data);
237
+ // 直播信息
238
+ this.emit("change", data);
239
+ }
235
240
  }
236
241
  exports.default = acfunLive;
@@ -39,6 +39,7 @@ declare class bilibiliLive extends EventEmitter implements LiveRoom {
39
39
  destory(): void;
40
40
  emitMsg(data: any): void;
41
41
  emitOrigin(data: any): void;
42
+ emitChange(data: Partial<LiveInfo>): void;
42
43
  getDanmakuMode(n: number): string;
43
44
  /** 获取弹幕消息 */
44
45
  msg_DANMU_MSG(msg: any): void;
@@ -54,5 +55,6 @@ declare class bilibiliLive extends EventEmitter implements LiveRoom {
54
55
  msg_LIVE(msg: any): void;
55
56
  msg_CUT_OFF(msg: any): void;
56
57
  msg_PREPARING(msg: any): void;
58
+ msg_ROOM_CHANGE(msg: any): void;
57
59
  }
58
60
  export default bilibiliLive;
@@ -111,6 +111,7 @@ class bilibiliLive extends events_1.EventEmitter {
111
111
  client.on("CUT_OFF", this.msg_CUT_OFF.bind(this));
112
112
  client.on("PREPARING", this.msg_PREPARING.bind(this));
113
113
  client.on("LIVE", this.msg_LIVE.bind(this));
114
+ client.on("ROOM_CHANGE", this.msg_ROOM_CHANGE.bind(this));
114
115
  }
115
116
  close() {
116
117
  if (!this.opening)
@@ -131,6 +132,11 @@ class bilibiliLive extends events_1.EventEmitter {
131
132
  // 源消息
132
133
  this.emit("origin", data);
133
134
  }
135
+ emitChange(data) {
136
+ this.live = Object.assign(this.live, data);
137
+ // 直播信息
138
+ this.emit("change", data);
139
+ }
134
140
  getDanmakuMode(n) {
135
141
  switch (n) {
136
142
  case 1:
@@ -386,7 +392,7 @@ class bilibiliLive extends events_1.EventEmitter {
386
392
  start_time: msg.live_time * 1000,
387
393
  },
388
394
  };
389
- this.live.status = "live";
395
+ this.emitChange({ status: "live" });
390
396
  this.emitMsg(live);
391
397
  }
392
398
  }
@@ -401,7 +407,7 @@ class bilibiliLive extends events_1.EventEmitter {
401
407
  message: msg.msg,
402
408
  },
403
409
  };
404
- this.live.status = "off";
410
+ this.emitChange({ status: "off" });
405
411
  this.emitMsg(cut);
406
412
  }
407
413
  msg_PREPARING(msg) {
@@ -414,8 +420,21 @@ class bilibiliLive extends events_1.EventEmitter {
414
420
  status: msg.round ? "round" : "off"
415
421
  }
416
422
  };
417
- this.live.status = msg.round ? "round" : "off";
423
+ this.emitChange({ status: msg.round ? "round" : "off" });
418
424
  this.emitMsg(off);
419
425
  }
426
+ msg_ROOM_CHANGE(msg) {
427
+ let change = {
428
+ platform: "bilibili",
429
+ room: this.id,
430
+ type: "live_change",
431
+ info: {
432
+ title: msg.data.title,
433
+ area: [msg.data.parent_area_name, msg.data.area_name]
434
+ }
435
+ };
436
+ this.emitChange(change.info);
437
+ this.emitMsg(change);
438
+ }
420
439
  }
421
440
  exports.default = bilibiliLive;
@@ -21,7 +21,7 @@ declare class Room {
21
21
  /** 获取房间 */
22
22
  get(roomKey: string): LiveRoom | undefined;
23
23
  /** 获取房间信息 */
24
- getInfo(roomKey: string): import("../types/room/RoomInfo").default | undefined;
24
+ info(roomKey: string): import("../types/room/RoomInfo").default | undefined;
25
25
  /** 更新房间信息 */
26
26
  update(roomKey: string): void;
27
27
  /** 获取roomKey列表 */
@@ -52,9 +52,9 @@ class Room {
52
52
  room.on("info", () => {
53
53
  this.main.emit("room_info", key, (0, getRoomInfo_1.default)(room));
54
54
  });
55
- // 更新直播间信息
56
- room.on("update", (data) => {
57
- this.main.emit("room_update", key, data);
55
+ // 直播信息更改
56
+ room.on("change", (data) => {
57
+ this.main.emit("room_change", key, data);
58
58
  });
59
59
  // 房间被打开
60
60
  room.on("open", () => {
@@ -72,20 +72,20 @@ class Room {
72
72
  /** 移除房间 */
73
73
  remove(roomKey) {
74
74
  if (!this.roomMap.has(roomKey)) {
75
- this.main.emit("room", { key: "room_unexist", value: { key: roomKey } });
75
+ this.main.emit("room_unexist", roomKey);
76
76
  return;
77
77
  }
78
78
  let room = this.roomMap.get(roomKey);
79
79
  this.roomMap.delete(roomKey); // 从表中删除房间
80
80
  room?.removeAllListeners(); // 移除房间监听实例
81
- this.main.emit("room", { key: "room_remove", value: { key: roomKey } });
81
+ this.main.emit("room_remove", roomKey);
82
82
  }
83
83
  /** 获取房间 */
84
84
  get(roomKey) {
85
85
  return this.roomMap.get(roomKey);
86
86
  }
87
87
  /** 获取房间信息 */
88
- getInfo(roomKey) {
88
+ info(roomKey) {
89
89
  let room = this.roomMap.get(roomKey);
90
90
  return room ? (0, getRoomInfo_1.default)(room) : undefined;
91
91
  }