eedatek-electron-screenrecord 2.1.3 → 2.1.5

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/lib/index.d.ts CHANGED
@@ -34,6 +34,7 @@ export default class ScreenRecord extends Events {
34
34
  private isRecording;
35
35
  private mouseMoveListener;
36
36
  private scaleFactor;
37
+ private sourceId;
37
38
  constructor(opts?: ScreenRecordOpts);
38
39
  updateButtonBounds(bounds: {
39
40
  x: number;
package/lib/index.js CHANGED
@@ -45,6 +45,7 @@ class ScreenRecord extends events_1.default {
45
45
  isRecording = false;
46
46
  mouseMoveListener = null;
47
47
  scaleFactor = 1;
48
+ sourceId = "";
48
49
  constructor(opts) {
49
50
  super();
50
51
  this.logger = opts?.logger || (0, debug_1.default)("electron-screenshots");
@@ -55,6 +56,7 @@ class ScreenRecord extends events_1.default {
55
56
  //更新开始、结束录屏按钮区域
56
57
  updateButtonBounds(bounds) {
57
58
  this.logger(`updateButtonBounds x:${bounds.x} y:${bounds.y} w:${bounds.width} h:${bounds.height}`);
59
+ this.isRecording = true;
58
60
  this.buttonBounds = bounds;
59
61
  }
60
62
  startMouseTracking() {
@@ -67,6 +69,7 @@ class ScreenRecord extends events_1.default {
67
69
  // const mousePos = screen.getCursorScreenPoint();
68
70
  const mousePos = robot.getMousePos();
69
71
  const winBounds = this.$win?.getBounds();
72
+ // console.log(`mousePos: x:${mousePos.x} y: ${mousePos.y}`);
70
73
  // 计算鼠标是否在按钮区域内
71
74
  const isInButtonArea = this.isMouseInButtonArea(mousePos, winBounds);
72
75
  if (isInButtonArea) {
@@ -107,6 +110,7 @@ class ScreenRecord extends events_1.default {
107
110
  */
108
111
  async startCapture() {
109
112
  this.logger("startCapture");
113
+ this.reset();
110
114
  const display = (0, getDisplay_1.default)();
111
115
  //全屏的截图base64
112
116
  const [imageUrl] = await Promise.all([this.capture(display)]);
@@ -231,6 +235,7 @@ class ScreenRecord extends events_1.default {
231
235
  // })
232
236
  this.$win.on("closed", () => {
233
237
  this.emit("windowClosed", this.$win);
238
+ this.isRecording = false;
234
239
  this.$win = null;
235
240
  this.stopMouseTracking();
236
241
  });
@@ -282,36 +287,8 @@ class ScreenRecord extends events_1.default {
282
287
  this.logger("SCREENRECORD:capture Can't find screen source. sources: %o, display: %o", sources, display);
283
288
  throw new Error("Can't find screen source");
284
289
  }
290
+ this.sourceId = source.id;
285
291
  return source.thumbnail.toDataURL();
286
- // const { Screenshots: NodeScreenshots } = await import('node-screenshots');
287
- // const capturer = NodeScreenshots.fromPoint(
288
- // display.x + display.width / 2,
289
- // display.y + display.height / 2,
290
- // );
291
- // this.logger(
292
- // 'SCREENRECORD:capture NodeScreenshots.fromPoint arguments %o',
293
- // display,
294
- // );
295
- // this.logger(
296
- // 'SCREENRECORD:capture NodeScreenshots.fromPoint return %o',
297
- // capturer
298
- // ? {
299
- // id: capturer.id,
300
- // x: capturer.x,
301
- // y: capturer.y,
302
- // width: capturer.width,
303
- // height: capturer.height,
304
- // rotation: capturer.rotation,
305
- // scaleFactor: capturer.scaleFactor,
306
- // isPrimary: capturer.isPrimary,
307
- // }
308
- // : null,
309
- // );
310
- // if (!capturer) {
311
- // throw new Error(`NodeScreenshots.fromDisplay(${display.id}) get null`);
312
- // }
313
- // const image = await capturer.capture();
314
- // return `data:image/png;base64,${image.toString('base64')}`;
315
292
  }
316
293
  catch (err) {
317
294
  this.logger("SCREENRECORD:capture NodeScreenshots capture() error %o", err);
@@ -337,6 +314,7 @@ class ScreenRecord extends events_1.default {
337
314
  this.logger("SCREENRECORD:capture Can't find screen source. sources: %o, display: %o", sources, display);
338
315
  throw new Error("Can't find screen source");
339
316
  }
317
+ this.sourceId = source.id;
340
318
  return source.thumbnail.toDataURL();
341
319
  }
342
320
  }
@@ -355,7 +333,6 @@ class ScreenRecord extends events_1.default {
355
333
  this.logger("callback SCREENRECORD:ok");
356
334
  this.$win?.setIgnoreMouseEvents(true, { forward: true });
357
335
  if (process.platform !== "win32") {
358
- this.isRecording = true;
359
336
  this.startMouseTracking();
360
337
  }
361
338
  });
@@ -370,7 +347,6 @@ class ScreenRecord extends events_1.default {
370
347
  * CANCEL事件
371
348
  */
372
349
  electron_1.ipcMain.on("SCREENRECORD:cancel", () => {
373
- this.isRecording = false;
374
350
  this.logger("callback SCREENRECORD:cancel");
375
351
  this.$win?.setIgnoreMouseEvents(false);
376
352
  if (process.platform !== "win32") {
@@ -411,10 +387,20 @@ class ScreenRecord extends events_1.default {
411
387
  this.updateButtonBounds(data);
412
388
  });
413
389
  electron_1.ipcMain.handle("SCREENRECORD:get-desktop-capturer-source", async () => {
414
- return [
390
+ const sources = [
415
391
  ...(await electron_1.desktopCapturer.getSources({ types: ["screen", "window"] })),
416
392
  ...(await selfWindws()),
417
393
  ];
394
+ if (sources.length > 0) {
395
+ sources.forEach((source) => {
396
+ this.logger("sources name" + source.name + " id:" + source.id);
397
+ });
398
+ }
399
+ return sources;
400
+ });
401
+ electron_1.ipcMain.handle("SCREENRECORD:get-desktop-capturer-source-id", async () => {
402
+ this.logger("sources id:" + this.sourceId);
403
+ return this.sourceId;
418
404
  });
419
405
  electron_1.ipcMain.handle("SCREENRECORD:get-display-nearest-point", async () => {
420
406
  if (this.$win) {
package/lib/preload.js CHANGED
@@ -53,6 +53,9 @@ electron_1.contextBridge.exposeInMainWorld('screenshots', {
53
53
  invokeGetDesktopCapturerSource: () => {
54
54
  return electron_1.ipcRenderer.invoke('SCREENRECORD:get-desktop-capturer-source');
55
55
  },
56
+ invokeGetDesktopCapturerSourceId: () => {
57
+ return electron_1.ipcRenderer.invoke('SCREENRECORD:get-desktop-capturer-source-id');
58
+ },
56
59
  invokeGetDisplayNearestPoint: () => {
57
60
  return electron_1.ipcRenderer.invoke('SCREENRECORD:get-display-nearest-point');
58
61
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eedatek-electron-screenrecord",
3
- "version": "2.1.3",
3
+ "version": "2.1.5",
4
4
  "description": "electron 录屏插件",
5
5
  "types": "lib/index.d.ts",
6
6
  "main": "lib/index.cjs.js",
@@ -34,7 +34,7 @@
34
34
  "dependencies": {
35
35
  "@jitsi/robotjs": "0.6.18",
36
36
  "debug": "^4.3.4",
37
- "eedatek-react-screenrecord": "^2.0.9",
37
+ "eedatek-react-screenrecord": "^2.1.5",
38
38
  "fs-extra": "^11.1.1"
39
39
  },
40
40
  "peerDependencies": {