1

我正在simple-peer使用angular 7

async ngOnInit() {
    try {
      if (location.hash === '#init') {
        this.peer = new SimplePeer({
          initiator: location.hash === '#init'
        })
      }
      else {
        this.peer = new SimplePeer()
      }

      this.peer.on('signal', function (data) {
        console.log(JSON.stringify(data));
      })

      this.peer.on('data', (data) => {
        console.log('Received Data: ' + data)
      })
    } catch (error) {
      console.log(error)
    }
  }

当 Angular 编译器出现此事件时

this.peer.on('data', (data) => {
     console.log('Received Data: ' + data)
})

然后它抛出错误

在此处输入图像描述

当我省略这个时,event这个错误就消失了

注意:包版本为

  1. simple-peer v9.1.2
  2. NPM v6.5.0
  3. Node v10.14.2
4

1 回答 1

4

完全相同的问题解决了:

npm i -S process, then add this to polyfill.ts:
import * as process from 'process';
window['process'] = process;

也可以安装:

npm i -S process-nextick-args
于 2019-03-02T13:38:18.200 回答