Skip to content

Commit 7cc1230

Browse files
committed
connector: properly send bridge states
1 parent 7cef692 commit 7cc1230

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

pkg/connector/client.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,18 @@ func NewClient(userLogin *bridgev2.UserLogin, client *gchatmeow.Client) *GChatCl
4141
}
4242

4343
func (c *GChatClient) Connect(ctx context.Context) {
44-
c.client.OnConnect.AddObserver(func(interface{}) { c.onConnect(ctx) })
45-
c.client.OnStreamEvent.AddObserver(func(evt interface{}) { c.onStreamEvent(ctx, evt) })
44+
c.client.OnConnect.AddObserver(func(any) {
45+
c.userLogin.BridgeState.Send(status.BridgeState{
46+
StateEvent: status.StateConnected,
47+
})
48+
c.onConnect(ctx)
49+
})
50+
c.client.OnDisconnect.AddObserver(func(any) {
51+
c.userLogin.BridgeState.Send(status.BridgeState{
52+
StateEvent: status.StateTransientDisconnect,
53+
})
54+
})
55+
c.client.OnStreamEvent.AddObserver(func(evt any) { c.onStreamEvent(ctx, evt) })
4656

4757
err := c.client.Connect(ctx, time.Duration(90)*time.Minute)
4858
if err != nil {

pkg/gchatmeow/channel.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ type Channel struct {
5151
ofs int
5252
rid int
5353

54-
OnConnect *Event
54+
// Fired when receiving data from the channel for the first time. This is only ever fired once.
55+
OnConnect *Event
56+
// Fired when a connection is re-established. This can be fired multiple times.
5557
OnReconnect *Event
5658
OnDisconnect *Event
5759
OnReceiveArray *Event

0 commit comments

Comments
 (0)