summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/sromku/go-gitter/faye.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2016-11-02 16:12:43 +0100
committerWim <wim@42.be>2016-11-02 16:13:22 +0100
commit1b1589713592ec9d8f1945e4e61cac423e3e245e (patch)
treee92e23f00375f4bb71e0dcff541bf729f47147ac /vendor/github.com/sromku/go-gitter/faye.go
parent8e606e3cef5f36cff1a14c25fc1915ecfd30e054 (diff)
downloadmatterbridge-msglm-1b1589713592ec9d8f1945e4e61cac423e3e245e.tar.gz
matterbridge-msglm-1b1589713592ec9d8f1945e4e61cac423e3e245e.tar.bz2
matterbridge-msglm-1b1589713592ec9d8f1945e4e61cac423e3e245e.zip
Fix tight loop (gitter). Closes #68.
Diffstat (limited to 'vendor/github.com/sromku/go-gitter/faye.go')
-rw-r--r--vendor/github.com/sromku/go-gitter/faye.go70
1 files changed, 0 insertions, 70 deletions
diff --git a/vendor/github.com/sromku/go-gitter/faye.go b/vendor/github.com/sromku/go-gitter/faye.go
deleted file mode 100644
index dcd3e210..00000000
--- a/vendor/github.com/sromku/go-gitter/faye.go
+++ /dev/null
@@ -1,70 +0,0 @@
-package gitter
-
-import (
- "encoding/json"
- "fmt"
-
- "github.com/mrexodia/wray"
-)
-
-type Faye struct {
- endpoint string
- Event chan Event
- client *wray.FayeClient
- gitter *Gitter
-}
-
-func (gitter *Gitter) Faye(roomID string) *Faye {
- wray.RegisterTransports([]wray.Transport{
- &wray.HttpTransport{
- SendHook: func(data map[string]interface{}) {
- if channel, ok := data["channel"]; ok && channel == "/meta/handshake" {
- data["ext"] = map[string]interface{}{"token": gitter.config.token}
- }
- },
- },
- })
- return &Faye{
- endpoint: "/api/v1/rooms/" + roomID + "/chatMessages",
- Event: make(chan Event),
- client: wray.NewFayeClient(fayeBaseURL),
- gitter: gitter,
- }
-}
-
-func (faye *Faye) Listen() {
- defer faye.destroy()
-
- faye.client.Subscribe(faye.endpoint, false, func(message wray.Message) {
- dataBytes, err := json.Marshal(message.Data["model"])
- if err != nil {
- fmt.Printf("JSON Marshal error: %v\n", err)
- return
- }
- var gitterMessage Message
- err = json.Unmarshal(dataBytes, &gitterMessage)
- if err != nil {
- fmt.Printf("JSON Unmarshal error: %v\n", err)
- return
- }
- faye.Event <- Event{
- Data: &MessageReceived{
- Message: gitterMessage,
- },
- }
- })
-
- //TODO: this might be needed in the future
- /*go func() {
- for {
- faye.client.Publish("/api/v1/ping2", map[string]interface{}{"reason": "ping"})
- time.Sleep(60 * time.Second)
- }
- }()*/
-
- faye.client.Listen()
-}
-
-func (faye *Faye) destroy() {
- close(faye.Event)
-}