-
Notifications
You must be signed in to change notification settings - Fork 6
/
messenger.go
39 lines (33 loc) · 1.17 KB
/
messenger.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
/*
Package messageServer implements a general purpose messaging platform based on the gorilla
websocket implementation. The platform is similar to other messaging platforms like pubnub,
in that it is channel based.
This means that you can replace it with the distributed messaging platform of your choice as your app grows.
See the web/assets/js/goradd-ws.js for the client side.
*/
package messageServer
import (
"encoding/json"
"github.com/goradd/html5tag"
"github.com/goradd/goradd/pkg/log"
)
var Messenger MessengerI
type MessengerI interface {
// JavascriptInit returns javascript that needs to be called when a page starts to initialize
JavascriptInit() string
// Send sends a message to the given channel
Send(channel string, message string)
// JavascriptFiles returns file names and attributes used to embed the need javascript files for your messenger
JavascriptFiles() map[string]html5tag.Attributes
}
// Send sends a message to the given channel via the current messenger
func Send(channel string, message interface{}) {
msg, err := json.Marshal(message)
if err != nil {
log.Debug(err)
return
}
if Messenger != nil {
Messenger.Send(channel, string(msg))
}
}