Producer
ProducerOptions
Field Type Description Required Default kind MediaKind 媒体类型audio或者video Yes rtpParameters RtpSendParameters 发送端的rtp参数,produce出来的类型 Yes paused Boolean start之后,end端,建议先pause,等待resume,建议给true,后续跟进需要resume No false keyFrameRequestDelay Number video才有.询问key frame的间隔 No 0 appData Object Custom application data. No {}
ProducerScore
Field Type Description Required Default encodingIdx Number Producer rtpParams array index Yes ssrc Number RTP stream SSRC. Yes rid String RTP stream RID value. No score Number RTP stream score (from 0 to 10) representing the transmission quality. Yes
ProducerVideoOrientation
Field Type Description Required Default camera Boolean 摄像头数据源 Yes flip Boolean 视频资源是否被翻转 Yes rotation Number 旋转0,80,180,270度 Yes
ProducerTraceEventData
Field Type Description Required Default type ProducerTraceEventType Trace event type. Yes timestamp Number Event timestamp. Yes direction String “in” (icoming direction) or “out” (outgoing direction). Yes info Object Per type specific information. Yes
Enums
ProducerType
Value Description “simple” A single RTP stream is received with no spatial/temporal layers. “simulcast” Two or more RTP streams are received, each of them with one or more temporal layers. “svc” A single RTP stream is received with spatial/temporal layers.
ProducerTraceEventType
Value Description “rtp” RTP packet. “keyframe” RTP video keyframe packet. “nack” RTCP NACK packet. “pli” RTCP PLI packet. “fir” RTCP FIR packet.
Properties
producer.id producer.closed producer.kind producer.rtpParameters producer.type // single,simulcast, svc ? producer.paused // resume 最好先判断确认,使用该域 producer.score // 表示的实际是传输的质量 producer.appData producer.observer
Methods
producer.close() // 触发 producerclose 事件 producer.getStats() producer.pause() producer.resume() producer.enableTraceEvent(types)
Events
producer.on(“transportclose”, fn()) producer.on(“score”, fn(score)) // SCORE 发生变化 producer.on(“videoorientationchange”, fn(videoOrientation)) // urn:3gpp:video-orientation,该选项如果被协商设置,那么才会触发该事件。主要针对的是摄像头设备被旋转了的情况 producer.on(“trace”, fn(trace))
producer.observer.on(“close”, fn()) producer.observer.on(“pause”, fn()) producer.observer.on(“resume”, fn()) producer.observer.on(“score”, fn(score)) producer.observer.on(“videoorientationchange”, fn(videoOrientation)) producer.observer.on(“trace”, fn(trace))
Consumer
ConsumerOptions
Field Type Description Required Default producerId String The id of the producer to consume. Yes rtpCapabilities RtpCapabilities RTP capabilities of the consuming endpoint. Yes paused Boolean pause模式启动,详见下面Note. No false preferredLayers ConsumerLayers Preferred spatial and temporal layer for simulcast or SVC media sources. If unset, the highest ones are selected. No appData Object Custom application data. No { }
Note: 建议先 pause 启动,根据需要 resume。
ConsumerLayers
Field Type Description Required Default spatialLayer Number The spatial layer index (from 0 to N). Yes temporalLayer Number The temporal layer index (from 0 to N). No
ConsumerScore
Field Type Description Required Default score Number Score of the RTP stream in the consumer (from 0 to 10) representing its transmission quality. Yes producerScore Number Score of the currently selected RTP stream in the associated producer (from 0 to 10) representing its transmission quality. Yes producerScores Array 单producer多RTP流,仅适用于Sulmcast场景 Yes
ConsumerTraceEventData
Field Type Description Required Default type ConsumerTraceEventType Trace event type. Yes timestamp Number Event timestamp. Yes direction String “in” (icoming direction) or “out” (outgoing direction). Yes info Object Per type specific information. Yes
Enums
ConsumerType
Value Description “simple” A single RTP stream is sent with no spatial/temporal layers. “simulcast” Two or more RTP streams are sent, each of them with one or more temporal layers. “svc” A single RTP stream is sent with spatial/temporal layers. “pipe” Special type for consumers created on a PipeTransport.
ConsumerTraceEventType
Value Description “rtp” RTP packet. “keyframe” RTP video keyframe packet. “nack” RTCP NACK packet. “pli” RTCP PLI packet. “fir” RTCP FIR packet.
Properties
consumer. id consumer.producerId consumer.closed consumer.kind consumer.rtpParameters consumer.type consumer.paused consumer.producerPaused consumer.preferredLayers consumer.currentLayers // simulcast and SVC 模式下使用 consumer.priority // 见 Method setPriority() consumer.appData consumer.observer
Methods
consumer.close() consumer.getStats() consumer.pause() // if paused, no RTP will be sent to the consuming endpoint consumer.resume() consumer.setPreferredLayers(preferredLayers) consumer.setPriority(priority) // priority 会影响到transport中outgoing bitrate 在其他所有consumer中的分发:重新按照 priority 分排。 // 该选项只会在 该transport 中的outgoing bitrate评估不够的情况下,才会生效,按照priority分发。 consumer.unsetPriority() consumer.requestKeyFrame() // just for video consumer.enableTraceEvent(types)
Events
consumer.on(“transportclose”, fn()) consumer.on(“producerclose”, fn()) consumer.on(“producerpause”, fn()) consumer.on(“producerresume”, fn()) consumer.on(“score”, fn(score)) consumer.on(“layerschange”, fn(layers)) consumer.on(“trace”, fn(trace))
consumer.observer.on(“close”, fn()) consumer.observer.on(“pause”, fn()) consumer.observer.on(“resume”, fn()) consumer.observer.on(“score”, fn(score)) consumer.observer.on(“layerschange”, fn(layers)) consumer.observer.on(“trace”, fn(trace))
DataProducer & DataConsumer
基于 SCTP 或者 direct 方式的 producer & consumer
DataProducerOptions
Field Type Description Required Default sctpStreamParameters SctpStreamParameters 不能用于DirectTransport中,确认如果使用SCTP/DataChannel,给定该参数 No label String DataChannel标识 No protocol String Name of the sub-protocol used by this DataChannel. No appData Object Custom application data. No { }
SctpStreamParameters
Field Type Description Required Default streamId Number SCTP stream id true ordered Boolean Whether data messages must be received in order. if true the messages will be sent reliably. No true maxPacketLifeTime Number When ordered is false indicates the time (in milliseconds) after which a SCTP packet will stop being retransmitted. No maxRetransmits Number When ordered is false indicates the maximum number of times a packet will be retransmitted. No
If ordered is true then maxPacketLifeTime and maxRetransmits must be false. If ordered if false, only one of maxPacketLifeTime or maxRetransmits can be true.
DataConsumerOptions
Field Type Description Required Default dataProducerId String The id of the data producer to consume. Yes ordered Boolean SCTP 传输生效. 按序接收,如果true,发送端reliably 发送. No The value in the data producer (if it’s of type ‘sctp’) or true (if it’s of type ‘direct’). maxPacketLifeTime Number SCTP 传输生效. When ordered is false, it indicates the time (in milliseconds) after which a SCTP packet will stop being retransmitted. No The value in the data producer (if it’s of type ‘sctp’) or unset (if it’s of type ‘direct’). maxRetransmits Number SCTP 传输生效. When ordered is false, it indicates the maximum number of times a packet will be retransmitted. No The value in the data producer (if it’s of type ‘sctp’) or unset (if it’s of type ‘direct’). appData Object Custom application data. No { }
RtpObserver
Properties
rtpObserver.id rtpObserver.closed rtpObserver.paused rtpObserver.appData rtpObserver.observer
Methods
rtpObserver.close() rtpObserver.pause() rtpObserver.resume() rtpObserver.addProducer(producer) rtpObserver.removeProducer(producer)
Events
rtpObserver.on(“routerclose”)
Observer Events
rtpObserver.observer.on(“close”, fn()) rtpObserver.observer.on(“pause”, fn()) rtpObserver.observer.on(“resume”, fn()) rtpObserver.observer.on(“addproducer”, fn(producer)) rtpObserver.observer.on(“removeproducer”, fn(producer))
AudioLevelObserver
audio level observer 监控的是被选中的 audio producer 的音量。并且,仅监控 audio producer。
Dictionaries
AudioLevelObserverOptions
Field Type Description Required Default maxEntries Number Maximum number of entries in the “volumes” event. No 1 threshold Number Minimum average volume (in dBvo from -127 to 0) for entries in the “volumes” event. No -80 interval Number Interval in ms for checking audio volumes. No 1000 appData Object Custom application data. No { }
AudioLevelObserverVolume
Field Type Description Required Default producer Producer The audio producer instance. Yes volume Number The average volume (in dBvo from -127 to 0) of the audio producer in the last interval. Yes