{"_id":"@diyawanna/lan-bridge-core","_rev":"2-9ff2790c0d04012f20471622198b0981","name":"@diyawanna/lan-bridge-core","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.0":{"name":"@diyawanna/lan-bridge-core","version":"0.1.0","keywords":["lan","bridge","websocket","react","mobile","communication","real-time","file-transfer","local-network","cross-platform","Diyawanna"],"author":{"name":"diyawanna"},"license":"MIT","_id":"@diyawanna/lan-bridge-core@0.1.0","maintainers":[{"name":"diyawanna","email":"wije.sahan@gmail.com"}],"homepage":"https://github.com/Diyawanna/npm-lan-bridge-core#readme","bugs":{"url":"https://github.com/Diyawanna/npm-lan-bridge-core/issues"},"dist":{"shasum":"f90adce6e61bed36e83bcac5937a85a8db8274dc","tarball":"https://registry.npmjs.org/@diyawanna/lan-bridge-core/-/lan-bridge-core-0.1.0.tgz","fileCount":7,"integrity":"sha512-khwbb0aQjLe6ZKL55MKliZVZGpa3p4m0Z8f6VNx+KGWgF5yUrUb06+2JziLQdaEFTQcrxN4HkasQMBs8GBNeog==","signatures":[{"sig":"MEQCIFewBvzZpAV4EFP+IQNgsBdtVDBDl5J6/6WeESf9Y28AAiBphR6jwNKPpW5Dh9NDG+z8wDW+nRMHnbRfCSgTyy1NXQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":32845},"main":"index.js","engines":{"node":">=14.0.0"},"gitHead":"b4ae9eebcb94b5d781e2de7ca17248025f0c6f23","scripts":{"test":"echo \"Error: no test specified\" && exit 1","start":"node index.js","prepublishOnly":"echo \"Preparing for publish...\""},"_npmUser":{"name":"diyawanna","email":"wije.sahan@gmail.com"},"repository":{"url":"git+https://github.com/Diyawanna/npm-lan-bridge-core.git","type":"git"},"_npmVersion":"10.8.1","description":"A module for LAN-based bi-directional communication between web and mobile applications using WebSockets.","directories":{},"_nodeVersion":"22.3.0","dependencies":{"ws":"^8.18.2"},"_hasShrinkwrap":false,"peerDependencies":{"react":">=16.8.0"},"_npmOperationalInternal":{"tmp":"tmp/lan-bridge-core_0.1.0_1749687307510_0.5971717828992089","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@diyawanna/lan-bridge-core","version":"0.1.1","description":"A module for LAN-based bi-directional communication between web and mobile applications using WebSockets.","main":"index.js","scripts":{"start":"node index.js","test":"echo \"Error: no test specified\" && exit 1","prepublishOnly":"echo \"Preparing for publish...\""},"keywords":["lan","bridge","websocket","react","mobile","communication","real-time","file-transfer","local-network","cross-platform","Diyawanna"],"author":{"name":"diyawanna"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/Diyawanna/npm-lan-bridge-core.git"},"bugs":{"url":"https://github.com/Diyawanna/npm-lan-bridge-core/issues"},"homepage":"https://github.com/Diyawanna/npm-lan-bridge-core#readme","dependencies":{"ws":"^8.18.2"},"peerDependencies":{"react":">=16.8.0"},"engines":{"node":">=14.0.0"},"_id":"@diyawanna/lan-bridge-core@0.1.1","gitHead":"b4ae9eebcb94b5d781e2de7ca17248025f0c6f23","_nodeVersion":"22.3.0","_npmVersion":"10.8.1","dist":{"integrity":"sha512-Zhlb6cVnngd42uuqY03WnZiThcANhUEvH3GYB2TwiiJO7/omCeYdkURRQT40PAGm/3tW8hbwMgPolk3HBFvK9g==","shasum":"36a7ec7e2db671cbae6b6f7827f6e22b1bbff0f8","tarball":"https://registry.npmjs.org/@diyawanna/lan-bridge-core/-/lan-bridge-core-0.1.1.tgz","fileCount":7,"unpackedSize":32923,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCUeT5q5lr/RMyqqVykyPQLvE1Bf4wUCF6H5l5auMbo2QIgPxwsHZqCRGiB2aT80irQyjFztm4RNJ+O2HUrZDuPXG8="}]},"_npmUser":{"name":"diyawanna","email":"wije.sahan@gmail.com"},"directories":{},"maintainers":[{"name":"diyawanna","email":"wije.sahan@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/lan-bridge-core_0.1.1_1749688163034_0.38816163116414604"},"_hasShrinkwrap":false}},"time":{"created":"2025-06-12T00:15:07.437Z","modified":"2025-06-12T00:29:23.416Z","0.1.0":"2025-06-12T00:15:07.738Z","0.1.1":"2025-06-12T00:29:23.214Z"},"bugs":{"url":"https://github.com/Diyawanna/npm-lan-bridge-core/issues"},"author":{"name":"diyawanna"},"license":"MIT","homepage":"https://github.com/Diyawanna/npm-lan-bridge-core#readme","keywords":["lan","bridge","websocket","react","mobile","communication","real-time","file-transfer","local-network","cross-platform","Diyawanna"],"repository":{"type":"git","url":"git+https://github.com/Diyawanna/npm-lan-bridge-core.git"},"description":"A module for LAN-based bi-directional communication between web and mobile applications using WebSockets.","maintainers":[{"name":"diyawanna","email":"wije.sahan@gmail.com"}],"readme":"# @diyawanna/lan-bridge-core\n\nA powerful npm module for enabling bi-directional communication between web and mobile applications over local area networks using WebSockets.\n\n## Overview\n\n`@diyawanna/lan-bridge-core` provides a simple yet robust solution for real-time communication between web applications and mobile devices on the same local network. This module is perfect for scenarios where you need to share data, files, or messages between different devices without relying on external servers or internet connectivity.\n\n## Features\n\n- **Real-time Communication**: WebSocket-based bi-directional messaging\n- **Multi-platform Support**: Works with web browsers, React Native, Flutter, iOS, and Android\n- **File Transfer**: Support for sending images and files between devices\n- **Auto-reconnection**: Automatic reconnection with exponential backoff\n- **Network Discovery**: Built-in tools for finding servers on the local network\n- **Type Safety**: Full TypeScript support\n- **Easy Integration**: Simple API with React components included\n\n## Demo\n\nHere's a quick look at the web application demonstrating the LAN Bridge in action:\n\n![LAN Bridge Core Demo](docs/lan-bridge-demo.webp)\n\n## Installation\n\n```bash\nnpm install @diyawanna/lan-bridge-core\n```\n\n## Quick Start\n\n### 1. Start the Server\n\n```javascript\nconst LANBridge = require(\"@diyawanna/lan-bridge-core\");\n\n// Start the WebSocket server\nconst server = new LANBridge.Server({ port: 8080 });\nserver.start();\n\nconsole.log(\"LAN Bridge server running on port 8080\");\n```\n\n### 2. Connect from Web Application\n\n```javascript\n// Import the client library\nimport LANBridge from \"@diyawanna/lan-bridge-core/client\";\n\n// Create a new bridge instance\nconst bridge = new LANBridge(\"ws://localhost:8080\");\n\n// Connect to the server\nawait bridge.connect();\n\n// Send a text message\nbridge.sendText(\"Hello from web!\");\n\n// Listen for incoming messages\nbridge.onMessage(\"text\", (message) => {\n  console.log(\"Received:\", message.payload);\n});\n```\n\n### 3. React Component\n\n```jsx\nimport React from \"react\";\nimport { LANBridgeComponent } from \"@diyawanna/lan-bridge-core/react\";\n\nfunction App() {\n  return (\n    <div>\n      <h1>My App</h1>\n      <LANBridgeComponent serverUrl=\"ws://localhost:8080\" />\n    </div>\n  );\n}\n```\n\n## API Reference\n\n### Server API\n\n#### `new LANBridge.Server(options)`\n\nCreates a new LAN Bridge server instance.\n\n**Options:**\n- `port` (number): Port to listen on (default: 8080)\n- `host` (string): Host to bind to (default: \"0.0.0.0\")\n\n**Methods:**\n- `start()`: Start the server\n- `stop()`: Stop the server\n- `getConnectedClients()`: Get list of connected clients\n\n### Client API\n\n#### `new LANBridge(serverUrl)`\n\nCreates a new client instance.\n\n**Parameters:**\n- `serverUrl` (string): WebSocket server URL\n\n**Methods:**\n- `connect()`: Connect to the server (returns Promise)\n- `disconnect()`: Disconnect from the server\n- `sendText(text)`: Send a text message\n- `sendFile(file)`: Send a file (returns Promise)\n- `onMessage(type, handler)`: Register message handler\n\n**Events:**\n- `text`: Text message received\n- `image`: Image file received\n- `file`: File received\n- `error`: Error occurred\n\n## Message Protocol\n\nAll messages follow a standardized JSON format:\n\n### Text Messages\n```json\n{\n  \"type\": \"text\",\n  \"payload\": \"Your message content\",\n  \"timestamp\": 1640995200000\n}\n```\n\n### File Messages\n```json\n{\n  \"type\": \"image\", // or \"file\"\n  \"name\": \"filename.jpg\",\n  \"payload\": \"base64_encoded_data\",\n  \"timestamp\": 1640995200000\n}\n```\n\n## Mobile Integration\n\nFor detailed instructions on integrating with mobile applications, please refer to the [Mobile Integration Guide](mobile-integration.md).\n\n## Network Discovery\n\nFind LAN Bridge servers on your network:\n\n```javascript\nimport { NetworkDiscovery } from \"@diyawanna/lan-bridge-core\";\n\nconst discovery = new NetworkDiscovery();\nconst servers = await discovery.findServers();\n\nconsole.log(\"Found servers:\", servers);\n// Output: [\"192.168.1.100:8080\", \"192.168.1.101:8080\"]\n```\n\n## Security Considerations\n\n- **Local Network Only**: The server only accepts connections from the local network\n- **No Authentication**: Basic version doesn't include authentication (suitable for trusted networks)\n- **File Size Limits**: Configurable limits on file uploads\n- **Input Validation**: All incoming data is validated\n\n## Examples\n\n### Basic Chat Application\n\n```javascript\n// Server\nconst server = new LANBridge.Server({ port: 8080 });\nserver.start();\n\n// Web Client\nconst bridge = new LANBridge(\"ws://localhost:8080\");\nawait bridge.connect();\n\nbridge.onMessage(\"text\", (message) => {\n  displayMessage(message.payload);\n});\n\nfunction sendMessage(text) {\n  bridge.sendText(text);\n  displayMessage(text, true); // Show as sent\n}\n```\n\n### File Sharing\n\n```javascript\n// Send file from web\nconst fileInput = document.getElementById(\"fileInput\");\nfileInput.addEventListener(\"change\", async (event) => {\n  const file = event.target.files[0];\n  if (file) {\n    await bridge.sendFile(file);\n    console.log(\"File sent:\", file.name);\n  }\n});\n\n// Receive file\nbridge.onMessage(\"file\", (message) => {\n  console.log(\"File received:\", message.name);\n  // File is automatically saved to uploads directory\n});\n```\n\n## Configuration\n\n### Server Configuration\n\n```javascript\nconst server = new LANBridge.Server({\n  port: 8080,\n  host: \"0.0.0.0\",\n  maxFileSize: 10 * 1024 * 1024, // 10MB\n  uploadsDir: \"./uploads\",\n  cors: true\n});\n```\n\n### Client Configuration\n\n```javascript\nconst bridge = new LANBridge(\"ws://localhost:8080\", {\n  reconnectAttempts: 5,\n  reconnectDelay: 1000,\n  timeout: 30000\n});\n```\n\n## Troubleshooting\n\n### Connection Issues\n\n1. **Check Network**: Ensure devices are on the same network\n2. **Firewall**: Verify port 8080 is not blocked\n3. **IP Address**: Use the correct local IP address\n4. **Server Status**: Confirm the server is running\n\n### File Transfer Issues\n\n1. **File Size**: Check if file exceeds size limits\n2. **Format**: Ensure file format is supported\n3. **Network**: Large files may timeout on slow networks\n\n## Contributing\n\nWe welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.\n\n## License\n\nMIT License - see [LICENSE](LICENSE) file for details.\n\n## Support\n\n- **Documentation**: [Full API Documentation](https://tech.diyawanna.com/docs/lan-bridge)\n- **Issues**: [GitHub Issues](https://github.com/Diyawanna/npm-lan-bridge-core/issues)\n- **Discussions**: [GitHub Discussions](https://github.com/Diyawanna/npm-lan-bridge-core/discussions)\n\n## Changelog\n\n### v0.0.1 (Initial Release)\n- Basic WebSocket server and client\n- Text and file messaging\n- React component\n- Mobile integration examples\n- Network discovery utilities\n\n## Publishing\n\nFor detailed instructions on how to publish this module to npm, please refer to the [Publishing Guide](PUBLISHING.md).\n","readmeFilename":"README.md"}