@nerxa/socketon 0.0.0-stage → 1.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/EXPERIMENTAL.md +350 -0
- package/LICENSE +24 -0
- package/README.md +6317 -2
- package/WAProto/index.d.ts +17301 -0
- package/WAProto/index.js +125088 -0
- package/engine-requirements.js +14 -0
- package/package.json +100 -4
- package/src/Defaults/index.d.ts +152 -0
- package/src/Defaults/index.js +164 -0
- package/src/MessageBuilder/bot-signature.d.ts +22 -0
- package/src/MessageBuilder/bot-signature.js +122 -0
- package/src/MessageBuilder/extras.d.ts +449 -0
- package/src/MessageBuilder/extras.js +1356 -0
- package/src/MessageBuilder/index.d.ts +210 -0
- package/src/MessageBuilder/index.js +3594 -0
- package/src/MessageBuilder/metaai.d.ts +438 -0
- package/src/MessageBuilder/metaai.js +890 -0
- package/src/Signal/Group/ciphertext-message.d.ts +9 -0
- package/src/Signal/Group/ciphertext-message.js +11 -0
- package/src/Signal/Group/group-session-builder.d.ts +7 -0
- package/src/Signal/Group/group-session-builder.js +27 -0
- package/src/Signal/Group/group_cipher.d.ts +11 -0
- package/src/Signal/Group/group_cipher.js +78 -0
- package/src/Signal/Group/index.d.ts +11 -0
- package/src/Signal/Group/index.js +11 -0
- package/src/Signal/Group/keyhelper.d.ts +6 -0
- package/src/Signal/Group/keyhelper.js +17 -0
- package/src/Signal/Group/sender-chain-key.d.ts +13 -0
- package/src/Signal/Group/sender-chain-key.js +25 -0
- package/src/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/src/Signal/Group/sender-key-distribution-message.js +62 -0
- package/src/Signal/Group/sender-key-message.d.ts +18 -0
- package/src/Signal/Group/sender-key-message.js +65 -0
- package/src/Signal/Group/sender-key-name.d.ts +11 -0
- package/src/Signal/Group/sender-key-name.js +47 -0
- package/src/Signal/Group/sender-key-record.d.ts +12 -0
- package/src/Signal/Group/sender-key-record.js +40 -0
- package/src/Signal/Group/sender-key-state.d.ts +16 -0
- package/src/Signal/Group/sender-key-state.js +83 -0
- package/src/Signal/Group/sender-message-key.d.ts +11 -0
- package/src/Signal/Group/sender-message-key.js +25 -0
- package/src/Signal/libsignal.d.ts +54 -0
- package/src/Signal/libsignal.js +427 -0
- package/src/Signal/lid-mapping.d.ts +20 -0
- package/src/Signal/lid-mapping.js +274 -0
- package/src/Socket/Client/index.d.ts +2 -0
- package/src/Socket/Client/index.js +3 -0
- package/src/Socket/Client/tcp.js +177 -0
- package/src/Socket/Client/types.d.ts +5 -0
- package/src/Socket/Client/types.js +9 -0
- package/src/Socket/Client/websocket.d.ts +12 -0
- package/src/Socket/Client/websocket.js +53 -0
- package/src/Socket/business.d.ts +431 -0
- package/src/Socket/business.js +379 -0
- package/src/Socket/chats.d.ts +247 -0
- package/src/Socket/chats.js +1484 -0
- package/src/Socket/communities.d.ts +598 -0
- package/src/Socket/communities.js +421 -0
- package/src/Socket/email.js +145 -0
- package/src/Socket/groups.d.ts +298 -0
- package/src/Socket/groups.js +339 -0
- package/src/Socket/index.d.ts +581 -0
- package/src/Socket/index.js +37 -0
- package/src/Socket/messages-recv.d.ts +370 -0
- package/src/Socket/messages-recv.js +1864 -0
- package/src/Socket/messages-send.d.ts +390 -0
- package/src/Socket/messages-send.js +1574 -0
- package/src/Socket/mex.d.ts +1 -0
- package/src/Socket/mex.js +44 -0
- package/src/Socket/mobile-builders.js +72 -0
- package/src/Socket/mobile.js +424 -0
- package/src/Socket/newsletter.d.ts +468 -0
- package/src/Socket/newsletter.js +671 -0
- package/src/Socket/socket.d.ts +77 -0
- package/src/Socket/socket.js +1106 -0
- package/src/Store/index.d.ts +3 -0
- package/src/Store/index.js +3 -0
- package/src/Store/make-in-memory-store.d.ts +62 -0
- package/src/Store/make-in-memory-store.js +396 -0
- package/src/Store/make-ordered-dictionary.d.ts +12 -0
- package/src/Store/make-ordered-dictionary.js +78 -0
- package/src/Store/object-repository.d.ts +10 -0
- package/src/Store/object-repository.js +23 -0
- package/src/Types/Auth.d.ts +1 -0
- package/src/Types/Auth.js +1 -0
- package/src/Types/Bussines.d.ts +1 -0
- package/src/Types/Bussines.js +1 -0
- package/src/Types/Call.d.ts +1 -0
- package/src/Types/Call.js +1 -0
- package/src/Types/Chat.d.ts +2 -0
- package/src/Types/Chat.js +24 -0
- package/src/Types/Contact.d.ts +1 -0
- package/src/Types/Contact.js +1 -0
- package/src/Types/Events.d.ts +1 -0
- package/src/Types/Events.js +0 -0
- package/src/Types/GroupMetadata.d.ts +5 -0
- package/src/Types/GroupMetadata.js +6 -0
- package/src/Types/Label.d.ts +2 -0
- package/src/Types/Label.js +24 -0
- package/src/Types/LabelAssociation.d.ts +2 -0
- package/src/Types/LabelAssociation.js +6 -0
- package/src/Types/Message.d.ts +13 -0
- package/src/Types/Message.js +23 -0
- package/src/Types/Mex.d.ts +2 -0
- package/src/Types/Mex.js +95 -0
- package/src/Types/Product.d.ts +1 -0
- package/src/Types/Product.js +1 -0
- package/src/Types/Signal.d.ts +1 -0
- package/src/Types/Signal.js +0 -0
- package/src/Types/Socket.d.ts +1 -0
- package/src/Types/Socket.js +0 -0
- package/src/Types/State.d.ts +5 -0
- package/src/Types/State.js +54 -0
- package/src/Types/USync.d.ts +1 -0
- package/src/Types/USync.js +0 -0
- package/src/Types/index.d.ts +13 -0
- package/src/Types/index.js +25 -0
- package/src/Utils/auth-store.d.ts +29 -0
- package/src/Utils/auth-store.js +76 -0
- package/src/Utils/auth-utils.d.ts +58 -0
- package/src/Utils/auth-utils.js +273 -0
- package/src/Utils/browser-utils.d.ts +9 -0
- package/src/Utils/browser-utils.js +28 -0
- package/src/Utils/business.d.ts +49 -0
- package/src/Utils/business.js +226 -0
- package/src/Utils/chat-utils.d.ts +408 -0
- package/src/Utils/chat-utils.js +846 -0
- package/src/Utils/companion-reg-client-utils.d.ts +4 -0
- package/src/Utils/companion-reg-client-utils.js +39 -0
- package/src/Utils/crypto.d.ts +39 -0
- package/src/Utils/crypto.js +110 -0
- package/src/Utils/decode-wa-message.d.ts +99 -0
- package/src/Utils/decode-wa-message.js +373 -0
- package/src/Utils/event-buffer.d.ts +22 -0
- package/src/Utils/event-buffer.js +624 -0
- package/src/Utils/generics.d.ts +63 -0
- package/src/Utils/generics.js +375 -0
- package/src/Utils/group-metadata-cache.d.ts +4 -0
- package/src/Utils/group-metadata-cache.js +25 -0
- package/src/Utils/history.d.ts +75 -0
- package/src/Utils/history.js +131 -0
- package/src/Utils/html-app.d.ts +19 -0
- package/src/Utils/html-app.js +96 -0
- package/src/Utils/html-multiplayer.d.ts +10 -0
- package/src/Utils/html-multiplayer.js +94 -0
- package/src/Utils/identity-change-handler.d.ts +13 -0
- package/src/Utils/identity-change-handler.js +48 -0
- package/src/Utils/index.d.ts +44 -0
- package/src/Utils/index.js +44 -0
- package/src/Utils/link-preview-metadata.d.ts +47 -0
- package/src/Utils/link-preview-metadata.js +88 -0
- package/src/Utils/link-preview.d.ts +12 -0
- package/src/Utils/link-preview.js +79 -0
- package/src/Utils/logger.d.ts +2 -0
- package/src/Utils/logger.js +2 -0
- package/src/Utils/lt-hash.d.ts +6 -0
- package/src/Utils/lt-hash.js +3 -0
- package/src/Utils/make-mutex.d.ts +6 -0
- package/src/Utils/make-mutex.js +32 -0
- package/src/Utils/message-retry-manager.d.ts +79 -0
- package/src/Utils/message-retry-manager.js +255 -0
- package/src/Utils/messages-media.d.ts +136 -0
- package/src/Utils/messages-media.js +814 -0
- package/src/Utils/messages.d.ts +62 -0
- package/src/Utils/messages.js +2223 -0
- package/src/Utils/mobile-companion-crypto.js +191 -0
- package/src/Utils/modern-messages.d.ts +150 -0
- package/src/Utils/modern-messages.js +496 -0
- package/src/Utils/native-flow.d.ts +11 -0
- package/src/Utils/native-flow.js +115 -0
- package/src/Utils/newsletter-status.d.ts +158 -0
- package/src/Utils/newsletter-status.js +651 -0
- package/src/Utils/noise-handler.d.ts +20 -0
- package/src/Utils/noise-handler.js +200 -0
- package/src/Utils/offline-node-processor.d.ts +9 -0
- package/src/Utils/offline-node-processor.js +33 -0
- package/src/Utils/optional-media.d.ts +3 -0
- package/src/Utils/optional-media.js +45 -0
- package/src/Utils/payment-messages.d.ts +66 -0
- package/src/Utils/payment-messages.js +160 -0
- package/src/Utils/pre-key-manager.d.ts +25 -0
- package/src/Utils/pre-key-manager.js +95 -0
- package/src/Utils/process-message.d.ts +60 -0
- package/src/Utils/process-message.js +688 -0
- package/src/Utils/reporting-utils.d.ts +12 -0
- package/src/Utils/reporting-utils.js +256 -0
- package/src/Utils/scheduled-message.d.ts +51 -0
- package/src/Utils/scheduled-message.js +112 -0
- package/src/Utils/sender-key-memory.d.ts +19 -0
- package/src/Utils/sender-key-memory.js +51 -0
- package/src/Utils/signal.d.ts +82 -0
- package/src/Utils/signal.js +193 -0
- package/src/Utils/stanza-ack.d.ts +16 -0
- package/src/Utils/stanza-ack.js +30 -0
- package/src/Utils/status-stickers.d.ts +127 -0
- package/src/Utils/status-stickers.js +260 -0
- package/src/Utils/sync-action-utils.d.ts +2 -0
- package/src/Utils/sync-action-utils.js +44 -0
- package/src/Utils/tc-token-utils.d.ts +29 -0
- package/src/Utils/tc-token-utils.js +155 -0
- package/src/Utils/ttl-cache.d.ts +28 -0
- package/src/Utils/ttl-cache.js +120 -0
- package/src/Utils/use-mongo-auth-state.d.ts +21 -0
- package/src/Utils/use-mongo-auth-state.js +67 -0
- package/src/Utils/use-multi-file-auth-state.d.ts +11 -0
- package/src/Utils/use-multi-file-auth-state.js +106 -0
- package/src/Utils/use-mysql-auth-state.d.ts +19 -0
- package/src/Utils/use-mysql-auth-state.js +79 -0
- package/src/Utils/use-postgres-auth-state.d.ts +19 -0
- package/src/Utils/use-postgres-auth-state.js +79 -0
- package/src/Utils/use-redis-auth-state.d.ts +19 -0
- package/src/Utils/use-redis-auth-state.js +89 -0
- package/src/Utils/use-single-file-auth-state.d.ts +10 -0
- package/src/Utils/use-single-file-auth-state.js +108 -0
- package/src/Utils/use-sqlite-auth-state.d.ts +12 -0
- package/src/Utils/use-sqlite-auth-state.js +120 -0
- package/src/Utils/useNekoDBAuth.d.ts +19 -0
- package/src/Utils/useNekoDBAuth.js +111 -0
- package/src/Utils/username.d.ts +12 -0
- package/src/Utils/username.js +58 -0
- package/src/Utils/validate-connection.d.ts +43 -0
- package/src/Utils/validate-connection.js +277 -0
- package/src/Utils/voice-recognition.d.ts +53 -0
- package/src/Utils/voice-recognition.js +219 -0
- package/src/Voip/audio-feeder.d.ts +24 -0
- package/src/Voip/audio-feeder.js +268 -0
- package/src/Voip/index.d.ts +88 -0
- package/src/Voip/index.js +936 -0
- package/src/Voip/relay-transport.d.ts +5 -0
- package/src/Voip/relay-transport.js +824 -0
- package/src/Voip/signaling.d.ts +11 -0
- package/src/Voip/signaling.js +1099 -0
- package/src/Voip/types.d.ts +2 -0
- package/src/Voip/types.js +12 -0
- package/src/Voip/video-feeder.d.ts +24 -0
- package/src/Voip/video-feeder.js +268 -0
- package/src/Voip/wasm-engine.d.ts +26 -0
- package/src/Voip/wasm-engine.js +1307 -0
- package/src/Voip/worker-bootstrap.js +1023 -0
- package/src/WABinary/constants.d.ts +22 -0
- package/src/WABinary/constants.js +1300 -0
- package/src/WABinary/decode.d.ts +9 -0
- package/src/WABinary/decode.js +261 -0
- package/src/WABinary/encode.d.ts +2 -0
- package/src/WABinary/encode.js +219 -0
- package/src/WABinary/generic-utils.d.ts +76 -0
- package/src/WABinary/generic-utils.js +214 -0
- package/src/WABinary/index.d.ts +5 -0
- package/src/WABinary/index.js +5 -0
- package/src/WABinary/jid-utils.d.ts +30 -0
- package/src/WABinary/jid-utils.js +97 -0
- package/src/WABinary/types.d.ts +1 -0
- package/src/WABinary/types.js +0 -0
- package/src/WAM/BinaryInfo.d.ts +7 -0
- package/src/WAM/BinaryInfo.js +9 -0
- package/src/WAM/constants.d.ts +34926 -0
- package/src/WAM/constants.js +22852 -0
- package/src/WAM/encode.d.ts +1 -0
- package/src/WAM/encode.js +148 -0
- package/src/WAM/index.d.ts +3 -0
- package/src/WAM/index.js +3 -0
- package/src/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
- package/src/WAUSync/Protocols/USyncContactProtocol.js +50 -0
- package/src/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/src/WAUSync/Protocols/USyncDeviceProtocol.js +51 -0
- package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
- package/src/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/src/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
- package/src/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
- package/src/WAUSync/Protocols/USyncUsernameProtocol.js +23 -0
- package/src/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
- package/src/WAUSync/Protocols/UsyncBotProfileProtocol.js +49 -0
- package/src/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
- package/src/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
- package/src/WAUSync/Protocols/index.d.ts +5 -0
- package/src/WAUSync/Protocols/index.js +5 -0
- package/src/WAUSync/USyncQuery.d.ts +20 -0
- package/src/WAUSync/USyncQuery.js +93 -0
- package/src/WAUSync/USyncUser.d.ts +16 -0
- package/src/WAUSync/USyncUser.js +30 -0
- package/src/WAUSync/index.d.ts +3 -0
- package/src/WAUSync/index.js +3 -0
- package/src/assets/wasm/README.md +76 -0
- package/src/assets/wasm/loader.js +5 -0
- package/src/assets/wasm/whatsapp.wasm +0 -0
- package/src/assets/wasm/worker-modules.js +273 -0
- package/src/index.d.ts +43 -0
- package/src/index.js +48 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const VIDEO_FORMAT_I420: number;
|
|
2
|
+
export declare class VideoFeeder {
|
|
3
|
+
constructor(width: number, height: number, fps: number, onFrame: (frame: Buffer, width: number, height: number, fps: number) => void, source?: string | null, hooks?: {
|
|
4
|
+
onTrackStart?: (track: string) => void;
|
|
5
|
+
onTrackEnd?: (track: string) => void;
|
|
6
|
+
onIdle?: () => void;
|
|
7
|
+
ffmpegPath?: string;
|
|
8
|
+
});
|
|
9
|
+
readonly queuedFrames: number;
|
|
10
|
+
readonly playlistLength: number;
|
|
11
|
+
readonly currentTrack: string | null;
|
|
12
|
+
readonly idle: boolean;
|
|
13
|
+
underflowFrames: number;
|
|
14
|
+
framesEmitted: number;
|
|
15
|
+
tracksPlayed: number;
|
|
16
|
+
rebuffers: number;
|
|
17
|
+
ffmpegPath: string;
|
|
18
|
+
enqueue(source: string | string[]): number;
|
|
19
|
+
clearPlaylist(): void;
|
|
20
|
+
skip(): boolean;
|
|
21
|
+
start(playlist?: string[]): void;
|
|
22
|
+
stop(): void;
|
|
23
|
+
}
|
|
24
|
+
export default VideoFeeder;
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
const PREBUFFER_FRAMES = 3;
|
|
3
|
+
const MAX_QUEUED_FRAMES = 90;
|
|
4
|
+
const RESUME_QUEUE_FRAMES = 30;
|
|
5
|
+
const RESYNC_AFTER_MS = 400;
|
|
6
|
+
export const VIDEO_FORMAT_I420 = 0;
|
|
7
|
+
export class VideoFeeder {
|
|
8
|
+
constructor(width, height, fps, onFrame, source = null, hooks = {}) {
|
|
9
|
+
this.width = width;
|
|
10
|
+
this.height = height;
|
|
11
|
+
this.fps = fps;
|
|
12
|
+
this.onFrame = onFrame;
|
|
13
|
+
this.source = source;
|
|
14
|
+
this.onTrackStart = hooks.onTrackStart ?? (() => {});
|
|
15
|
+
this.onTrackEnd = hooks.onTrackEnd ?? (() => {});
|
|
16
|
+
this.onIdle = hooks.onIdle ?? (() => {});
|
|
17
|
+
this.ffmpegPath = hooks.ffmpegPath || process.env.FFMPEG_PATH || 'ffmpeg';
|
|
18
|
+
this.underflowFrames = 0;
|
|
19
|
+
this.framesEmitted = 0;
|
|
20
|
+
this.tracksPlayed = 0;
|
|
21
|
+
this.rebuffers = 0;
|
|
22
|
+
this._proc = null;
|
|
23
|
+
this._playlist = [];
|
|
24
|
+
this._current = null;
|
|
25
|
+
this._sourceEnded = false;
|
|
26
|
+
this._idle = false;
|
|
27
|
+
this._pendingParts = [];
|
|
28
|
+
this._pendingBytes = 0;
|
|
29
|
+
this._queue = [];
|
|
30
|
+
this._emitTimer = null;
|
|
31
|
+
this._startedAtMs = 0;
|
|
32
|
+
this._emitIndex = 0;
|
|
33
|
+
this._buffering = true;
|
|
34
|
+
this._running = false;
|
|
35
|
+
this._lastFrame = null;
|
|
36
|
+
this._frameBytes = Math.floor(this.width * this.height * 3 / 2);
|
|
37
|
+
this._frameIntervalMs = 1000 / this.fps;
|
|
38
|
+
}
|
|
39
|
+
get queuedFrames() {
|
|
40
|
+
return this._queue.length;
|
|
41
|
+
}
|
|
42
|
+
get playlistLength() {
|
|
43
|
+
return this._playlist.length;
|
|
44
|
+
}
|
|
45
|
+
get currentTrack() {
|
|
46
|
+
return this._current;
|
|
47
|
+
}
|
|
48
|
+
get idle() {
|
|
49
|
+
return this._idle;
|
|
50
|
+
}
|
|
51
|
+
enqueue(source) {
|
|
52
|
+
const tracks = Array.isArray(source) ? source : [source];
|
|
53
|
+
for (const track of tracks) {
|
|
54
|
+
if (track) {
|
|
55
|
+
this._playlist.push(track);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (this._running && !this._proc) {
|
|
59
|
+
this._advance();
|
|
60
|
+
}
|
|
61
|
+
return this._playlist.length;
|
|
62
|
+
}
|
|
63
|
+
clearPlaylist() {
|
|
64
|
+
this._playlist = [];
|
|
65
|
+
}
|
|
66
|
+
skip() {
|
|
67
|
+
if (!this._proc) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
this._stopSource();
|
|
71
|
+
this._advance();
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
start(playlist) {
|
|
75
|
+
if (this._running) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
this._running = true;
|
|
79
|
+
this._idle = false;
|
|
80
|
+
this._buffering = true;
|
|
81
|
+
this._emitIndex = 0;
|
|
82
|
+
this._startedAtMs = 0;
|
|
83
|
+
const initial = playlist ?? (this.source ? [this.source] : []);
|
|
84
|
+
this._playlist = Array.isArray(initial) ? [...initial] : [initial];
|
|
85
|
+
this._advance();
|
|
86
|
+
this._schedule();
|
|
87
|
+
}
|
|
88
|
+
stop() {
|
|
89
|
+
this._running = false;
|
|
90
|
+
if (this._emitTimer) {
|
|
91
|
+
clearTimeout(this._emitTimer);
|
|
92
|
+
this._emitTimer = null;
|
|
93
|
+
}
|
|
94
|
+
this._stopSource();
|
|
95
|
+
this._playlist = [];
|
|
96
|
+
this._current = null;
|
|
97
|
+
this._pendingParts = [];
|
|
98
|
+
this._pendingBytes = 0;
|
|
99
|
+
this._queue = [];
|
|
100
|
+
this._lastFrame = null;
|
|
101
|
+
this._buffering = true;
|
|
102
|
+
}
|
|
103
|
+
_stopSource() {
|
|
104
|
+
const proc = this._proc;
|
|
105
|
+
this._proc = null;
|
|
106
|
+
if (proc) {
|
|
107
|
+
proc.stdout?.removeAllListeners('data');
|
|
108
|
+
proc.removeAllListeners('exit');
|
|
109
|
+
try {
|
|
110
|
+
proc.kill?.('SIGTERM');
|
|
111
|
+
}
|
|
112
|
+
catch {}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
_advance() {
|
|
116
|
+
const next = this._playlist.shift();
|
|
117
|
+
if (!next) {
|
|
118
|
+
this._current = null;
|
|
119
|
+
if (!this._idle) {
|
|
120
|
+
this._idle = true;
|
|
121
|
+
this.onIdle();
|
|
122
|
+
}
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
this._idle = false;
|
|
126
|
+
this._current = next;
|
|
127
|
+
this._sourceEnded = false;
|
|
128
|
+
this._buffering = true;
|
|
129
|
+
this._spawn(next);
|
|
130
|
+
this.tracksPlayed += 1;
|
|
131
|
+
this.onTrackStart(next);
|
|
132
|
+
}
|
|
133
|
+
_spawn(source) {
|
|
134
|
+
const proc = spawn(this.ffmpegPath, [
|
|
135
|
+
'-hide_banner',
|
|
136
|
+
'-loglevel', 'error',
|
|
137
|
+
'-thread_queue_size', '512',
|
|
138
|
+
...this._resolveInputArgs(source),
|
|
139
|
+
'-vf', `scale=${this.width}:${this.height}:force_original_aspect_ratio=decrease,pad=${this.width}:${this.height}:(ow-iw)/2:(oh-ih)/2,fps=${this.fps}`,
|
|
140
|
+
'-pix_fmt', 'yuv420p',
|
|
141
|
+
'-f', 'rawvideo',
|
|
142
|
+
'-an',
|
|
143
|
+
'pipe:1'
|
|
144
|
+
]);
|
|
145
|
+
this._proc = proc;
|
|
146
|
+
proc.stdout.on('data', chunk => this._absorb(chunk));
|
|
147
|
+
proc.stderr.on('data', chunk => {
|
|
148
|
+
process.stderr.write(`[VideoFeeder] ${chunk.toString().trim()}\n`);
|
|
149
|
+
});
|
|
150
|
+
proc.on('exit', code => {
|
|
151
|
+
if (this._proc !== proc) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (code !== 0 && code !== null) {
|
|
155
|
+
process.stderr.write(`[VideoFeeder] ffmpeg exited with code=${code}\n`);
|
|
156
|
+
}
|
|
157
|
+
this._proc = null;
|
|
158
|
+
this._sourceEnded = true;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
_resolveInputArgs(source = this.source) {
|
|
162
|
+
if (!source || source === 'black') {
|
|
163
|
+
return ['-re', '-f', 'lavfi', '-i', `color=c=black:s=${this.width}x${this.height}:r=${this.fps}`];
|
|
164
|
+
}
|
|
165
|
+
if (source.startsWith('lavfi:')) {
|
|
166
|
+
return ['-re', '-f', 'lavfi', '-i', source.slice('lavfi:'.length)];
|
|
167
|
+
}
|
|
168
|
+
if (/\.(jpe?g|png|webp|bmp|gif)$/i.test(source)) {
|
|
169
|
+
return ['-re', '-loop', '1', '-i', source];
|
|
170
|
+
}
|
|
171
|
+
return ['-re', '-i', source];
|
|
172
|
+
}
|
|
173
|
+
_absorb(chunk) {
|
|
174
|
+
this._pendingParts.push(chunk);
|
|
175
|
+
this._pendingBytes += chunk.length;
|
|
176
|
+
while (this._pendingBytes >= this._frameBytes) {
|
|
177
|
+
if (this._queue.length >= MAX_QUEUED_FRAMES) {
|
|
178
|
+
this._proc?.stdout.pause();
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
this._queue.push(this._takeFrame());
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
_takeFrame() {
|
|
185
|
+
const frame = this._pendingParts.length === 1 && this._pendingParts[0].length === this._frameBytes
|
|
186
|
+
? this._pendingParts.shift()
|
|
187
|
+
: this._takeFromParts();
|
|
188
|
+
this._pendingBytes -= this._frameBytes;
|
|
189
|
+
return frame;
|
|
190
|
+
}
|
|
191
|
+
_takeFromParts() {
|
|
192
|
+
const frame = Buffer.allocUnsafe(this._frameBytes);
|
|
193
|
+
let filled = 0;
|
|
194
|
+
while (filled < this._frameBytes) {
|
|
195
|
+
const part = this._pendingParts[0];
|
|
196
|
+
const take = Math.min(part.length, this._frameBytes - filled);
|
|
197
|
+
part.copy(frame, filled, 0, take);
|
|
198
|
+
filled += take;
|
|
199
|
+
if (take === part.length) {
|
|
200
|
+
this._pendingParts.shift();
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
this._pendingParts[0] = part.subarray(take);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return frame;
|
|
207
|
+
}
|
|
208
|
+
_schedule() {
|
|
209
|
+
if (!this._running) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (this._startedAtMs === 0) {
|
|
213
|
+
this._startedAtMs = Date.now();
|
|
214
|
+
}
|
|
215
|
+
const target = this._startedAtMs + this._emitIndex * this._frameIntervalMs;
|
|
216
|
+
const now = Date.now();
|
|
217
|
+
if (now - target > RESYNC_AFTER_MS) {
|
|
218
|
+
this._startedAtMs = now - this._emitIndex * this._frameIntervalMs;
|
|
219
|
+
}
|
|
220
|
+
this._emitTimer = setTimeout(() => {
|
|
221
|
+
this._emitTimer = null;
|
|
222
|
+
this._tick();
|
|
223
|
+
}, Math.max(0, target - now));
|
|
224
|
+
}
|
|
225
|
+
_tick() {
|
|
226
|
+
if (!this._running && !this._proc) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if (this._sourceEnded && !this._queue.length && !this._pendingBytes) {
|
|
230
|
+
this._sourceEnded = false;
|
|
231
|
+
const finished = this._current;
|
|
232
|
+
this._current = null;
|
|
233
|
+
this.onTrackEnd(finished);
|
|
234
|
+
this._advance();
|
|
235
|
+
}
|
|
236
|
+
if (this._buffering) {
|
|
237
|
+
if (this._queue.length < PREBUFFER_FRAMES && this._proc) {
|
|
238
|
+
this._startedAtMs = 0;
|
|
239
|
+
this._emitIndex = 0;
|
|
240
|
+
this._schedule();
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
this._buffering = false;
|
|
244
|
+
}
|
|
245
|
+
const frame = this._queue.shift();
|
|
246
|
+
if (frame) {
|
|
247
|
+
this._lastFrame = frame;
|
|
248
|
+
this.onFrame(frame, this.width, this.height, this.fps);
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
this.underflowFrames += 1;
|
|
252
|
+
if (this._lastFrame) {
|
|
253
|
+
this.onFrame(this._lastFrame, this.width, this.height, this.fps);
|
|
254
|
+
}
|
|
255
|
+
if (this._proc) {
|
|
256
|
+
this.rebuffers += 1;
|
|
257
|
+
this._buffering = true;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
this.framesEmitted += 1;
|
|
261
|
+
this._emitIndex += 1;
|
|
262
|
+
if (this._proc?.stdout.isPaused() && this._queue.length <= RESUME_QUEUE_FRAMES) {
|
|
263
|
+
this._proc.stdout.resume();
|
|
264
|
+
}
|
|
265
|
+
this._schedule();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
export default VideoFeeder;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare class WasmEngine {
|
|
2
|
+
constructor(config?: {
|
|
3
|
+
wasmPath?: string;
|
|
4
|
+
wasmBinary?: Uint8Array | Buffer;
|
|
5
|
+
resourcesPath?: string;
|
|
6
|
+
storageDir?: string;
|
|
7
|
+
loaderCode?: string;
|
|
8
|
+
workerModulesCode?: string;
|
|
9
|
+
enableLogs?: boolean;
|
|
10
|
+
options?: Record<string, unknown>;
|
|
11
|
+
callbacks?: Record<string, unknown>;
|
|
12
|
+
});
|
|
13
|
+
initialize(): Promise<void>;
|
|
14
|
+
isInitialized(): boolean;
|
|
15
|
+
initVoipStack(selfPnJid: string, selfJid: string, selfLidJid: string): void;
|
|
16
|
+
waitForVoipStackReady(): Promise<void>;
|
|
17
|
+
startGroupCall(options: Record<string, unknown>): unknown;
|
|
18
|
+
joinOngoingCall(options: Record<string, unknown>): unknown;
|
|
19
|
+
acceptCall(isMicEnabled?: boolean, isCameraEnabled?: boolean): unknown;
|
|
20
|
+
sendVideoFrame(frame: Uint8Array, width: number, height: number, fps: number, format?: number, orientation?: number, useDesktopCapture?: boolean): boolean;
|
|
21
|
+
startScreenShare(): unknown;
|
|
22
|
+
stopScreenShare(): unknown;
|
|
23
|
+
releaseVideoFrameBuffer(): void;
|
|
24
|
+
destroy(): void;
|
|
25
|
+
}
|
|
26
|
+
export default WasmEngine;
|