我正在开发电子/Angular 13应用程序
我有以下功能:
async handleStop(e: any) {
const blob = new Blob(this.recordChunks, {
type: 'video/webm; codecs=vp9'
});
const buffer = Buffer.from(await blob.arrayBuffer());
console.log(buffer)
this._electronService.ipcRenderer.send('stop-recording', buffer);
}
我将其用作回调函数,如下所示:
async onSourceSelected(displayId: string) {
let constraints = {
audio: false,
video: {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: displayId
}
}
};
// CREATE A STREAM
let stream = await (navigator.mediaDevices as any).getUserMedia(constraints);
// Create the media Recorder
const options = { mimeType: 'video/webm; codecs=vp9' };
this.mediaRecorder = new MediaRecorder(stream, options);
// Register event handler
this.mediaRecorder.ondataavailable = this.handleDataAvailable;
this.mediaRecorder.onstop = this.handleStop;
};
组件的构造函数:
constructor(private dialogRef: DialogRef, @Inject(DIALOG_DATA) public data: any, private _electronService: ElectronApiServiceService, private zone: NgZone, private dialog: DialogService) { }
“_electronService”是一个注入到组件构造函数中的Angular服务。当调用“handleStop”方法时,我在控制台中得到以下错误:
“未处理的承诺拒绝:无法读取未定义的属性(阅读“ipcRenderer”);区域:;任务:答应吧。值:类型错误:无法读取未定义的属性(阅读'ipcRenderer')”
1条答案
按热度按时间uyhoqukh1#
需要显式地将事件处理程序绑定到
this
。当您将handleStop
赋值给onstop
时,它会丢失上下文,因此handleStop
函数中的this
不会引用对象本身。