message: Manage created transports inside PeerConnectionServer
diff: @@ -33,6 +33,9 @@ class PeerConnectionServer
  this.capabilities = capabilities;
  this.tm = tm;
  + //The created transports
  + this.transports = new Set();
  +
  //Create event emitter
  this.emitter = new EventEmitter();
  @@ -49,6 +52,7 @@ class PeerConnectionServer
  var offer = SDPInfo.expand(cmd.data);
  //Create an DTLS ICE transport in that enpoint
  const transport = this.endpoint.createTransport(offer);
  +
  //Set RTP remote properties
  transport.setRemoteProperties(offer);
  @@ -103,6 +107,8 @@ class PeerConnectionServer
  });
  }
  }).on("stopped",()=>{
  + //Remove from transports
  + this.transports.delete(transport);
  //Send enven
  pcns.event("stopped");
  //Close ns
  @@ -110,6 +116,9 @@ class PeerConnectionServer
  });
  + //Add to transport
  + this.transports.add(transport);
  +
  //Listen remote events
  pcns.on("event",(event)=>{
  //Get event data
  @@ -188,7 +197,7 @@ class PeerConnectionServer
  });
  //Stop when endpoint stop
  - this.endpoint.on("stopped",()=>this.stop());
  + this.endpoint.once("stopped",this.onendpointstopped=()=>this.stop());
  }
  /**
  @@ -238,6 +247,19 @@ class PeerConnectionServer
  */
  stop()
  {
  + //Chheck not stopped alrady
  + if (!this.endoint)
  + //Do nothing
  + return;
  +
  + //Don't listen for stopped event
  + this.endpoint.off("stopped",this.onendpointstopped);
  +
  + //For all transports
  + for (const transport of this.transports)
  + //Stop them
  + transport.close();
  +
  //Close ns
  this.ns.close();
  @@ -252,6 +274,7 @@ class PeerConnectionServer
  this.emitter.emit("stopped",this);
  //Null
  + this.transports = null;
  this.emitter = null;
  this.ns = null;
  this.endpoint = null;
  