I have an angular library written in v15 with recordRTC v5.6.2 package. I am trying to use recordRTC inside a service but it gives a typeError that does not occurs in a regular angular project (not a library). My service is:
import { Injectable } from '@angular/core';
import * as RecordRTC from 'recordrtc';
@Injectable({
providedIn: 'root'
})
export class RecorderService {
private stream: MediaStream;
private recorder;
constructor() { }
public initializeRecorder(): Promise<boolean> {
return navigator.mediaDevices.getUserMedia({
audio: true,
video: false,
}).then(async (stream) => {
this.stream = stream;
this.recorder = new RecordRTC(stream, {
type: 'audio'
});
this.recorder.startRecording();
return true;
}).catch(err => {
console.log('error initializing recorder ----> ', err);
return false;
});
}
}
And when i try to run the "initializeRecorder" method it falls to my catch block giving the error:
TypeError: (recordrtc__WEBPACK_IMPORTED_MODULE_1___namespace_cache || recordrtc__WEBPACK_IMPORTED_MODULE_1___namespace_cache) is not a constructor
The same code snippet when i run it at a regular angular 15 project works normally, but inside the angular library it does not work.
In my opinion, you did not install and import correctly. To install and use this library, whether, for audio or video, you can follow these two links:
1- Audio Recording using Record RTC: link.
and
2- RecordRTC Video Recording with Angular: link.