Skip to content

Commit

Permalink
impl: analytics ready webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
jibon57 committed Nov 20, 2023
1 parent a5927e8 commit 3756f46
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/jordic/lti v0.0.0-20160211051708-2c756eacbab9
github.com/livekit/protocol v1.9.1
github.com/livekit/server-sdk-go v1.1.1
github.com/mynaparrot/plugnmeet-protocol v0.0.0-20231120144725-8b2fcffff319
github.com/mynaparrot/plugnmeet-protocol v0.0.0-20231120153130-a7986a8ecea5
github.com/redis/go-redis/v9 v9.3.0
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.8.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZ
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k=
github.com/mynaparrot/plugnmeet-protocol v0.0.0-20231120144725-8b2fcffff319 h1:lEnpVW75RJQTh2a6ZJRJjuyYuftBft0S8xYmA2DETis=
github.com/mynaparrot/plugnmeet-protocol v0.0.0-20231120144725-8b2fcffff319/go.mod h1:KXtBamxckRtrcWtmY5BIboDkhM5elHg23hZxbA9lw8Y=
github.com/mynaparrot/plugnmeet-protocol v0.0.0-20231120153130-a7986a8ecea5 h1:qRRhEYdSbfSzzgWW/HgcpjHhhENZlSoF9dGZm92ttc0=
github.com/mynaparrot/plugnmeet-protocol v0.0.0-20231120153130-a7986a8ecea5/go.mod h1:KXtBamxckRtrcWtmY5BIboDkhM5elHg23hZxbA9lw8Y=
github.com/nats-io/nats.go v1.31.0 h1:/WFBHEc/dOKBF6qf1TZhrdEfTmOZ5JzdJ+Y3m6Y/p7E=
github.com/nats-io/nats.go v1.31.0/go.mod h1:di3Bm5MLsoB4Bx61CBTsxuarI36WbhAwOm8QrW39+i8=
github.com/nats-io/nkeys v0.4.6 h1:IzVe95ru2CT6ta874rt9saQRkWfe2nFj1NtvYSLqMzY=
Expand Down
24 changes: 24 additions & 0 deletions pkg/models/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ func (m *AnalyticsModel) PrepareToExportAnalytics(sid, meta string) {
if metadata.RoomFeatures.EnableAnalytics {
// record in db
m.addAnalyticsFileToDB(room.Id, room.CreationTime, room.RoomId, fileId, stat)
// notify
m.sendToWebhookNotifier(room.RoomId, room.Sid, "analytics_proceeded", fileId)
}
}

Expand Down Expand Up @@ -307,6 +309,7 @@ func (m *AnalyticsModel) exportAnalyticsToFile(room *RoomInfo, path string, meta
log.Errorln(err)
return nil, err
}

}

// at the end delete all redis records
Expand Down Expand Up @@ -440,3 +443,24 @@ func (m *AnalyticsModel) handleFirstTimeUserJoined(key string) {
log.Errorln(err)
}
}

func (m *AnalyticsModel) sendToWebhookNotifier(roomId, roomSid, task, fileId string) {
n := GetWebhookNotifier(roomId, roomSid)
if n != nil {
msg := &plugnmeet.CommonNotifyEvent{
Event: &task,
Room: &plugnmeet.NotifyEventRoom{
Sid: &roomSid,
RoomId: &roomId,
},
Analytics: &plugnmeet.AnalyticsEvent{
FileId: &fileId,
},
}

err := n.SendWebhook(msg, nil)
if err != nil {
log.Errorln(err)
}
}
}

0 comments on commit 3756f46

Please sign in to comment.