summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/gopackage/ddp/ddp.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2019-02-15 18:20:32 +0100
committerGitHub <noreply@github.com>2019-02-15 18:20:32 +0100
commit716751cf7685471bbc969e19fe26f23e66f3c0b4 (patch)
tree6db2350f28a76ae6e1cf7c3cea7263503057d82f /vendor/github.com/gopackage/ddp/ddp.go
parent077b818d82a98855d5577f4f9de5d2b2d2cc6a50 (diff)
parent6ebd5cbbd8a941e0bc5f99f0d8e99cfd1d8ac0d7 (diff)
downloadmatterbridge-msglm-716751cf7685471bbc969e19fe26f23e66f3c0b4.tar.gz
matterbridge-msglm-716751cf7685471bbc969e19fe26f23e66f3c0b4.tar.bz2
matterbridge-msglm-716751cf7685471bbc969e19fe26f23e66f3c0b4.zip
Refactor and update RocketChat bridge (#707)
* Add support for editing/deleting messages * Add support for uploading files * Add support for avatars * Use the Rocket.Chat.Go.SDK * Use the rest and streaming api
Diffstat (limited to 'vendor/github.com/gopackage/ddp/ddp.go')
-rw-r--r--vendor/github.com/gopackage/ddp/ddp.go79
1 files changed, 79 insertions, 0 deletions
diff --git a/vendor/github.com/gopackage/ddp/ddp.go b/vendor/github.com/gopackage/ddp/ddp.go
new file mode 100644
index 00000000..910adafd
--- /dev/null
+++ b/vendor/github.com/gopackage/ddp/ddp.go
@@ -0,0 +1,79 @@
+// Package ddp implements the MeteorJS DDP protocol over websockets. Fallback
+// to longpolling is NOT supported (and is not planned on ever being supported
+// by this library). We will try to model the library after `net/http` - right
+// now the library is barebones and doesn't provide the pluggability of http.
+// However, that's the goal for the package eventually.
+package ddp
+
+import (
+ "fmt"
+ "log"
+ "sync"
+ "time"
+)
+
+// debugLog is true if we should log debugging information about the connection
+var debugLog = true
+
+// The main file contains common utility types.
+
+// -------------------------------------------------------------------
+
+// idManager provides simple incrementing IDs for ddp messages.
+type idManager struct {
+ // nextID is the next ID for API calls
+ nextID uint64
+ // idMutex is a mutex to protect ID updates
+ idMutex *sync.Mutex
+}
+
+// newidManager creates a new instance and sets up resources.
+func newidManager() *idManager {
+ return &idManager{idMutex: new(sync.Mutex)}
+}
+
+// newID issues a new ID for use in calls.
+func (id *idManager) newID() string {
+ id.idMutex.Lock()
+ next := id.nextID
+ id.nextID++
+ id.idMutex.Unlock()
+ return fmt.Sprintf("%x", next)
+}
+
+// -------------------------------------------------------------------
+
+// pingTracker tracks in-flight pings.
+type pingTracker struct {
+ handler func(error)
+ timeout time.Duration
+ timer *time.Timer
+}
+
+// -------------------------------------------------------------------
+
+// Call represents an active RPC call.
+type Call struct {
+ ID string // The uuid for this method call
+ ServiceMethod string // The name of the service and method to call.
+ Args interface{} // The argument to the function (*struct).
+ Reply interface{} // The reply from the function (*struct).
+ Error error // After completion, the error status.
+ Done chan *Call // Strobes when call is complete.
+ Owner *Client // Client that owns the method call
+}
+
+// done removes the call from any owners and strobes the done channel with itself.
+func (call *Call) done() {
+ delete(call.Owner.calls, call.ID)
+ select {
+ case call.Done <- call:
+ // ok
+ default:
+ // We don't want to block here. It is the caller's responsibility to make
+ // sure the channel has enough buffer space. See comment in Go().
+ if debugLog {
+ log.Println("rpc: discarding Call reply due to insufficient Done chan capacity")
+ }
+ }
+}