forked from centrifugal/centrifugo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
channel.go
63 lines (51 loc) · 3.33 KB
/
channel.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
package channel
// NamespaceKey is a name of namespace unique for project.
type NamespaceKey string
// Namespace allows to create channels with different channel options within the Project
type Namespace struct {
// Name is a unique namespace name.
Name NamespaceKey `json:"name"`
// Options for namespace determine channel options for channels belonging to this namespace.
Options `mapstructure:",squash"`
}
// ChannelOptions represent channel specific configuration for namespace or project in a whole
type Options struct {
// Watch determines if message published into channel will be also sent into admin channel.
// Note that this option must be used carefully in channels with high rate of new messages
// as admin client can not process all of those messages. Use this option for testing or for
// channels with reasonable message rate.
Watch bool `json:"watch"`
// Publish determines if client can publish messages into channel directly. This allows to use
// Centrifugo without backend. All messages go through Centrifugo and delivered to clients. But
// in this case you lose everything your backend code could give - validation, persistence etc.
// This option most useful for demos, testing real-time ideas.
Publish bool `json:"publish"`
// Anonymous determines is anonymous access (with empty user ID) allowed or not. In most
// situations your application works with authorized users so every user has its own unique
// id. But if you provide real-time features for public access you may need anauthorized
// access to channels. Turn on this option and use empty string as user ID.
Anonymous bool `json:"anonymous"`
// Presence turns on(off) presence information for channels. Presence is a structure with
// clients currently subscribed on channel.
Presence bool `json:"presence"`
// JoinLeave turns on(off) join/leave messages for channels. When client subscribes on channel
// join message sent to all clients in this channel. When client leaves channel (unsubscribes)
// leave message sent.
JoinLeave bool `mapstructure:"join_leave" json:"join_leave"`
// HistorySize determines max amount of history messages for channel, 0 means no history for channel.
// Centrifugo history has auxiliary role – it can not replace your backend persistent storage.
HistorySize int `mapstructure:"history_size" json:"history_size"`
// HistoryLifetime determines time in seconds until expiration for history messages. As Centrifugo
// keeps history in memory (in process memory or in Redis process memory) it's important to remove
// old messages to prevent infinite memory grows.
HistoryLifetime int `mapstructure:"history_lifetime" json:"history_lifetime"`
// Recover enables recover mechanism for channels. This means that Centrifugo will
// try to recover missed messages for resubscribing client. This option uses messages
// from history and must be used with reasonable HistorySize and HistoryLifetime
// configuration.
Recover bool `json:"recover"`
// HistoryDropInactive enables an optimization where history is only saved for channels that have at
// least one active subscriber. This can give a huge memory saving, with only minor edgecases that are
// different from without it as noted on https://github.com/centrifugal/centrifugo/issues/50.
HistoryDropInactive bool `mapstructure:"history_drop_inactive" json:"history_drop_inactive"`
}