Closed devheitor closed 3 years ago
I think I solved the problem.. Soon, if any one want, I can send a pull request... just let me know
Right now I can't reproduce the error, but that doesn't have to mean anything. If you could make a pull request once you have fixed the error that would be great.
I've just released a few more minor changes to the code, updating the WhatsApp Web version among other things. Before that, I only got a message like this:
"1623777717.--0,["Cmd",{"type": "update"}]"
Maybe something has changed in the encoding of the messages?
HI JicuNull.. First of all, now that I have the opportunity, thank you for your project, it's great to have such implementation in Java, personally I think Java implementations are likely to be much more comprehensible and organized.
About the issue, sooner today I got the same message:
"1623777717.--0,["Cmd",{"type": "update"}]"
, but the bug I mentioned in this issue is not related to that.
As you said, updating whatsapp web version fix the "message problem", and I haven't identified any change in the encoding of the messages yet.. So, I think the message response from whatsapp websocket is really just a matter with the whatsapp web version sent in login request.
About the issue, as soon as possible I'll send the pull request. But, briefly, among other minor changes, the most important is that I reimplemented the function readNode() in BinaryDecoder class:
private String readNode() {
int readByte = readByte() & 0xff;
int listSize = readListSize(readByte); // Needs to cast to unsigned byte or int
int descrTag = readByte() & 0xff;
if(descrTag == BinaryConstants.Tags.STREAM_END) {
System.err.println("Unexpected stream end");
}
String descr = readString(descrTag);
if(listSize == 0 || descr == null) {
System.err.println("Invalid node");
}
String attrs = readAttributes((listSize - 1) >> 1);
String[] content = null;
if(listSize % 2 == 0) {
int tag = readByte() & 0xff; // Needs cast to unsigned byte / int
if(isListTag(tag)) {
content = readList(tag);
} else {
/*
* Handles messages with the message description only
* The byte array gets further processed using protobuf
*
*/
String decodedString = "";
byte [] decodedArray = null;
switch(tag) {
// Conversation messages
case BinaryConstants.Tags.BINARY_8:
decodedArray = readBytes(readByte() & 0xff);
break;
// Image, video, extended and rarely conversation messages
case BinaryConstants.Tags.BINARY_20:
decodedArray = readBytes(readInt20());
break;
// ?
case BinaryConstants.Tags.BINARY_32:
decodedArray = readBytes(readInt(4));
break;
default:
decodedString = readString(tag);
break;
}
if (descr.equals("message") && decodedArray != null) {
try {
String base64Decoded = Base64.getEncoder().encodeToString(
WebMessageInfo.parseFrom(decodedArray).toByteArray());
content = new String[] {"\"" + base64Decoded + "\""};
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
} else {
content = new String[] {"\"" + decodedString + "\""};
}
}
}
return "[\"" + descr + "\", " + attrs + ", " + Arrays.toString(content) + "]"; // Node
}
["Cmd",{"type":"update"}]
I am also getting this error even if I update WhatsApp version. 🤔
["Cmd",{"type":"update"}]
I am also getting this error even if I update WhatsApp version. 🤔
Are you sure you are specifying a commit version on Jitpack to use the latest updates? The last commit contains the updated WhatsApp web version:
implementation 'com.github.JicuNull:WhatsJava:f9b17488fc'
It's not about the app version on your phone.
Now, It works. Thanks.
Does anyone know what might be causing this exception all the time?
Is that critical? Are there tags that are not mapped, or is it something else, like a real bug?
On Baileys project this does not seem to happen, but I could not find the difference comparing both implementations. Any help?