@bililive-tools/huya-recorder 1.16.0 → 1.17.0

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.
Files changed (2) hide show
  1. package/lib/index.js +20 -8
  2. package/package.json +3 -3
package/lib/index.js CHANGED
@@ -13,6 +13,7 @@ function createRecorder(opts) {
13
13
  ...mitt(),
14
14
  ...opts,
15
15
  cache: null,
16
+ appendTimeline: null,
16
17
  availableStreams: [],
17
18
  availableSources: [],
18
19
  qualityRetry: opts.qualityRetry ?? 0,
@@ -71,10 +72,13 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
71
72
  try {
72
73
  const liveInfo = await getInfo(this.channelId);
73
74
  this.liveInfo = liveInfo;
74
- this.state = "idle";
75
+ this.emit("stateChange", { state: "idle" });
75
76
  }
76
77
  catch (error) {
77
- this.state = "check-error";
78
+ this.emit("stateChange", {
79
+ state: "check-error",
80
+ msg: `检查失败,` + (error instanceof Error ? error.message : String(error)),
81
+ });
78
82
  throw error;
79
83
  }
80
84
  const { living, owner, title, liveStartTime, recordStartTime } = this.liveInfo;
@@ -108,10 +112,13 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
108
112
  catch (err) {
109
113
  if (qualityRetryLeft > 0)
110
114
  await this.cache.set("qualityRetryLeft", qualityRetryLeft - 1);
111
- this.state = "check-error";
115
+ this.emit("stateChange", {
116
+ state: "check-error",
117
+ msg: `检查失败,` + (err instanceof Error ? err.message : String(err)),
118
+ });
112
119
  throw err;
113
120
  }
114
- this.state = "recording";
121
+ this.emit("stateChange", { state: "recording" });
115
122
  const { currentStream: stream, sources: availableSources, streams: availableStreams } = res;
116
123
  this.availableStreams = availableStreams.map((s) => s.desc);
117
124
  this.availableSources = availableSources.map((s) => s.name);
@@ -153,6 +160,7 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
153
160
  headers: {
154
161
  "User-Agent": stream.ua,
155
162
  },
163
+ proxy: this.proxy,
156
164
  }, onEnd, async () => {
157
165
  const info = await getInfo(this.channelId);
158
166
  return info;
@@ -176,8 +184,8 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
176
184
  });
177
185
  };
178
186
  downloader.on("videoFileCreated", handleVideoCreated);
179
- downloader.on("videoFileCompleted", ({ filename }) => {
180
- this.emit("videoFileCompleted", { filename });
187
+ downloader.on("videoFileCompleted", (data) => {
188
+ this.emit("videoFileCompleted", data);
181
189
  });
182
190
  downloader.on("DebugLog", (data) => {
183
191
  this.emit("DebugLog", data);
@@ -241,7 +249,11 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
241
249
  client.on("error", (e) => {
242
250
  this.emit("DebugLog", { type: "common", text: String(e) });
243
251
  });
252
+ client.on("connect", () => {
253
+ this.appendTimeline({ text: `弹幕连接已建立` });
254
+ });
244
255
  client.on("retry", (e) => {
256
+ this.appendTimeline({ text: `弹幕连接断开,正在重试: ${e.count}/${e.max}` });
245
257
  this.emit("DebugLog", {
246
258
  type: "common",
247
259
  text: `${this?.liveInfo?.owner}:${this.channelId} huya danmu retry: ${e.count}/${e.max}`,
@@ -259,7 +271,7 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
259
271
  const stop = utils.singleton(async (reason) => {
260
272
  if (!this.recordHandle)
261
273
  return;
262
- this.state = "stopping-record";
274
+ this.emit("stateChange", { state: "stopping-record" });
263
275
  try {
264
276
  client?.stop();
265
277
  await downloader.stop();
@@ -275,7 +287,7 @@ const checkLiveStatusAndRecord = async function ({ getSavePath, banLiveId, isMan
275
287
  this.emit("RecordStop", { recordHandle: this.recordHandle, reason });
276
288
  this.recordHandle = undefined;
277
289
  this.liveInfo = undefined;
278
- this.state = "idle";
290
+ this.emit("stateChange", { state: "idle" });
279
291
  this.cache.set("qualityRetryLeft", this.qualityRetry);
280
292
  });
281
293
  this.recordHandle = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bililive-tools/huya-recorder",
3
- "version": "1.16.0",
3
+ "version": "1.17.0",
4
4
  "description": "bililive-tools huya recorder implemention",
5
5
  "main": "./lib/index.js",
6
6
  "type": "module",
@@ -38,8 +38,8 @@
38
38
  "axios": "^1.15.0",
39
39
  "lodash-es": "^4.17.21",
40
40
  "mitt": "^3.0.1",
41
- "huya-danma-listener": "0.1.4",
42
- "@bililive-tools/manager": "^1.16.0"
41
+ "@bililive-tools/manager": "^1.17.0",
42
+ "huya-danma-listener": "0.1.4"
43
43
  },
44
44
  "scripts": {
45
45
  "build": "tsc",