message: add support for dynamic encodings, add encoding getters and missing isAttached
diff: @@ -36,17 +36,8 @@ class IncomingStreamTrackMirrored
  //Create source map
  this.encodings = new Map();
  - //Get number of encodings
  - const num = Object.keys(incomingStreamTrack.encodings).length;
  -
  - //If multiple sources
  - if (num > 1)
  - //Create a simulcast frame listerner
  - this.depacketizer = new Native.SimulcastMediaFrameListener(1, num);
  -
  - //For each encoding in the original track
  - for (let encoding of incomingStreamTrack.encodings.values())
  - {
  + //Internal function for adding a new mirrored encoding to the track
  + const addEncoding = (encoding) => {
  //Create mirrored source
  const source = new Native.RTPIncomingMediaStreamMultiplexer(encoding.source.media.ssrc, timeService);
  @@ -55,6 +46,7 @@ class IncomingStreamTrackMirrored
  id : encoding.id,
  source : source,
  mirror : encoding.source,
  + receiver : encoding.receiver,
  depacketizer : new Native.RTPIncomingMediaStreamDepacketizer(source)
  };
  @@ -63,17 +55,18 @@ class IncomingStreamTrackMirrored
  //Push new encoding
  this.encodings.set(mirrored.id, mirrored);
  -
  - //If multiple encodings
  - if (this.depacketizer)
  - //Make the simulcast depacketizer listen for this
  - mirrored.depacketizer.AddMediaListener(this.depacketizer);
  }
  - //If there is no depacketizer
  - if (!this.depacketizer)
  - //This is the single depaquetizer, so reause it
  - this.depacketizer = this.encodings.values().next().value.depacketizer;
  + //For each encoding in the original track
  + for (let encoding of incomingStreamTrack.encodings.values())
  + //Add new encoding
  + addEncoding(encoding);
  +
  + //LIsten for new encodings
  + incomingStreamTrack.on("encoding",(incomingStreamTrack,encoding) => {
  + //Add new encoding
  + addEncoding(encoding);
  + });
  //Create event emitter
  this.emitter = new EventEmitter();
  @@ -182,6 +175,45 @@ class IncomingStreamTrackMirrored
  return this;
  }
  + /**
  + * Get all track encodings
  + * Internal use, you'd beter know what you are doing before calling this method
  + * @returns {Array<Object>} - encodings
  + **/
  + getEncodings()
  + {
  + return Array.from(this.encodings.values());
  + }
  +
  + /**
  + * Get encoding by id
  + * Internal use, you'd beter know what you are doing before calling this method
  + * @param {String} encodingId - encoding Id,
  + * @returns {Object} - encoding
  + **/
  + getEncoding(encodingId)
  + {
  + return this.encodings.get(encodingId);
  + }
  +
  + /**
  + * Get default encoding
  + * Internal use, you'd beter know what you are doing before calling this method
  + * @returns {Object} - encoding
  + **/
  + getDefaultEncoding()
  + {
  + return this.encodings.values().next().value;
  + }
  +
  + /**
  + * Return if the track is attached or not
  + */
  + isAttached()
  + {
  + return this.counter>0;
  + }
  +
  /**
  * Signal that this track has been attached.
  * Internal use, you'd beter know what you are doing before calling this method
  