-
Notifications
You must be signed in to change notification settings - Fork 27
/
meeting.go
74 lines (65 loc) · 1.99 KB
/
meeting.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package jitsi
import (
"fmt"
"strings"
)
// MeetingTokenGenerator provides an interface for creating video conference
// authenticated access via JWT.
type MeetingTokenGenerator interface {
CreateJWT(JWTInput) (string, error)
}
// ServerConfigReader provides an interface for reading configure server data
// from the configuration store.
type ServerConfigReader interface {
Get(string) (ServerCfg, error)
}
// MeetingGenerator provides an interface for generating meetings configured
// correctly for the slack team.
type MeetingGenerator struct {
ServerConfigReader ServerConfigReader
MeetingTokenGenerator MeetingTokenGenerator
}
// Meeting contains the server specific info for a meeting.
type Meeting struct {
RoomName string
URL string
Host string
AuthenticatedURL func(UserID, UserName, AvatarURL string) (string, error)
}
// New generates a new meeting for the provided team. Each team may either be
// using the default service, meet.jit.si, or their own installation.
func (m *MeetingGenerator) New(teamID, teamName string) (Meeting, error) {
var mtg Meeting
mtg.RoomName = RandomName()
srv, err := m.ServerConfigReader.Get(teamID)
if err != nil {
return Meeting{}, err
}
mtg.Host = srv.Server
if srv.TenantScopedURLs {
mtg.URL = fmt.Sprintf("%s/%s/%s", srv.Server, strings.ToLower(teamName), mtg.RoomName)
} else {
mtg.URL = fmt.Sprintf("%s/%s", srv.Server, mtg.RoomName)
}
if srv.AuthenticatedURLSupport {
mtg.AuthenticatedURL = func(userID, userName, avatarURL string) (string, error) {
jwt, err := m.MeetingTokenGenerator.CreateJWT(JWTInput{
TenantID: teamID,
TenantName: teamName,
RoomClaim: mtg.RoomName,
UserID: userID,
UserName: userName,
AvatarURL: avatarURL,
})
if err != nil {
return "", err
}
return fmt.Sprintf("%s?jwt=%s", mtg.URL, jwt), nil
}
} else {
mtg.AuthenticatedURL = func(userID, userName, avatarURL string) (string, error) {
return mtg.URL, nil
}
}
return mtg, nil
}