-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathextension_pubsub.go
74 lines (61 loc) · 2.52 KB
/
extension_pubsub.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
package helix
// PublishType The Pub/Sub broadcast type
type ExtensionPubSubPublishType string
// Types of Pub/Sub Permissions or targets
const (
ExtensionPubSubGenericPublish ExtensionPubSubPublishType = "*"
ExtensionPubSubBroadcastPublish ExtensionPubSubPublishType = "broadcast"
ExtensionPubSubGlobalPublish ExtensionPubSubPublishType = "global"
)
func (p ExtensionPubSubPublishType) String() string {
return string(p)
}
func (c *Client) createExtensionPubSubWhisper(opaqueId string) ExtensionPubSubPublishType {
return ExtensionPubSubPublishType("whisper-" + opaqueId)
}
// FormWhisperSendPubSubPermissions create the pubsub permissions
// for publishing a whisper message type
func (c *Client) FormWhisperSendPubSubPermissions(opaqueId string) *PubSubPermissions {
return &PubSubPermissions{
Send: []ExtensionPubSubPublishType{c.createExtensionPubSubWhisper(opaqueId)},
}
}
// FormBroadcastSendPubSubPermissions create the pubsub permissions
// for publishing a broadcast message type
func (c *Client) FormBroadcastSendPubSubPermissions() *PubSubPermissions {
return &PubSubPermissions{
Send: []ExtensionPubSubPublishType{ExtensionPubSubBroadcastPublish},
}
}
// FormGlobalSendPubSubPermissions create the pubsub permissions
// for publishing a global targeted message
func (c *Client) FormGlobalSendPubSubPermissions() *PubSubPermissions {
return &PubSubPermissions{
Send: []ExtensionPubSubPublishType{ExtensionPubSubGlobalPublish},
}
}
// FormGenericPubSubPermissions create the pubsub permissions
// for publishing to message for any target type
func (c *Client) FormGenericPubSubPermissions() *PubSubPermissions {
return &PubSubPermissions{
Send: []ExtensionPubSubPublishType{ExtensionPubSubGenericPublish},
}
}
type ExtensionSendPubSubMessageParams struct {
BroadcasterID string `json:"broadcaster_id"`
Message string `json:"message"`
Target []ExtensionPubSubPublishType `json:"target"`
IsGlobalBroadcast bool `json:"is_global_broadcast"`
}
type ExtensionSendPubSubMessageResponse struct {
ResponseCommon
}
func (c *Client) SendExtensionPubSubMessage(params *ExtensionSendPubSubMessageParams) (*ExtensionSendPubSubMessageResponse, error) {
resp, err := c.postAsJSON("/extensions/pubsub", &ExtensionSendPubSubMessageResponse{}, params)
if err != nil {
return nil, err
}
sndExtPubSubMsgRsp := &ExtensionSendPubSubMessageResponse{}
resp.HydrateResponseCommon(&sndExtPubSubMsgRsp.ResponseCommon)
return sndExtPubSubMsgRsp, nil
}