Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package moqtransport
// Common Message types. Handlers can react to any of these messages.
const (
MessageSubscribe = "SUBSCRIBE"
MessageUnsubscribe = "UNSUBSCRIBE "
MessageFetch = "FETCH"
MessageAnnounce = "ANNOUNCE"
MessageAnnounceCancel = "ANNOUNCE_CANCEL"
Expand Down
21 changes: 15 additions & 6 deletions integrationtests/subscribe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package integrationtests

import (
"context"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -113,14 +114,21 @@ func TestSubscribe(t *testing.T) {
defer cancel()

publisherCh := make(chan moqtransport.Publisher, 1)
var clientClosing atomic.Bool
clientClosing.Store(false)

handler := moqtransport.HandlerFunc(func(w moqtransport.ResponseWriter, m *moqtransport.Message) {
assert.Equal(t, moqtransport.MessageSubscribe, m.Method)
assert.NotNil(t, w)
assert.NoError(t, w.Accept())
publisher, ok := w.(moqtransport.Publisher)
assert.True(t, ok)
publisherCh <- publisher
if !clientClosing.Load() {
assert.Equal(t, moqtransport.MessageSubscribe, m.Method)
assert.NotNil(t, w)
assert.NoError(t, w.Accept())
publisher, ok := w.(moqtransport.Publisher)
assert.True(t, ok)
publisherCh <- publisher
} else {
assert.Equal(t, moqtransport.MessageUnsubscribe, m.Method)
assert.Nil(t, w)
}
})
_, _, _, ct, cancel := setup(t, sConn, cConn, handler)
defer cancel()
Expand All @@ -136,6 +144,7 @@ func TestSubscribe(t *testing.T) {
assert.FailNow(t, "timeout while waiting for publisher")
}

clientClosing.Store(true)
assert.NoError(t, rt.Close())

time.Sleep(10 * time.Millisecond)
Expand Down
8 changes: 5 additions & 3 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,15 +867,17 @@ func (s *Session) onSubscribeUpdate(_ *wire.SubscribeUpdateMessage) error {
return nil
}

// TODO: Maybe don't immediately close the track and give app a chance to react
// first?
func (s *Session) onUnsubscribe(msg *wire.UnsubscribeMessage) error {
lt, ok := s.localTracks.findByID(msg.SubscribeID)
if !ok {
return errUnknownSubscribeID
}
lt.unsubscribe()
return nil
m := &Message{
Method: MessageUnsubscribe,
SubscribeID: msg.SubscribeID,
}
return s.ctrlMsgReceiveQueue.enqueue(context.Background(), m)
}

func (s *Session) onSubscribeDone(msg *wire.SubscribeDoneMessage) error {
Expand Down