48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package reach
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"forge.cadoles.com/Pyxis/golang-socketio"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
const (
|
|
eventGetReachViewVersion = "get reachview version"
|
|
eventReachViewVersionResults = "current reachview version"
|
|
)
|
|
|
|
type reachViewVersion struct {
|
|
Version string `json:"version"`
|
|
}
|
|
|
|
// ReachViewVersion returns the ReachRS module ReachView version
|
|
func (c *Client) ReachViewVersion() (string, error) {
|
|
|
|
var err error
|
|
var version string
|
|
var wg sync.WaitGroup
|
|
|
|
wg.Add(1)
|
|
|
|
err = c.conn.On(eventReachViewVersionResults, func(h *gosocketio.Channel, rv *reachViewVersion) {
|
|
version = rv.Version
|
|
c.conn.Off(eventReachViewVersionResults)
|
|
wg.Done()
|
|
})
|
|
if err != nil {
|
|
return "", errors.Wrapf(err, "error while binding to '%s' event", eventReachViewVersionResults)
|
|
}
|
|
|
|
c.logf("sending '%s' event", eventGetReachViewVersion)
|
|
if err = c.conn.Emit(eventGetReachViewVersion, nil); err != nil {
|
|
return "", errors.Wrapf(err, "error while emitting '%s' event", eventGetReachViewVersion)
|
|
}
|
|
c.logf("'%s' event sent", eventGetReachViewVersion)
|
|
|
|
wg.Wait()
|
|
|
|
return version, err
|
|
|
|
}
|