message: add support for dynamic encodings and use track getters
diff: @@ -40,6 +40,21 @@ class Transponder
  //No encoding
  this.encodingId = null;
  };
  + //Listener for when new encodings become avialable
  + this.onAttachedTrackEncoding = (incomingStreamTrack,encoding) => {
  + //If we don't have an encoding yet
  + if (this.track === incomingStreamTrack && (!this.encodingId || this.encodingId == encoding.id))
  + {
  + //Start listening to the encoding
  + this.select({
  + encodingId : encoding.id,
  + spatialLayerId : this.spatialLayerId,
  + temporalLayerId : this.temporalLayerId,
  + maxSpatialLayerId : this.maxSpatialLayerId,
  + maxTemporalLayerId : this.maxTemporalLayerId
  + });
  + }
  + };
  //Create event emitter
  this.emitter = new EventEmitter();
  @@ -71,8 +86,9 @@ class Transponder
  //If was previously attached
  if (this.track)
  {
  - //Remove stop listener
  + //Remove listeners listener
  this.track.off("stopped", this.onAttachedTrackStopped);
  + this.track.off("encoding",this.onAttachedTrackEncoding);
  //Signal dettached
  this.track.detached();
  }
  @@ -83,15 +99,36 @@ class Transponder
  //If removing track
  if (this.track)
  {
  + //Get default encoding
  + const defaultencoding = this.track.getDefaultEncoding();
  +
  + //IF the track has any encodings
  + if (defaultencoding) {
  //Set defaults
  const curated = Object.assign({
  - encodingId : this.track.encodings.values().next().value.id,
  + encodingId : defaultencoding.id,
  },layers);
  - //Start listening to the encoding
  + //Start listening to the default encoding
  this.select(curated);
  + } else {
  + //Set defaults
  + const curated = Object.assign({
  + spatialLayerId : LayerInfo.MaxLayerId,
  + temporalLayerId : LayerInfo.MaxLayerId,
  + maxSpatialLayerId : LayerInfo.MaxLayerId,
  + maxTemporalLayerId : LayerInfo.MaxLayerId
  + }, layers);
  +
  + //Store default values
  + this.encodingId = curated.encodingId;
  + this.setMaximumLayers(curated.maxSpatialLayerId,curated.maxTemporalLayerId)
  + this.spatialLayerId = curated.spatialLayerId;
  + this.temporalLayerId = curated.temporalLayerId;
  + }
  - //Add stop listener
  + //Add listeners
  + this.track.on("encoding",this.onAttachedTrackEncoding);
  this.track.once("stopped",this.onAttachedTrackStopped);
  //Singal track is attached
  @@ -377,13 +414,13 @@ class Transponder
  //Do nothing
  return;
  //Get encoding
  - const encoding = this.track.encodings.get(encodingId);
  + const encoding = this.track.getEncoding(encodingId);
  //If not found
  if (!encoding)
  //Error
  throw new Error("Encoding id ["+encodingId+"] not found on transpoder track");
  //Start listening to it
  - this.transponder.SetIncoming(encoding.source,this.track.receiver);
  + this.transponder.SetIncoming(encoding.source,encoding.receiver);
  //store encoding
  this.encodingId = encodingId;
  }
  