Skip to content

sync: dev with v4 - #165

Merged
1Lucas1apk merged 23 commits into
v4from
dev
Sep 26, 2025
Merged

sync: dev with v4#165
1Lucas1apk merged 23 commits into
v4from
dev

Conversation

@1Lucas1apk

Copy link
Copy Markdown
Member

No description provided.

1Lucas1apk and others added 23 commits August 6, 2025 13:14
Signed-off-by: Lucas Morais Rodrigues <76886832+1Lucas1apk@users.noreply.github.com>
…check mechanism and improved error handling during node transfers
…ug logging

- Introduced `isResuming` flag for players to track resumption state.
- Improved WebSocket error handling by categorizing fatal and client error codes.
- Added debug logs for ignored `WebSocketClosedEvent` during resumption and exceeded reconnect attempts.
…ing health checks

- Enhanced `_handleAutoplay` to return a boolean for better flow control.
- Added `trackStale` event to manage stale track scenarios.
- Improved player health check to handle track resumption, skipping, or stopping gracefully.
- Removed redundant `handleTrackEnd` method logic.
…tialization

- Introduced `autoJoin` to simplify player setup by handling voice and text channel assignments, including reconnections.
…debug logs

- Enhanced `VOICE_STATE_UPDATE` and `VOICE_SERVER_UPDATE` packet handling with additional validation and debugging.
- Ensured players handle voice channel changes, disconnections, and session updates accurately.
- Improved debug logs to track user actions and session transitions.
- Fixed potential playback issues by enforcing proper self-mute and server-mute behavior.
…ayload handling

- Added a `MAX_PAYLOAD_SIZE` constant to the WebSocket service, allowing better control over payload limits.
…namespace

- Adjusted `EventEmitter` import to use `node:events` for better clarity and Node.js compatibility.
- Introduced `isValidDiscordId` to validate Discord IDs for enhanced input verification.
- Changed `http` import to `node:http` for consistency with Node.js module resolution and better clarity.
…ner`

- Renamed `connect` to `connectBun` and introduced `connectNode` for platform-specific implementation.
- Removed the unused `addEventListener` method definition from the WebSocket class.
- Updated package version in `package.json` to 4.60.18.
- Changed User-Agent identifier from `Epiphany` to `Malodorus`.
- Updated `.npmignore` to exclude `.idea` and `assets` directories.
@1Lucas1apk
1Lucas1apk merged commit b3c974d into v4 Sep 26, 2025
0 of 2 checks passed
@Ecliptia Ecliptia deleted a comment from gemini-code-assist Bot Sep 26, 2025

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request appears to be a large synchronization, introducing a wide range of improvements and refactorings. Key enhancements include a more robust WebSocket implementation with support for both Node.js and Bun, a new player health check mechanism to handle stale tracks and unresponsive nodes, and significantly improved voice state handling in the manager. While these changes greatly improve the library's stability and feature set, I've identified a critical issue in the new WebSocket implementation where client-sent frames are not being masked, which will cause connections to fail. Additionally, IDE-specific configuration files are being added to the repository, which should be avoided by updating the .gitignore file.

Comment on lines +225 to 247
sendFrame(opcode, payload) {
const payloadLength = payload.length;
let header;
let headerLength = 2;
if (payloadLength < 126) {
header = Buffer.alloc(headerLength);
header[1] = payloadLength;
}
else if (payloadLength > 125) {
header[1] = 0x80 | 126;
else if (payloadLength < 65536) {
headerLength = 4;
header = Buffer.alloc(headerLength);
header[1] = 126;
header.writeUInt16BE(payloadLength, 2);
}
else {
header[1] = 0x80 | payloadLength;
}
const mask = (0, crypto_1.randomBytes)(4);
mask.copy(header, headerLength - 4);
const maskedPayload = Buffer.alloc(payloadLength);
for (let i = 0; i < payloadLength; i++) {
maskedPayload[i] = payload[i] ^ mask[i % 4];
headerLength = 10;
header = Buffer.alloc(headerLength);
header[1] = 127;
header.writeBigUInt64BE(BigInt(payloadLength), 2);
}
this.netSocket.write(Buffer.concat([header, maskedPayload]), cb);
header[0] = 0x80 | opcode;
this.netSocket.write(Buffer.concat([header, payload]));
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

The WebSocket frames sent from the client to the server must be masked according to RFC 6455, Section 5.1. This implementation is missing the payload masking. A server must close the connection upon receiving an unmasked frame from a client, which will cause this implementation to fail. You need to set the MASK bit in the header, generate a 4-byte masking key, include it in the header, and XOR the payload with the key before sending.

    sendFrame(opcode, payload) {
        const payloadLength = payload.length;
        let header;
        let headerLength = 2;
        if (payloadLength < 126) {
            headerLength += 4;
            header = Buffer.alloc(headerLength);
            header[1] = 0x80 | payloadLength;
        }
        else if (payloadLength < 65536) {
            headerLength = 4 + 4;
            header = Buffer.alloc(headerLength);
            header[1] = 0x80 | 126;
            header.writeUInt16BE(payloadLength, 2);
        }
        else {
            headerLength = 10 + 4;
            header = Buffer.alloc(headerLength);
            header[1] = 0x80 | 127;
            header.writeBigUInt64BE(BigInt(payloadLength), 2);
        }
        header[0] = 0x80 | opcode;
        const mask = (0, node_crypto_1.randomBytes)(4);
        mask.copy(header, headerLength - 4);
        const maskedPayload = Buffer.alloc(payloadLength);
        for (let i = 0; i < payloadLength; i++) {
            maskedPayload[i] = payload[i] ^ mask[i % 4];
        }
        this.netSocket.write(Buffer.concat([header, maskedPayload]));
    }

@Ecliptia Ecliptia deleted a comment from gemini-code-assist Bot Sep 26, 2025
@1Lucas1apk
1Lucas1apk deleted the dev branch November 14, 2025 19:52
1Lucas1apk added a commit that referenced this pull request Feb 7, 2026
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.

1 participant