Skip to content

Commit

Permalink
Webhook events for track published (#106)
Browse files Browse the repository at this point in the history
* Webhook events for track published

* timeout for webhook notifications to avoid hang
  • Loading branch information
davidzhao authored Mar 19, 2022
1 parent 51f5188 commit 8dff6f8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
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

0 comments on commit 8dff6f8

Please sign in to comment.