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

Add NoAutoSubscribe to peer.JoinConfig. #558

Merged
merged 4 commits into from
Jul 28, 2021
Merged

Conversation

cloudwebrtc
Copy link
Contributor

@cloudwebrtc cloudwebrtc commented Jul 23, 2021

Description

Do not subscribe to any stream during peer join, so that the application layer can perform fine control and subscribe on-demand

1, Listen publisher.OnPublishTrack event, generate StreamEvent and broadcast to each peer.

peer.Publisher().OnPublisherTrack(func(track ion_sfu.PublisherTrack) {
    log.Debugf("peer.OnPublisherTrack: \nKind %v, \nUid: %v,  \nMsid: %v,\nTrackID: %v",
                       track.Track.Kind(),
                       uid, 
                       track.Track.Msid(), 
                       track.Track.ID())
    // event := &rtc.StreamEvent{.....}
    // sig.BroadcastStreamEvent(event)
})

2,Peer uses the trackIds in StreamEvent to subscribe or unsubscribe.

case *rtc.UpdateSettings_Subcription:

subscription := payload.UpdateSettings.GetSubcription()
enabled := subscription.GetSubscribe()

for _, trackId := range subscription.TrackIds {

	if enabled {
                 // Add down tracks
		for _, p := range peer.Session().Peers() {
			for _, track := range p.Publisher().PublisherTracks() {
				if track.Receiver.TrackID() == trackId {
					peer.Publisher().GetRouter().AddDownTrack(peer.Subscriber(), track.Receiver)
				}
			}
		}
	} else {
               // Remove down tracks
		for streamID, downTracks := range peer.Subscriber().DownTracks() {
			for _,  track := range downTracks {
				if track.ID() == trackId {
					peer.Subscriber().RemoveDownTrack(streamID, track)
                                          track.Stop()
				}
			}
		}
	}

}

peer.Subscriber().Negotiate()

This event is used to monitor the publisher OnTrack event and distribute
the event to other members in the session through signaling.
Copy link
Contributor

@adwpc adwpc left a comment

Choose a reason for hiding this comment

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

LGTM. seems no break changes

@codecov
Copy link

codecov bot commented Jul 24, 2021

Codecov Report

Merging #558 (c92f06a) into master (efaa0b7) will decrease coverage by 0.44%.
The diff coverage is 34.18%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #558      +/-   ##
==========================================
- Coverage   40.24%   39.80%   -0.45%     
==========================================
  Files          23       23              
  Lines        2430     2437       +7     
==========================================
- Hits          978      970       -8     
- Misses       1324     1336      +12     
- Partials      128      131       +3     
Impacted Files Coverage Δ
pkg/buffer/buffer.go 37.32% <ø> (ø)
pkg/buffer/factory.go 0.00% <0.00%> (ø)
pkg/buffer/helpers.go 36.47% <0.00%> (ø)
pkg/logger/helpers.go 17.39% <ø> (-11.19%) ⬇️
pkg/sfu/sfu.go 48.21% <0.00%> (-0.88%) ⬇️
pkg/sfu/router.go 47.97% <10.00%> (-0.85%) ⬇️
pkg/sfu/publisher.go 30.20% <14.28%> (-1.23%) ⬇️
pkg/logger/zerologr.go 37.50% <29.72%> (-8.66%) ⬇️
pkg/sfu/downtrack.go 31.62% <33.33%> (-1.01%) ⬇️
pkg/sfu/peer.go 54.16% <33.33%> (-0.54%) ⬇️
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9888842...c92f06a. Read the comment docs.

pkg/sfu/publisher.go Outdated Show resolved Hide resolved
pkg/sfu/publisher.go Outdated Show resolved Hide resolved
pkg/sfu/publisher.go Outdated Show resolved Hide resolved
pkg/sfu/publisher.go Outdated Show resolved Hide resolved
pkg/sfu/subscriber.go Outdated Show resolved Hide resolved
@cloudwebrtc cloudwebrtc force-pushed the feat/no-auto-subcribe branch from 266a58e to c92f06a Compare July 25, 2021 02:56
@cloudwebrtc
Copy link
Contributor Author

@OrlandoCo updated

@cloudwebrtc cloudwebrtc merged commit aa273c9 into master Jul 28, 2021
@cloudwebrtc cloudwebrtc deleted the feat/no-auto-subcribe branch July 28, 2021 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants