'How to implement Node-Media-Server in Nestjs?

I try to implement a RMTP server in Nestjs thanks to Node-Media-Server, have any of you ever managed to do something like this?

I naively tried to run this little piece of code inside a function in a service, but it doesn't work, I have this error when the function is executed :

node_media_server_1.default is not a constructor

broadcast.service.ts

import { Injectable } from '@nestjs/common';
import NodeMediaServer from 'node-media-server';

@Injectable()
export class BroadcastService {
  private config = {
    rtmp: {
      port: 1935,
      chunk_size: 60000,
      gop_cache: true,
      ping: 30,
      ping_timeout: 60,
    },
    http: {
      mediaroot: '',
      port: 8000,
      allow_origin: '*',
    },
  };
  create() {
    const nodeMediaServer = new NodeMediaServer(this.config);
    nodeMediaServer.run();
    return 'This action adds a new broadcast';
  }
}

Maybe for this kind of task with nestjs, I shouldn't do it this way? If a nestjs pro could enlighten me on this subject I would be really delighted



Solution 1:[1]

Instead of import NodeMediaServer from 'node-media-server'; use like this

const NodeMediaServer = require('node-media-server');

Or

import * as NodeMediaServer from 'node-media-server';

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1