-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcall.go
68 lines (55 loc) · 1.22 KB
/
call.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
package zoom
import (
"net/url"
"path"
"strings"
"mvdan.cc/xurls/v2"
)
var urlRegexp = xurls.Strict()
type call struct {
id string
password string
originalURL string
}
func (c call) GetAppURL() string {
if c.id == "" {
return c.originalURL
}
url := "zoommtg://zoom.us/join?confno=" + c.id
if c.password != "" {
url = url + "&pwd=" + c.password
}
return url
}
func extractZoomCallURL(input string) (*url.URL, bool) {
urls := urlRegexp.FindAllString(input, -1)
if len(urls) == 0 {
return nil, false
}
for _, inputURL := range urls {
u, err := url.Parse(inputURL)
if err != nil {
continue
}
if strings.HasSuffix(u.Hostname(), ".zoom.us") || u.Hostname() == "zoom.us" {
return u, true
}
}
return nil, false
}
func extractZoomCallData(input string) (call, bool) {
zoomURL, ok := extractZoomCallURL(input)
if !ok {
return call{}, false
}
// By default, match the whole URL.
data := &call{originalURL: zoomURL.String()}
// If we have a meeting ID in the URL, then we have a URL.
if strings.HasPrefix(zoomURL.Path, "/j/") {
_, data.id = path.Split(zoomURL.Path)
}
if password := zoomURL.Query().Get("pwd"); password != "" {
data.password = password
}
return *data, true
}