Packs local media streams. Participants can publish it to a session. Initialized with initPublisher method.

See available event listeners at PublisherEventMap.

Hierarchy

Properties

accessAllowed: boolean = false

Whether the Publisher has been granted access to the requested input devices or not

id: string

id attribute of the DOM video element displaying the Publisher/Subscriber's stream. This property is only defined if:

isSubscribedToRemote: boolean = false

Whether you have called subscribeToRemote with value true or false (false by default)

remote: boolean

Whether the Stream represented in the DOM is local or remote

session: Session

The Session to which the Publisher belongs

stream: Stream

The Stream represented in the DOM by the Publisher/Subscriber

targetElement: HTMLElement

The DOM HTMLElement assigned as target element when creating the video for the Publisher/Subscriber. This property is only defined if:

videos: StreamManagerVideo[] = []

All the videos displaying the Stream of this Publisher/Subscriber

Methods

  • Makes video element parameter display this stream. This is useful when you are managing the video elements on your own

    Calling this method with a video already added to other Publisher/Subscriber will cause the video element to be disassociated from that previous Publisher/Subscriber and to be associated to this one.

    Returns

    1 if the video wasn't associated to any other Publisher/Subscriber and has been successfully added to this one. 0 if the video was already added to this Publisher/Subscriber. -1 if the video was previously associated to any other Publisher/Subscriber and has been successfully disassociated from that one and properly added to this one.

    Parameters

    • video: HTMLVideoElement

    Returns number

  • Creates a new video element displaying this stream. This allows you to have multiple video elements displaying the same media stream.

    Events dispatched

    The Publisher/Subscriber object will dispatch a videoElementCreated event once the HTML video element has been added to DOM. See VideoElementEvent

    Returns

    The created HTMLVideoElement

    Parameters

    • Optional targetElement: string | HTMLElement

      HTML DOM element (or its id attribute) in which the video element of the Publisher/Subscriber will be inserted

    • Optional insertMode: VideoInsertMode

      How the video element will be inserted accordingly to targetElemet

    Returns HTMLVideoElement

  • Publish or unpublish the audio stream (if available). Calling this method twice in a row passing same enabled value will have no effect

    Events dispatched

    Only if Session.publish(Publisher) has been called for this Publisher

    The Session object of the local participant will dispatch a streamPropertyChanged event with changedProperty set to "audioActive" and reason set to "publishAudio" The Publisher object of the local participant will also dispatch the exact same event

    The Session object of every other participant connected to the session will dispatch a streamPropertyChanged event with changedProperty set to "audioActive" and reason set to "publishAudio" The respective Subscriber object of every other participant receiving this Publisher's stream will also dispatch the exact same event

    See StreamPropertyChangedEvent to learn more.

    Parameters

    • enabled: boolean

      true to publish the audio stream, false to unpublish it

    Returns void

  • Publish or unpublish the video stream (if available). Calling this method twice in a row passing same enabled value will have no effect

    Events dispatched

    Only if Session.publish(Publisher) has been called for this Publisher

    The Session object of the local participant will dispatch a streamPropertyChanged event with changedProperty set to "videoActive" and reason set to "publishVideo" The Publisher object of the local participant will also dispatch the exact same event

    The Session object of every other participant connected to the session will dispatch a streamPropertyChanged event with changedProperty set to "videoActive" and reason set to "publishVideo" The respective Subscriber object of every other participant receiving this Publisher's stream will also dispatch the exact same event

    See StreamPropertyChangedEvent to learn more.

    Type Parameters

    • T extends boolean

    Parameters

    • enabled: T

      true to publish the video stream, false to unpublish it

    • Optional resource: T extends false ? boolean : MediaStreamTrack

      If parameter enabled is false, this optional parameter is of type boolean. It can be set to true to forcibly free the hardware resource associated to the video track, or can be set to false to keep the access to the hardware resource. Not freeing the resource makes the operation much more efficient, but depending on the platform two side-effects can be introduced: the video device may not be accessible by other applications and the access light of webcams may remain on. This is platform-dependent: some browsers will not present the side-effects even when not freeing the resource.

      If parameter enabled is true, this optional parameter is of type MediaStreamTrack. It can be set to force the restoration of the video track with a custom track. This may be useful if the Publisher was unpublished freeing the hardware resource, and openvidu-browser is not able to successfully re-create the video track as it was before unpublishing. In this way previous track settings will be ignored and this MediaStreamTrack will be used instead.

    Returns Promise<void>

  • Replaces the current video or audio track with a different one. This allows you to replace an ongoing track with a different one without having to renegotiate the whole WebRTC connection (that is, initializing a new Publisher, unpublishing the previous one and publishing the new one).

    You can get this new MediaStreamTrack by using the native Web API or simply with getUserMedia method.

    WARNING: this method has been proven to work in the majority of cases, but there may be some combinations of published/replaced tracks that may be incompatible between them and break the connection in OpenVidu Server. A complete renegotiation may be the only solution in this case. Visit RTCRtpSender.replaceTrack documentation for further details.

    Returns

    A Promise (to which you can optionally subscribe to) that is resolved if the track was successfully replaced and rejected with an Error object in other case

    Parameters

    • track: MediaStreamTrack

      The MediaStreamTrack object to replace the current one. If it is an audio track, the current audio track will be the replaced one. If it is a video track, the current video track will be the replaced one.

    Returns Promise<void>

  • Call this method before publish if you prefer to subscribe to your Publisher's remote stream instead of using the local stream, as any other user would do.

    Parameters

    • Optional value: boolean

    Returns void

  • Updates the current configuration for the PublisherSpeakingEvent feature and the StreamManagerEvent.streamAudioVolumeChange feature for this specific StreamManager audio stream, overriding the global options set with setAdvancedConfiguration. This way you can customize the audio events options for each specific StreamManager and change them dynamically.

    Parameters

    • publisherSpeakingEventsOptions: {
          interval?: number;
          threshold?: number;
      }

      New options to be applied to this StreamManager's audio stream. It is an object which includes the following optional properties:

      • interval: (number) how frequently the analyser polls the audio stream to check if speaking has started/stopped or audio volume has changed. Default 100 (ms)
      • threshold: (number) the volume at which publisherStartSpeaking, publisherStopSpeaking events will be fired. Default -50 (dB)
      • Optional interval?: number
      • Optional threshold?: number

    Returns void

Generated using TypeDoc