forked from inlivedev/sfu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
56 lines (45 loc) · 1.11 KB
/
util.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
package sfu
import (
"bufio"
"math/rand"
"strings"
"github.com/speps/go-hashids"
)
func GetUfragAndPass(sdp string) (ufrag, pass string) {
scanner := bufio.NewScanner(strings.NewReader(sdp))
iceUfrag := "a=ice-ufrag:"
icePwd := "a=ice-pwd:" //nolint:gosec //it's not a password
for scanner.Scan() {
line := scanner.Text()
if strings.Contains(line, iceUfrag) {
ufrag = strings.Replace(line, iceUfrag, "", 1)
} else if strings.Contains(line, icePwd) {
pass = strings.Replace(line, icePwd, "", 1)
}
if ufrag != "" && pass != "" {
break
}
}
return ufrag, pass
}
func CountTracks(sdp string) int {
counter := 0
scanner := bufio.NewScanner(strings.NewReader(sdp))
for scanner.Scan() {
line := scanner.Text()
if strings.Contains(line, "m=audio") || strings.Contains(line, "m=video") {
counter++
}
}
return counter
}
func GenerateID(data []int) string {
randInt := rand.Intn(100) //nolint:gosec //it's not a password
data = append(data, randInt)
hd := hashids.NewData()
hd.Salt = "this is my salt"
hd.MinLength = 9
h, _ := hashids.NewWithData(hd)
e, _ := h.Encode(data)
return e
}