6
6
"github.com/mynaparrot/plugnmeet-protocol/webhook"
7
7
"github.com/mynaparrot/plugnmeet-server/pkg/config"
8
8
"github.com/mynaparrot/plugnmeet-server/pkg/services/db"
9
+ natsservice "github.com/mynaparrot/plugnmeet-server/pkg/services/nats"
9
10
"github.com/mynaparrot/plugnmeet-server/pkg/services/redis"
10
11
log "github.com/sirupsen/logrus"
11
12
"time"
@@ -15,6 +16,7 @@ type WebhookNotifier struct {
15
16
ds * dbservice.DatabaseService
16
17
rs * redisservice.RedisService
17
18
app * config.AppConfig
19
+ natsService * natsservice.NatsService
18
20
isEnabled bool
19
21
enabledForPerMeeting bool
20
22
defaultUrl string
@@ -26,13 +28,13 @@ type webhookRedisFields struct {
26
28
PerformDeleting bool `json:"perform_deleting"`
27
29
}
28
30
29
- func newWebhookNotifier (app * config.AppConfig , ds * dbservice. DatabaseService , rs * redisservice. RedisService ) * WebhookNotifier {
31
+ func newWebhookNotifier (app * config.AppConfig ) * WebhookNotifier {
30
32
notifier := webhook .GetWebhookNotifier (config .DefaultWebhookQueueSize , app .Client .Debug , config .GetLogger ())
31
33
32
34
w := & WebhookNotifier {
33
- ds : ds ,
34
- rs : rs ,
35
35
app : app ,
36
+ ds : dbservice .New (app .DB ),
37
+ natsService : natsservice .New (app ),
36
38
isEnabled : app .Client .WebhookConf .Enable ,
37
39
enabledForPerMeeting : app .Client .WebhookConf .EnableForPerMeeting ,
38
40
defaultUrl : app .Client .WebhookConf .Url ,
@@ -84,16 +86,16 @@ func (w *WebhookNotifier) DeleteWebhook(roomId string) error {
84
86
return err
85
87
}
86
88
if d == nil {
87
- // this meeting do not have any webhook url
89
+ // this meeting does not have any webhook url
88
90
return nil
89
91
}
90
92
91
93
if ! d .PerformDeleting {
92
- // this mean may be new session has been started for same room
94
+ // this mean may be new session has been started for the same room
93
95
return nil
94
96
}
95
97
96
- return w .rs .DeleteWebhookData (roomId )
98
+ return w .natsService .DeleteWebhookData (roomId )
97
99
}
98
100
99
101
func (w * WebhookNotifier ) SendWebhookEvent (event * plugnmeet.CommonNotifyEvent ) error {
@@ -135,7 +137,8 @@ func (w *WebhookNotifier) SendWebhookEvent(event *plugnmeet.CommonNotifyEvent) e
135
137
}
136
138
137
139
// ForceToPutInQueue can be used to force checking meeting table to get url
138
- // this method will not do further validation. We should not use this method always because fetching data mysql will be slower than redis
140
+ // this method will not do further validation.
141
+ // We should not use this method always because fetching data mysql will be slower than redis
139
142
func (w * WebhookNotifier ) ForceToPutInQueue (event * plugnmeet.CommonNotifyEvent ) {
140
143
if ! w .isEnabled {
141
144
return
@@ -171,7 +174,7 @@ func (w *WebhookNotifier) saveData(roomId string, d *webhookRedisFields) error {
171
174
}
172
175
173
176
// we'll simply override any existing value & put new
174
- err = w .rs .AddWebhookData (roomId , marshal )
177
+ err = w .natsService .AddWebhookData (roomId , marshal )
175
178
if err != nil {
176
179
return err
177
180
}
@@ -180,17 +183,17 @@ func (w *WebhookNotifier) saveData(roomId string, d *webhookRedisFields) error {
180
183
}
181
184
182
185
func (w * WebhookNotifier ) getData (roomId string ) (* webhookRedisFields , error ) {
183
- result , err := w .rs .GetWebhookData (roomId )
186
+ data , err := w .natsService .GetWebhookData (roomId )
184
187
if err != nil {
185
188
return nil , err
186
189
}
187
190
188
- if result == "" {
191
+ if data == nil {
189
192
return nil , nil
190
193
}
191
194
192
195
d := new (webhookRedisFields )
193
- err = json .Unmarshal ([] byte ( result ) , d )
196
+ err = json .Unmarshal (data , d )
194
197
if err != nil {
195
198
return nil , err
196
199
}
@@ -200,11 +203,11 @@ func (w *WebhookNotifier) getData(roomId string) (*webhookRedisFields, error) {
200
203
201
204
var webhookNotifier * WebhookNotifier
202
205
203
- func GetWebhookNotifier (app * config.AppConfig , ds * dbservice. DatabaseService , rs * redisservice. RedisService ) * WebhookNotifier {
206
+ func GetWebhookNotifier (app * config.AppConfig ) * WebhookNotifier {
204
207
if webhookNotifier != nil {
205
208
return webhookNotifier
206
209
}
207
- webhookNotifier = newWebhookNotifier (app , ds , rs )
210
+ webhookNotifier = newWebhookNotifier (app )
208
211
209
212
return webhookNotifier
210
213
}
0 commit comments