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

Move setActive(true) from the trigger 'PUSH_REWRITE' to 'STREAM_BUFFER' #956

Merged
merged 3 commits into from
Nov 8, 2023
Merged
Changes from 1 commit
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
36 changes: 13 additions & 23 deletions mapic/mistapiconnector_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,27 +189,27 @@
}

func (mc *mac) handleStreamBuffer(ctx context.Context, payload *misttriggers.StreamBufferPayload) error {
// We only care about connections ending
if !payload.IsEmpty() {
return nil
}

isActive := !payload.IsEmpty()

Check warning on line 192 in mapic/mistapiconnector_app.go

View check run for this annotation

Codecov / codecov/patch

mapic/mistapiconnector_app.go#L192

Added line #L192 was not covered by tests
playbackID := payload.StreamName
if mc.baseStreamName != "" && strings.Contains(playbackID, "+") {
playbackID = strings.Split(playbackID, "+")[1]
}
if info, ok := mc.getStreamInfoLogged(playbackID); ok {
glog.Infof("Setting stream's manifestID=%s playbackID=%s active status to false", info.id, playbackID)
_, err := mc.lapi.SetActive(info.id, false, info.startedAt)
glog.Infof("Setting stream's manifestID=%s playbackID=%s active status to %v", info.id, playbackID, isActive)
_, err := mc.lapi.SetActive(info.id, isActive, info.startedAt)

Check warning on line 199 in mapic/mistapiconnector_app.go

View check run for this annotation

Codecov / codecov/patch

mapic/mistapiconnector_app.go#L198-L199

Added lines #L198 - L199 were not covered by tests
if err != nil {
glog.Error(err)
leszko marked this conversation as resolved.
Show resolved Hide resolved
}
mc.emitStreamStateEvent(info.stream, data.StreamState{Active: false})
info.mu.Lock()
info.stopped = true
info.mu.Unlock()
mc.removeInfoDelayed(playbackID, info.done)
metrics.StopStream(true)
mc.emitStreamStateEvent(info.stream, data.StreamState{Active: isActive})
if isActive {
metrics.StartStream()
} else {
info.mu.Lock()
info.stopped = true
info.mu.Unlock()
mc.removeInfoDelayed(playbackID, info.done)
metrics.StopStream(true)
}

Check warning on line 212 in mapic/mistapiconnector_app.go

View check run for this annotation

Codecov / codecov/patch

mapic/mistapiconnector_app.go#L203-L212

Added lines #L203 - L212 were not covered by tests
}

return nil
Expand Down Expand Up @@ -263,19 +263,9 @@
} else {
responseName = mc.wildcardPlaybackID(stream)
}
ok, err := mc.lapi.SetActive(stream.ID, true, info.startedAt)
if err != nil {
return "", fmt.Errorf("Error calling SetActive err=%s", err)
} else if !ok {
glog.Infof("Stream id=%s streamKey=%s playbackId=%s forbidden by webhook, rejecting", stream.ID, stream.StreamKey, stream.PlaybackID)
mc.removeInfo(stream.PlaybackID)
return "", nil
}
} else {
glog.Errorf("Shouldn't happen streamID=%s", stream.ID)
}
go mc.emitStreamStateEvent(stream, data.StreamState{Active: true})
metrics.StartStream()
glog.Infof("Responded with '%s'", responseName)
return responseName, nil
}
Expand Down
Loading