Skip to content

Commit

Permalink
Merge pull request #27 from juzibot/fix/mp3-duration
Browse files Browse the repository at this point in the history
Fix/mp3 duration
  • Loading branch information
hcfw007 authored Dec 20, 2024
2 parents 8e5be8f + f9bcb30 commit 935725c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@juzi/whatsapp-web.js",
"version": "1.21.12",
"version": "1.21.13",
"description": "Library for interacting with the WhatsApp Web API ",
"main": "./index.js",
"typings": "./index.d.ts",
Expand Down
3 changes: 3 additions & 0 deletions src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ class Client extends EventEmitter {
await this.pupPage.evaluate(ExposeLegacyAuthStore, moduleRaid.toString());
}

// bridge browser log
this.page.on('console', msg => console.log('PUPPETEER PAGE LOG:', msg.text()));

const needAuthentication = await this.pupPage.evaluate(async () => {
let state = window.AuthStore.AppState.state;

Expand Down
19 changes: 19 additions & 0 deletions src/util/Injected/Store.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,23 @@ exports.ExposeStore = () => {

window.injectToFunction({ module: 'WAWebE2EProtoUtils', function: 'typeAttributeFromProtobuf' }, (func, ...args) => { const [proto] = args; return proto.locationMessage || proto.groupInviteMessage ? 'text' : func(...args); });

window.injectToFunction({ module: 'WAWebFileUtils', function: 'getAudioDuration'}, (func, ...args) => {
const [file] = args;
let src;
let audio;
return new Promise((resolve) => {
audio = document.createElement('audio');
audio.addEventListener('loadeddata', resolve);
audio.addEventListener('error', (e) => {{
console.error(e);
resolve(5);
}});
src = URL.createObjectURL(file);
audio.src = src;
}).then(() => {
return ~~audio.seekable.end(0);
}).finally(() => {
src && URL.revokeObjectURL(src);
});
});
};

0 comments on commit 935725c

Please sign in to comment.