|
@@ -48,7 +48,12 @@ func NewClient(address string, id string, key string) (*FhoClient, error) {
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
- return &FhoClient{id: id, key: key, dataService: pb.NewDataServiceClient(conn)}, nil
|
|
|
+ client := &FhoClient{id: id, key: key, dataService: pb.NewDataServiceClient(conn)}
|
|
|
+ go func(c *FhoClient) {
|
|
|
+ Heartbeat(c, func(isConnected bool) {})
|
|
|
+ }(client)
|
|
|
+
|
|
|
+ return client, nil
|
|
|
}
|
|
|
|
|
|
func (f *FhoClient) query(object string, updatedAfter time.Time) ([]map[string]interface{}, error) {
|
|
@@ -148,6 +153,7 @@ func Heartbeat(c *FhoClient, fn func(isConnected bool)) error {
|
|
|
start:
|
|
|
_, err := s.stream.Recv()
|
|
|
if err != nil {
|
|
|
+ log.Println("stream error:", err)
|
|
|
if s.isConnected || !isInit {
|
|
|
fn(false)
|
|
|
s.isConnected = false
|