48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
|
package reach
|
||
|
|
||
|
import (
|
||
|
"sync"
|
||
|
|
||
|
"forge.cadoles.com/Pyxis/golang-socketio"
|
||
|
"github.com/pkg/errors"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
eventIsReceiverUpgradeAvailable = "is receiver upgrade available"
|
||
|
eventReceiverUpgradeAvailable = "receiver upgrade available"
|
||
|
)
|
||
|
|
||
|
type receiverUpgreAvailable struct {
|
||
|
Available bool `json:"available"`
|
||
|
Running bool `json:"running"`
|
||
|
}
|
||
|
|
||
|
// ReceiverUpgradeAvailable checks if an upgrade is avaialable/running for the ReachRS module
|
||
|
func (c *Client) ReceiverUpgradeAvailable() (available bool, running bool, err error) {
|
||
|
|
||
|
var wg sync.WaitGroup
|
||
|
|
||
|
wg.Add(1)
|
||
|
|
||
|
err = c.conn.On(eventReceiverUpgradeAvailable, func(h *gosocketio.Channel, up *receiverUpgreAvailable) {
|
||
|
available = up.Available
|
||
|
running = up.Running
|
||
|
c.conn.Off(eventReceiverUpgradeAvailable)
|
||
|
wg.Done()
|
||
|
})
|
||
|
if err != nil {
|
||
|
return false, false, errors.Wrapf(err, "error while binding to '%s' event", eventReceiverUpgradeAvailable)
|
||
|
}
|
||
|
|
||
|
c.logf("sending '%s' event", eventIsReceiverUpgradeAvailable)
|
||
|
if err = c.conn.Emit(eventIsReceiverUpgradeAvailable, nil); err != nil {
|
||
|
return false, false, errors.Wrapf(err, "error while emitting '%s' event", eventIsReceiverUpgradeAvailable)
|
||
|
}
|
||
|
c.logf("'%s' event sent", eventIsReceiverUpgradeAvailable)
|
||
|
|
||
|
wg.Wait()
|
||
|
|
||
|
return available, running, err
|
||
|
|
||
|
}
|