Simple-peer: Unable to destroy peer object

Created on 7 Apr 2020  路  7Comments  路  Source: feross/simple-peer

I have a peer object defined as var peer = new Peer()

Calling peer.destroy() leads to the error:

ReferenceError:
process is not defined
at emitReadable (_stream_readable.js:529)
at onEofChunk (_stream_readable.js:506)
at readableAddChunk (_stream_readable.js:255)
at Peer.push../node_modules/simple-peer/node_modules/readable-stream/lib/_stream_readable.js.Readable.push (_stream_readable.js:241)
at Peer._destroy (index.js:408)
at Peer.destroy (index.js:398)
at Socket. (sender.component.ts:88)
at Socket.push../node_modules/ngx-socket-io/node_modules/component-emitter/index.js.Emitter.emit (index.js:133)
at Socket.push../node_modules/ngx-socket-io/node_modules/socket.io-client/lib/socket.js.Socket.onevent (socket.js:278)
at Socket.push../node_modules/ngx-socket-io/node_modules/socket.io-client/lib/socket.js.Socket.onpacket (socket.js:23).

What I'm trying to achieve is if a remote client refreshes the browser, I want all other clients to destroy the connection to that remote client.

need more info question

Most helpful comment

It works! Thank you.

For simple-peer to work correctly in angular you need some polyfills.
Add this to your polyfills.ts file:

import * as process from 'process';

(window as any).global = window;
(window as any).process = process;
(window as any).Buffer = [];

And install this package: https://www.npmjs.com/package/process

All 7 comments

How do you get simple-peer on the page? I think there is something wrong the way bundling is configured in your app. You need to either use browserify or configure your bundles correctly or just use pre-built simplepeer.min.js.

I'm using Angular typescript, hence:

import * as Peer from 'simple-peer'.

I'm able to get the connections and streams across peers, but just unable to destroy them.

For simple-peer to work correctly in angular you need some polyfills.
Add this to your polyfills.ts file:

import * as process from 'process';

(window as any).global = window;
(window as any).process = process;
(window as any).Buffer = [];

And install this package: https://www.npmjs.com/package/process

It works! Thank you.

For simple-peer to work correctly in angular you need some polyfills.
Add this to your polyfills.ts file:

import * as process from 'process';

(window as any).global = window;
(window as any).process = process;
(window as any).Buffer = [];

And install this package: https://www.npmjs.com/package/process

I thought the object was destroyed but came across #553 and realized that this was happening instead. I closed one client without destorying the peer object and 2 errors popped out after about 15s:

  1. Uncaught Error: Connecton failed.
  2. Uncaught TypeError: Cannot read property '_readableState' of undefined.

_readableState is a property on this, maybe you're storing peer.destroy and not peer.destroy.bind(peer) somewhere?

Turns out I didn't install process correctly... problem was resolved after installing the correct package.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

saagarbethi picture saagarbethi  路  4Comments

Applicafroguy picture Applicafroguy  路  3Comments

idlatest picture idlatest  路  4Comments

mullerivan picture mullerivan  路  4Comments

jimmywarting picture jimmywarting  路  3Comments