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 (u *Updater) ReachViewVersion() (string, error) { var err error var version string var wg sync.WaitGroup wg.Add(1) err = u.conn.On(eventReachViewVersionResults, func(h *gosocketio.Channel, rv *reachViewVersion) { version = rv.Version u.conn.Off(eventReachViewVersionResults) wg.Done() }) if err != nil { return "", errors.Wrapf(err, "error while binding to '%s' event", eventReachViewVersionResults) } u.logf("sending '%s' event", eventGetReachViewVersion) if err = u.conn.Emit(eventGetReachViewVersion, nil); err != nil { return "", errors.Wrapf(err, "error while emitting '%s' event", eventGetReachViewVersion) } u.logf("'%s' event sent", eventGetReachViewVersion) wg.Wait() u.logf("reachview version result: %v", version) return version, err }