pair: parse client props
This commit is contained in:
@@ -120,6 +120,7 @@ func (cli *Client) makeQRData(ref []byte, clientType PairClientType) string {
|
||||
}
|
||||
|
||||
func (cli *Client) handlePairSuccess(ctx context.Context, node *waBinary.Node) {
|
||||
cli.serverTimeOffset.Store(int64(node.AttrGetter().UnixTime("t").Sub(time.Now().Round(time.Second))))
|
||||
id := node.Attrs["id"].(string)
|
||||
pairSuccess := node.GetChildByTag("pair-success")
|
||||
|
||||
@@ -128,18 +129,22 @@ func (cli *Client) handlePairSuccess(ctx context.Context, node *waBinary.Node) {
|
||||
jid, _ := pairSuccess.GetChildByTag("device").Attrs["jid"].(types.JID)
|
||||
lid, _ := pairSuccess.GetChildByTag("device").Attrs["lid"].(types.JID)
|
||||
platform, _ := pairSuccess.GetChildByTag("platform").Attrs["name"].(string)
|
||||
cli.serverTimeOffset.Store(int64(node.AttrGetter().UnixTime("t").Sub(time.Now().Round(time.Second))))
|
||||
clientPropsBytes, _ := pairSuccess.GetChildByTag("client-props").Content.([]byte)
|
||||
var props waCompanionReg.ClientPairingProps
|
||||
if err := proto.Unmarshal(clientPropsBytes, &props); err != nil {
|
||||
cli.Log.Warnf("Failed to parse client pairing props: %v", err)
|
||||
}
|
||||
|
||||
go func() {
|
||||
err := cli.handlePair(ctx, deviceIdentityBytes, id, businessName, platform, jid, lid)
|
||||
if err != nil {
|
||||
cli.Log.Errorf("Failed to pair device: %v", err)
|
||||
cli.Disconnect()
|
||||
cli.dispatchEvent(&events.PairError{ID: jid, LID: lid, BusinessName: businessName, Platform: platform, Error: err})
|
||||
cli.dispatchEvent(&events.PairError{ID: jid, LID: lid, BusinessName: businessName, Platform: platform, Props: &props, Error: err})
|
||||
} else {
|
||||
cli.Log.Infof("Successfully paired %s", cli.Store.ID)
|
||||
go cli.sendUnifiedSession()
|
||||
cli.dispatchEvent(&events.PairSuccess{ID: jid, LID: lid, BusinessName: businessName, Platform: platform})
|
||||
cli.dispatchEvent(&events.PairSuccess{ID: jid, LID: lid, BusinessName: businessName, Platform: platform, Props: &props})
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
armadillo "go.mau.fi/whatsmeow/proto"
|
||||
"go.mau.fi/whatsmeow/proto/instamadilloTransportPayload"
|
||||
"go.mau.fi/whatsmeow/proto/waArmadilloApplication"
|
||||
"go.mau.fi/whatsmeow/proto/waCompanionReg"
|
||||
"go.mau.fi/whatsmeow/proto/waConsumerApplication"
|
||||
"go.mau.fi/whatsmeow/proto/waE2E"
|
||||
"go.mau.fi/whatsmeow/proto/waHistorySync"
|
||||
@@ -48,6 +49,7 @@ type PairSuccess struct {
|
||||
LID types.JID
|
||||
BusinessName string
|
||||
Platform string
|
||||
Props *waCompanionReg.ClientPairingProps
|
||||
}
|
||||
|
||||
// PairError is emitted when a pair-success event is received from the server, but finishing the pairing locally fails.
|
||||
@@ -56,6 +58,7 @@ type PairError struct {
|
||||
LID types.JID
|
||||
BusinessName string
|
||||
Platform string
|
||||
Props *waCompanionReg.ClientPairingProps
|
||||
Error error
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user