-
Notifications
You must be signed in to change notification settings - Fork 312
/
storageClient.go
62 lines (55 loc) · 1.53 KB
/
storageClient.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
package main
import (
"time"
"github.com/deepch/vdk/av"
)
//ClientAdd Add New Client to Translations
func (obj *StorageST) ClientAdd(streamID string, channelID string, mode int) (string, chan *av.Packet, chan *[]byte, error) {
obj.mutex.Lock()
defer obj.mutex.Unlock()
streamTmp, ok := obj.Streams[streamID]
if !ok {
return "", nil, nil, ErrorStreamNotFound
}
//Generate UUID client
cid, err := generateUUID()
if err != nil {
return "", nil, nil, err
}
chAV := make(chan *av.Packet, 2000)
chRTP := make(chan *[]byte, 2000)
channelTmp, ok := streamTmp.Channels[channelID]
if !ok {
return "", nil, nil, ErrorStreamNotFound
}
channelTmp.clients[cid] = ClientST{mode: mode, outgoingAVPacket: chAV, outgoingRTPPacket: chRTP, signals: make(chan int, 100)}
channelTmp.ack = time.Now()
streamTmp.Channels[channelID] = channelTmp
obj.Streams[streamID] = streamTmp
return cid, chAV, chRTP, nil
}
//ClientDelete Delete Client
func (obj *StorageST) ClientDelete(streamID string, cid string, channelID string) {
obj.mutex.Lock()
defer obj.mutex.Unlock()
if _, ok := obj.Streams[streamID]; ok {
delete(obj.Streams[streamID].Channels[channelID].clients, cid)
}
}
//ClientHas check is client ext
func (obj *StorageST) ClientHas(streamID string, channelID string) bool {
obj.mutex.Lock()
defer obj.mutex.Unlock()
streamTmp, ok := obj.Streams[streamID]
if !ok {
return false
}
channelTmp, ok := streamTmp.Channels[channelID]
if !ok {
return false
}
if time.Now().Sub(channelTmp.ack).Seconds() > 30 {
return false
}
return true
}