A simple WebSocket server written in TypeScript that integrates seamlessly with Laravel Broadcast. This server allows for real-time communication with your Laravel application.
- TypeScript: Written entirely in TypeScript for type safety and better developer experience.
- Integration with Laravel Broadcast: Easily integrates with Laravel's broadcasting system.
- IP Whitelisting/Blacklisting: Control which IP addresses can connect to the WebSocket server.
Make sure you have the following tools globally installed on your system:
- Node.js
- TypeScript (ts)
- ts-node (ts-node)
- nodemon (nodemon)
You can install these globally using npm:
npm install -g typescript ts-node nodemonOr using yarn:
yarn global add typescript ts-node nodemon- 
Clone the repository: Clone the repository to your local machine: git clone https://github.com/naro-code-lab/Websocket-Server.git 
- 
Install dependencies: Navigate into the project directory and install the dependencies using npm or yarn: cd websocket-server npm installOr yarn install 
- 
Environment Setup: Create a .envfile from the provided.env.example:cp .env.example .env In the .envfile, configure the following settings:- HOST: The host for the WebSocket server (e.g.,- localhost).
- PORT: The port number for the web server.
- WS_PORT: The port number for the WebSocket server.
 Example .envconfiguration:HOST=localhost PORT=3000 WS_PORT=6001 ALLOWED_BROADCASTING_SERVER_IPS="*" BLACKLISTED_BROADCASTING_SERVER_IPS="" 
- 
IP Whitelisting: In the .envfile, specify the IP addresses that are allowed to connect to the server. Separate multiple IPs with commas. For localhost, you can use:ALLOWED_BROADCASTING_SERVER_IPS=127.0.0.1,::ffff:127.0.0.1,::1,localhost 
- 
IP Blacklisting: Optionally, you can also blacklist IP addresses that are not allowed to connect: BLACKLISTED_BROADCASTING_SERVER_IPS=192.168.0.1 
To start the WebSocket server, run the following command:
npm run serveOr with yarn:
yarn serveOnce the server is running, it will automatically listen for incoming WebSocket connections and broadcast events from Laravel. Ensure that your Laravel application is configured to use the WebSocket server for broadcasting.
Contributions are welcome! Please submit issues and pull requests for any improvements or bug fixes.
This project is licensed under the MIT License. See the LICENSE file for details.