Skip to content

Webhook events for track published #106

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

Merged
merged 2 commits into from
Mar 19, 2022
Merged
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
2 changes: 2 additions & 0 deletions webhook/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const (
EventRoomFinished = "room_finished"
EventParticipantJoined = "participant_joined"
EventParticipantLeft = "participant_left"
EventTrackPublished = "track_published"
EventTrackUnpublished = "track_unpublished"
EventRecordingStarted = "recording_started"
EventRecordingFinished = "recording_finished"
EventEgressStarted = "egress_started"
Expand Down
8 changes: 7 additions & 1 deletion webhook/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/livekit/protocol/auth"
)

const defaultWebhookTimeout = 10 * time.Second

type Notifier interface {
Notify(ctx context.Context, payload interface{}) error
}
Expand All @@ -24,6 +26,7 @@ type notifier struct {
apiKey string
apiSecret string
urls []string
client *http.Client
logger logr.Logger
}

Expand All @@ -33,6 +36,9 @@ func NewNotifier(apiKey, apiSecret string, urls []string) Notifier {
apiSecret: apiSecret,
urls: urls,
logger: logr.Discard(),
client: &http.Client{
Timeout: defaultWebhookTimeout,
},
}
}

Expand Down Expand Up @@ -71,7 +77,7 @@ func (n *notifier) Notify(_ context.Context, payload interface{}) error {
}
r.Header.Set(authHeader, token)
r.Header.Set("content-type", "application/json")
_, err = http.DefaultClient.Do(r)
_, err = n.client.Do(r)
if err != nil {
n.logger.Error(err, "could not post to webhook", "url", url)
}
Expand Down