Import JS into Angular getting 'is not defined' message

219 Views Asked by At

I'm trying to implement a Livestream using AntMedia, so I have this Angular 10 project where I need to import the webrtc_adaptor.js.

My webrtc_adaptor.js start like this:

function WebRTCAdaptor(initialValues)
{
   class PeerStats {

    constructor(streamId) {
     this.streamId = streamId;
     this.totalBytesReceivedCount = 0;
     this.totalBytesSent = 0;
     this.packetsLost = 0;
     this.fractionLost = 0;
     this.startTime = 0;
     this.lastBytesReceived = 0;
     this.lastBytesSent = 0;
     this.currentTimestamp = 0;
     this.lastTime = 0;
     this.timerId = 0;
     this.firstByteSentCount = 0;
     this.firstBytesReceivedCount = 0;
     this.audioLevel = -1;
    }
 }

To import that I added it to my angular.json the following line:

        "scripts": [
          "src/main/webapp/app/entities/master/livestream/video/webrtc_adaptor.js"
        ]

In my Angular component I added:

declare let WebRTCAdaptor: any;

And in my class, I added:

webRTCAdaptor: any;

this.webRTCAdaptor = new WebRTCAdaptor({
  websocket_url : "wss://your_server_url:5443/WebRTCAppEE/websocket",
  mediaConstraints : mediaConstraints,
  peerconnection_config : pc_config,
  sdp_constraints : sdpConstraints,
  remoteVideoId : "remoteVideo",
  isPlayMode: true,
  debug: true,
  callback : function(info, description)
});

I based myself on the AntMedia manual to do that, and after all I'm still getting the following error:

  ERROR ReferenceError: WebRTCAdaptor is not defined
   at VideoComponent.startLive (video.component.ts?a313:85)
   at VideoComponent.onSuccess (video.component.ts?a313:110)
   at SafeSubscriber.eval [as _next] (video.component.ts?a313:78)
   at SafeSubscriber.__tryOrUnsub (Subscriber.js?ee8f:183)
   at SafeSubscriber.next (Subscriber.js?ee8f:122)
   at Subscriber._next (Subscriber.js?ee8f:72)
   at Subscriber.next (Subscriber.js?ee8f:49)
   at MapSubscriber._next (map.js?949c:35)
   at MapSubscriber.next (Subscriber.js?ee8f:49)
   at FilterSubscriber._next (filter.js?a4b6:33)

Can someone help me to spot what I'm doing wrong?

Thank's.

0

There are 0 best solutions below