This repository has been archived on 2024-08-02. You can view files and clone it, but cannot push or open issues or pull requests.
2018-09-19 15:35:56 +02:00
|
|
|
package reach
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"forge.cadoles.com/Pyxis/golang-socketio"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
eventGetTimeSyncStatus = "get time sync status"
|
|
|
|
eventTimeSyncResults = "time sync status"
|
|
|
|
)
|
|
|
|
|
|
|
|
type timeSyncStatus struct {
|
|
|
|
Status bool `json:"status"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// TimeSyncStatus returns the ReachRS module time sync status
|
|
|
|
func (c *Client) TimeSyncStatus() (bool, error) {
|
|
|
|
|
|
|
|
var err error
|
|
|
|
var synced bool
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
|
|
|
|
err = c.conn.On(eventTimeSyncResults, func(h *gosocketio.Channel, st *timeSyncStatus) {
|
|
|
|
synced = st.Status
|
|
|
|
c.conn.Off(eventTimeSyncResults)
|
|
|
|
wg.Done()
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return false, errors.Wrapf(err, "error while binding to '%s' event", eventTimeSyncResults)
|
|
|
|
}
|
|
|
|
|
|
|
|
c.logf("sending '%s' event", eventGetTimeSyncStatus)
|
|
|
|
if err = c.conn.Emit(eventGetTimeSyncStatus, nil); err != nil {
|
|
|
|
return false, errors.Wrapf(err, "error while emitting '%s' event", eventGetTimeSyncStatus)
|
|
|
|
}
|
|
|
|
c.logf("'%s' event sent", eventGetTimeSyncStatus)
|
|
|
|
|
|
|
|
wg.Wait()
|
|
|
|
|
2018-09-19 15:54:11 +02:00
|
|
|
c.logf("time sync result: %v", synced)
|
|
|
|
|
2018-09-19 15:35:56 +02:00
|
|
|
return synced, err
|
|
|
|
|
|
|
|
}
|