-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.go
82 lines (69 loc) · 1.88 KB
/
events.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* Copyright (c) 2019 Zenichi Amano
*
* This file is part of go-push-receiver, which is MIT licensed.
* See http://opensource.org/licenses/MIT
*/
package pushreceiver
import (
"time"
pb "github.com/beeper/push-receiver/pb/mcs"
)
// Event type.
type Event interface{}
// ConnectedEvent is connection event.
type ConnectedEvent struct {
ServerTimestamp int64
}
// RetryEvent is disconnect event.
type RetryEvent struct {
ErrorObj error
RetryAfter time.Duration
}
// DisconnectedEvent is disconnect event.
type DisconnectedEvent struct {
ErrorObj error
}
// HeartbeatEvent is send/received heartbeat event.
type HeartbeatEvent struct {
Send bool
Ack bool
Status int64
LastStreamIDReceived int32
}
// MessageEvent is receive message event.
type MessageEvent struct {
PersistentID string `json:"persistentId"`
From string `json:"from"`
To string `json:"to"`
TTL int32 `json:"ttl"`
Sent int64 `json:"sent"`
AppData []*pb.AppData `json:"app_data"`
Token string `json:"token"`
RegID string `json:"reg_id"`
RawData []byte `json:"raw_data"`
AppID string `json:"app_id"`
}
func newMessageEvent(data *pb.DataMessageStanza) *MessageEvent {
return &MessageEvent{
PersistentID: data.GetPersistentId(),
From: data.GetFrom(),
To: data.GetTo(),
TTL: data.GetTtl(),
Sent: data.GetSent(),
AppData: data.GetAppData(),
Token: data.GetToken(),
RegID: data.GetRegId(),
RawData: data.GetRawData(),
AppID: data.GetAppID(),
}
}
type StreamAck struct{}
// HeartbeatError is send heartbeat error.
type HeartbeatError struct {
ErrorObj error
}
// UnauthorizedError is unauthorization error.
type UnauthorizedError struct {
ErrorObj error
}