Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call support #560

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Call support #560

wants to merge 1 commit into from

Conversation

arugaz
Copy link
Contributor

@arugaz arugaz commented Mar 28, 2024

No description provided.

@arugaz
Copy link
Contributor Author

arugaz commented Mar 28, 2024

yes, need to test again havent commit yet

Copy link

@ahmedRSA ahmedRSA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i tested call reject and this is working
thank you for contribution

@gamersindo1223
Copy link

I've found a way to offer a call on dm

func (cli *Client) OfferCall(callTo types.JID, video bool) error {
	clientID := cli.getOwnJID()
	if clientID.IsEmpty() {
		return ErrNotLoggedIn
	}
	var offerLen uint8 = 6
	if video {
		offerLen++
	}
	callID := strings.ToUpper(hex.EncodeToString(random.Bytes(16)))
	plaintext, dsmPlaintext, err := marshalMessage(callTo, &waProto.Message{Call: &waProto.Call{CallKey: random.Bytes(32)}})
	if err != nil {
		return fmt.Errorf("failed to marshal call: %w", err)
	}
	destinationNode, includeIdentity := cli.encryptMessageForDevices(context.TODO(), []types.JID{clientID, callTo}, clientID, callID, plaintext, dsmPlaintext, nil)
	if includeIdentity {
		destinationNode = append(destinationNode, cli.makeDeviceIdentityNode())
	}
	offerContent := make([]waBinary.Node, 0, offerLen)
	offerContent = append(offerContent,
		waBinary.Node{Tag: "audio", Attrs: waBinary.Attrs{"enc": "opus", "rate": "16000"}},
		waBinary.Node{Tag: "audio", Attrs: waBinary.Attrs{"enc": "opus", "rate": "8000"}},
	)
	if video {
		offerContent = append(offerContent,
			waBinary.Node{Tag: "video", Attrs: waBinary.Attrs{"orientation": "0", "screen_width": "1080", "screen_height": "2340", "device_orientation": "0", "enc": "vp8", "dec": "vp8"}},
		)
	}
	offerContent = append(offerContent,
		waBinary.Node{Tag: "capability", Attrs: waBinary.Attrs{"ver": "1"}, Content: []byte{1, 4, 255, 131, 207, 4}},
		waBinary.Node{Tag: "destination", Content: destinationNode},
		waBinary.Node{Tag: "encopt", Attrs: waBinary.Attrs{"keygen": "2"}},
		waBinary.Node{Tag: "net", Attrs: waBinary.Attrs{"medium": "3"}},
	)
	return cli.sendNode(waBinary.Node{
		Tag:   "call",
		Attrs: waBinary.Attrs{"id": cli.GenerateMessageID(), "to": callTo},
		Content: []waBinary.Node{{
			Tag:     "offer",
			Attrs:   waBinary.Attrs{"call-id": callID, "call-creator": clientID},
			Content: offerContent,
		}},
	})
}```

@arugaz
Copy link
Contributor Author

arugaz commented Mar 30, 2024

yeah, thats what was done 4 months ago, im still looking for group call

@ahmedRSA
Copy link

ahmedRSA commented Apr 1, 2024

I've found a way to offer a call on dm

func (cli *Client) OfferCall(callTo types.JID, video bool) error {
	clientID := cli.getOwnJID()
	if clientID.IsEmpty() {
		return ErrNotLoggedIn
	}
	var offerLen uint8 = 6
	if video {
		offerLen++
	}
	callID := strings.ToUpper(hex.EncodeToString(random.Bytes(16)))
	plaintext, dsmPlaintext, err := marshalMessage(callTo, &waProto.Message{Call: &waProto.Call{CallKey: random.Bytes(32)}})
	if err != nil {
		return fmt.Errorf("failed to marshal call: %w", err)
	}
	destinationNode, includeIdentity := cli.encryptMessageForDevices(context.TODO(), []types.JID{clientID, callTo}, clientID, callID, plaintext, dsmPlaintext, nil)
	if includeIdentity {
		destinationNode = append(destinationNode, cli.makeDeviceIdentityNode())
	}
	offerContent := make([]waBinary.Node, 0, offerLen)
	offerContent = append(offerContent,
		waBinary.Node{Tag: "audio", Attrs: waBinary.Attrs{"enc": "opus", "rate": "16000"}},
		waBinary.Node{Tag: "audio", Attrs: waBinary.Attrs{"enc": "opus", "rate": "8000"}},
	)
	if video {
		offerContent = append(offerContent,
			waBinary.Node{Tag: "video", Attrs: waBinary.Attrs{"orientation": "0", "screen_width": "1080", "screen_height": "2340", "device_orientation": "0", "enc": "vp8", "dec": "vp8"}},
		)
	}
	offerContent = append(offerContent,
		waBinary.Node{Tag: "capability", Attrs: waBinary.Attrs{"ver": "1"}, Content: []byte{1, 4, 255, 131, 207, 4}},
		waBinary.Node{Tag: "destination", Content: destinationNode},
		waBinary.Node{Tag: "encopt", Attrs: waBinary.Attrs{"keygen": "2"}},
		waBinary.Node{Tag: "net", Attrs: waBinary.Attrs{"medium": "3"}},
	)
	return cli.sendNode(waBinary.Node{
		Tag:   "call",
		Attrs: waBinary.Attrs{"id": cli.GenerateMessageID(), "to": callTo},
		Content: []waBinary.Node{{
			Tag:     "offer",
			Attrs:   waBinary.Attrs{"call-id": callID, "call-creator": clientID},
			Content: offerContent,
		}},
	})
}```

hi is this possible to send call for only like 5 second
or X second 1, 2second ?

@gamersindo1223
Copy link

no Idea

@brunoaduarte
Copy link

brunoaduarte commented Apr 26, 2024

I've found a way to offer a call on dm

func (cli *Client) OfferCall(callTo types.JID, video bool) error {
	clientID := cli.getOwnJID()
	if clientID.IsEmpty() {
		return ErrNotLoggedIn
	}
	var offerLen uint8 = 6
	if video {
		offerLen++
	}
	callID := strings.ToUpper(hex.EncodeToString(random.Bytes(16)))
	plaintext, dsmPlaintext, err := marshalMessage(callTo, &waProto.Message{Call: &waProto.Call{CallKey: random.Bytes(32)}})
	if err != nil {
		return fmt.Errorf("failed to marshal call: %w", err)
	}
	destinationNode, includeIdentity := cli.encryptMessageForDevices(context.TODO(), []types.JID{clientID, callTo}, clientID, callID, plaintext, dsmPlaintext, nil)
	if includeIdentity {
		destinationNode = append(destinationNode, cli.makeDeviceIdentityNode())
	}
	offerContent := make([]waBinary.Node, 0, offerLen)
	offerContent = append(offerContent,
		waBinary.Node{Tag: "audio", Attrs: waBinary.Attrs{"enc": "opus", "rate": "16000"}},
		waBinary.Node{Tag: "audio", Attrs: waBinary.Attrs{"enc": "opus", "rate": "8000"}},
	)
	if video {
		offerContent = append(offerContent,
			waBinary.Node{Tag: "video", Attrs: waBinary.Attrs{"orientation": "0", "screen_width": "1080", "screen_height": "2340", "device_orientation": "0", "enc": "vp8", "dec": "vp8"}},
		)
	}
	offerContent = append(offerContent,
		waBinary.Node{Tag: "capability", Attrs: waBinary.Attrs{"ver": "1"}, Content: []byte{1, 4, 255, 131, 207, 4}},
		waBinary.Node{Tag: "destination", Content: destinationNode},
		waBinary.Node{Tag: "encopt", Attrs: waBinary.Attrs{"keygen": "2"}},
		waBinary.Node{Tag: "net", Attrs: waBinary.Attrs{"medium": "3"}},
	)
	return cli.sendNode(waBinary.Node{
		Tag:   "call",
		Attrs: waBinary.Attrs{"id": cli.GenerateMessageID(), "to": callTo},
		Content: []waBinary.Node{{
			Tag:     "offer",
			Attrs:   waBinary.Attrs{"call-id": callID, "call-creator": clientID},
			Content: offerContent,
		}},
	})
}```

That doesn't work

My client sends the package but nothing returns from the server

14:10:08.046 [Client/Send DEBUG]
<call id="3EB0096894E2F3735674B5" to="xxxxxxxxx@s.whatsapp.net">
  <offer call-creator="yyyyyyyyyy:18@s.whatsapp.net" call-id="585786509F7115EF059ED9AE799F23F8">
    <audio enc="opus" rate="16000"/>
    <audio enc="opus" rate="8000"/>
    <capability ver="1">0104ff83cf04</capability>
    <destination>
      <to jid="xxxxxxxxx@s.whatsapp.net"><enc type="pkmsg" v="2"><!-- 184 bytes --></enc></to>
      <device-identity><!-- 186 bytes --></device-identity>
    </destination>
    <encopt keygen="2"/>
    <net medium="3"/>
  </offer>
</call>

@ahmedRSA
Copy link

ahmedRSA commented May 1, 2024

this stop working for some reason anyones having asame problem ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants