0

I am connecting to peer.js and then assigning a property with the returned value. Currently I am using a timeout, but I was wondering if there is a way to just assign the property the value when it has been returned? Kind of how observables work.

this.peer = new Peer({ key: 'mykey' });
setTimeout(() => {
  this.myId = this.peer.id;
}, 3000);
4

1 回答 1

1

像这样使用 on open 事件

var peer = new Peer({ key: 'mykey' });
peer.on('open', function(id) {
  console.log('The ID is: ' + id);
});
于 2016-10-22T15:52:18.033 回答