-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
93 lines (67 loc) · 1.7 KB
/
config.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package pubnub
import (
"fmt"
"github.com/pubnub/go/utils"
"log"
)
const (
presenceTimeout = 300
)
type Config struct {
PublishKey string
SubscribeKey string
SecretKey string
AuthKey string
Origin string
Uuid string
CipherKey string
Secure bool
// net.Dialer.Timeout
ConnectTimeout int
// http.Client.Timeout for non-subscribe requests
NonSubscribeRequestTimeout int
// http.Client.Timeout for subscribe requests only
SubscribeRequestTimeout int
HeartbeatInterval int
PresenceTimeout int
MaximumReconnectionRetries int
MaximumLatencyDataAge int
FilterExpression string
PNReconnectionPolicy ReconnectionPolicy
Log *log.Logger
SuppressLeaveEvents bool
DisablePNOtherProcessing bool
UseHttp2 bool
}
func NewDemoConfig() *Config {
demoConfig := NewConfig()
demoConfig.PublishKey = "demo"
demoConfig.SubscribeKey = "demo"
demoConfig.SecretKey = "demo"
return demoConfig
}
func NewConfig() *Config {
c := Config{
Origin: "ps.pndsn.com",
Secure: true,
Uuid: fmt.Sprintf("pn-%s", utils.Uuid()),
ConnectTimeout: 10,
NonSubscribeRequestTimeout: 10,
SubscribeRequestTimeout: 310,
MaximumLatencyDataAge: 60,
MaximumReconnectionRetries: -1,
SuppressLeaveEvents: false,
DisablePNOtherProcessing: false,
}
c.SetPresenceTimeout(presenceTimeout)
return &c
}
func (c *Config) SetPresenceTimeoutWithCustomInterval(
timeout, interval int) *Config {
c.PresenceTimeout = timeout
c.HeartbeatInterval = interval
return c
}
func (c *Config) SetPresenceTimeout(timeout int) *Config {
return c.SetPresenceTimeoutWithCustomInterval(timeout, (timeout/2)-1)
}