简体   繁体   中英

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

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';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM