Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(multi-stream-support) Add track streaming status #1855

Merged
merged 3 commits into from
Feb 23, 2022

Conversation

WillLiang918
Copy link
Contributor

@WillLiang918 WillLiang918 commented Jan 19, 2022

This change allow us handle the streaming status of each individual track when the feature flag is enabled. The emitted streaming status is mostly used for the connection indicator in the UI.

Related jitsi-meet PR: jitsi/jitsi-meet#10934

Todo/Follow up item:

  • Look into moving some of the TrackStreamingStatus#onForwardedSourcesChanged logic out into RTC#_onForwardedSourcesChanged. The reason being is that since TrackStreamingStatus is only initialized when a track is rendered, there is a corner case where we are not capturing the timestamp of when it entered forwarded sources.
  • Add specs, this can be part of another PR.

@jitsi-jenkins
Copy link

Hi, thanks for your contribution!
If you haven't already done so, could you please make sure you sign our CLA (https://jitsi.org/icla for individuals and https://jitsi.org/ccla for corporations)? We would unfortunately be unable to merge your patch unless we have that piece :(.

RTCEvents.REMOTE_TRACK_UNMUTE,
this._onTrackRtcUnmuted);

this.track.off(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic to handle the JitsiConferenceEvents.TRACK_REMOVED event has been moved into the dispose method of this class.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And when a track is removed this instance will be disposed anyway, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will double check to confirm if that is true. If not, I can dispose it where we are emitting JitsiConferenceEvents.TRACK_REMOVED

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I saw any logic in LJM that called dispose when a tracked was removed. I wasn't sure if this is intended so I added logic to clear _trackStreamingStatusImpl and _trackStreamingStatus where the event was emitted

* @param {Array<string>} enteringForwardedSources - The array of sourceName entering forwarded sources.
* @private
*/
_onForwardedSourcesChanged(leavingForwardedSources = [], enteringForwardedSources = []) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will work as I expect it to. I'll need to move this logic somewhere else, perhaps JitsiConferenceEventManager, and have it iterate through all the leaving and entering forwarded sources.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah because the timestamps will not be accurate since this instance may disappear. Lets try to think about it... Maybe we need to store the timestamps somewhere (the place which emits the forwarded sources changed event) and then expose that via a getter? Or better have a static part/helper class of TrackStreamingStatus which would keep track of the timestamps (mostly because they are not used by any other logic) ?

Copy link
Contributor Author

@WillLiang918 WillLiang918 Feb 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking into using a static method/helper class and it was starting to get a bit messy since it would still need to call figureOutStreamingStatus for each instances that is leaving/entering or when !browser.supportsVideoMuteOnConnInterrupted(). If our only concern is having inaccurate timestamps and performance isn't an issue, can we just emit the timestamp with the forwarded sources? Never mind, we still have the issue of losing this timestamp when the instance disappears

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can actually make it so that the JitsiRemoteTrack holds the timestamps when it entered/left the forwarded sources and this can happen any time the RTC module emits the forwarded sources event?

RTCEvents.REMOTE_TRACK_UNMUTE,
this._onTrackRtcUnmuted);

this.track.off(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And when a track is removed this instance will be disposed anyway, right?

* @param {Array<string>} enteringForwardedSources - The array of sourceName entering forwarded sources.
* @private
*/
_onForwardedSourcesChanged(leavingForwardedSources = [], enteringForwardedSources = []) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah because the timestamps will not be accurate since this instance may disappear. Lets try to think about it... Maybe we need to store the timestamps somewhere (the place which emits the forwarded sources changed event) and then expose that via a getter? Or better have a static part/helper class of TrackStreamingStatus which would keep track of the timestamps (mostly because they are not used by any other logic) ?

Copy link
Member

@jallamsetty1 jallamsetty1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @WillLiang918. Left few minor comments. One complaint that I have is there is a lot of code duplication.

* @param {Array<string>} enteringForwardedSources - The array of sourceName entering forwarded sources.
* @private
*/
_onForwardedSourcesChanged(leavingForwardedSources = [], enteringForwardedSources = []) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can actually make it so that the JitsiRemoteTrack holds the timestamps when it entered/left the forwarded sources and this can happen any time the RTC module emits the forwarded sources event?

@sapkra sapkra added the feature-request Issue is really a feature request label Feb 5, 2022
@WillLiang918 WillLiang918 changed the title feat: Adjust Last N to work with source names (WIP) feat(multi-stream-support) Add track streaming status Feb 9, 2022
@WillLiang918 WillLiang918 marked this pull request as ready for review February 9, 2022 13:45
@jallamsetty1
Copy link
Member

Jenkins please add to whitelist

@jallamsetty1
Copy link
Member

Jenkins test this please.

* @param {Array<string>|null} enteringForwardedSources the sourceNames of all the tracks which are entering forwarded
* sources
*/
export const FORWARDED_SOURCES_CHANGED = 'conference.forwardedSourcesChanged';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry that I wasn't paying attention to this earlier, but we need to add a getter to JitsiConference.getForwardedSources(), so that a LJM user can get the current state without having to register the even listener from the start.

Copy link
Contributor Author

@WillLiang918 WillLiang918 Feb 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, it does make sense to allow us to access the current forwarded sources state without having to register a listener. Is this more of a best practice to expose this on the conference do you see an optimization we can make?

@@ -43,3 +43,16 @@ export const NO_DATA_FROM_SOURCE = 'track.no_data_from_source';
* the microphone that is currently selected.
*/
export const NO_AUDIO_INPUT = 'track.no_audio_input';

/**
* Event fired when we detect local problem with the video track.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets reword it to Event fired whenever video track's streaming changes

import Statistics from '../statistics/statistics';

/** Track streaming statuses. */
type TrackStreamingStatus = 'active' | 'inactive' | 'interrupted' | 'restoring';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to make this an enum and not have the TrackStreamingStatusMapType?

/**
* @returns {Boolean} Whether this is a muted video track.
*/
isVideoMuted() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this method? In place where it's used it should be enough to check isMuted()

/**
* Disposes trackStreamingStatusImpl and clears trackStreamingStatus
*/
disposeTrackStreamingStatus() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add underscore to this method's name? JitsiRemoteTrack is exported by lib-jitsi-meet and this would look like a public method

/**
* Clears the timestamp of when the track entered forwarded sources.
*/
clearEnteredForwardedSourcesTimestamp() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add _

*
* @param {number} timestamp the time in millis
*/
setEnteredForwardedSourcesTimestamp(timestamp) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add _

*
* @returns {number} the time in millis
*/
getEnteredForwardedSourcesTimestamp() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add _

[key: string]: TrackStreamingStatus
}

type VideoType = 'camera' | 'desktop';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a place outside of TrackStreamingStatus where this type can be defined? Maybe create a dedicated .ts file? If that's too much work please mark this with a TODO comment that it should be removed from here once service/RTC/VideoType.js is converted to type script.

Copy link
Member

@jallamsetty1 jallamsetty1 Feb 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we import VideoType from service/RTC/VideoType.js here directly ?
ETA: What I meant was that we already have auto-generated type for VideoType. Can we use that instead of defining it here again ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We definitely can! I found that type after Pawel pointed this out. I'll push another set of changes out shortly after testing it locally

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait do you mean the VideoType enum in types/hand-crafted/services/RTC/VideoType.d.ts or the VideoType object in VideoType.js?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to take a quick look to see if we can do something similar to the recent changes to /JitsiConferenceEvents.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to revert my changes and adding a TODO to use the VideoType enum in https://github.com/jitsi/lib-jitsi-meet/pull/1916/files

Copy link
Member

@jallamsetty1 jallamsetty1 Feb 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry had to take half day off yesterday and was away. Yes, I was talking about VideoType from hand-crafted dir. It makes sense to use the VideoType enum from the newly created TS files after they get merged.

*/
const DEFAULT_RESTORING_TIMEOUT = 10000;

export const TrackStreamingStatusMap: TrackStreamingStatusMapType = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as per the other comment, if TrackStreamingStatusMapType was replace with TrackStreamingStatus enum, will it be possible to get rid of this map?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take another look into this. I think I was having issues when I first tried it because TrackStreamingStatusMap was being imported into non .ts files where enums aren't supported

update JitsiRemoteTrack to init and dispose TrackStreamingStatus
stop emitting LASTN_ENDPOINT_CHANGED event when source name signaling is enabled
convert TrackStreamingStatus class to typescript
@WillLiang918 WillLiang918 force-pushed the forwarded-sources branch 2 times, most recently from fc658c1 to bc20d78 Compare February 22, 2022 21:51
paweldomas
paweldomas previously approved these changes Feb 22, 2022
Copy link
Member

@paweldomas paweldomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's looking good! Left just one comment about JS docs

@paweldomas paweldomas merged commit c6b79dc into jitsi:master Feb 23, 2022
@WillLiang918 WillLiang918 deleted the forwarded-sources branch October 7, 2022 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Issue is really a feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants