feat: improve printer discovery with multicast fix and type safety#20
feat: improve printer discovery with multicast fix and type safety#20GhostTypes merged 3 commits intomainfrom
Conversation
Major improvements to printer discovery system: - Fix Windows multicast EINVAL error by joining multicast group once per socket instead of once per port - Add comprehensive TypeScript types for printer discovery (PrinterDiscovery model) - Add custom error classes (DiscoveryErrors) for better error handling - Add unit tests for PrinterDiscovery with Vitest - Move test-discovery.js to scripts/ directory and update import path - Update documentation with new PrinterDiscovery API usage - Add migration guide for FlashForgePrinterDiscovery → PrinterDiscovery rename - Update CLAUDE.md with modern discovery architecture details The multicast fix eliminates duplicate addMembership() calls that were causing "Failed to send multicast to 225.0.0.9:19000 - addMembership EINVAL" errors on Windows. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Summary of ChangesHello @GhostTypes, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request delivers a foundational overhaul of the printer discovery mechanism, making it more reliable, versatile, and developer-friendly. By addressing a specific Windows multicast bug, standardizing discovery across all FlashForge models, and integrating robust type safety and error handling, the system is now better equipped to handle diverse network environments and printer types. The introduction of comprehensive unit tests and a clear migration path ensures both the quality of the new implementation and a smooth transition for existing users. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request significantly improves the printer discovery mechanism by fixing the Windows multicast issue, introducing comprehensive TypeScript types, custom errors, and a new DiscoveryMonitor for event-based discovery. It also includes extensive unit tests and detailed documentation. No security vulnerabilities were found. I have a couple of minor suggestions to improve the documentation clarity.
- Fix MIGRATION_GUIDE.md example to properly handle discover() array return type - Add length check before accessing first printer to prevent runtime errors - Correct monitor() return type from EventEmitter to DiscoveryMonitor - Ensures type safety matches actual implementation Addresses review feedback from Gemini Code Assist.
Summary
This PR significantly improves the printer discovery system with a critical Windows multicast fix, comprehensive TypeScript types, error handling, and test coverage.
Changes
Bug Fix
socket.addMembership()call was inside the port loop, causing duplicate membership attempts that failed on Windows with "addMembership EINVAL". Moved the call outside the loop so the multicast group is joined once per socket, then packets are sent to all relevant ports.Type Safety
src/models/PrinterDiscovery.tswith TypeScript interfaces forDiscoveredPrinter,DiscoveryOptions,PrinterModelenum,PrinterStatusenum, andDiscoveryProtocolenumsrc/api/network/DiscoveryErrors.tswith custom error classes (InvalidResponseError,SocketCreationError) for better error handlingTesting
src/api/PrinterDiscovery.test.tswith comprehensive Vitest test coverage for all discovery methodstest-discovery.jstoscripts/directory with updated import pathDocumentation
docs/MIGRATION_GUIDE.mddocumenting theFlashForgePrinterDiscovery→PrinterDiscoveryAPI renamePrinterDiscoveryAPI usageBreaking Changes
FlashForgePrinterDiscoveryrenamed toPrinterDiscovery(backward compatibility export maintained)FlashForgePrinterrenamed toDiscoveredPrinterinterfacediscoverPrintersAsync()method renamed todiscover()with options object parameterTest Plan
Verification
🤖 Generated with Claude Code