update docker
This commit is contained in:
		
							parent
							
								
									548eb9613c
								
							
						
					
					
						commit
						9906c8d938
					
				|  | @ -1,12 +1,12 @@ | |||
| const httpServer = require("http").createServer(); | ||||
| const io = require("socket.io")(httpServer, { | ||||
|   // ...
 | ||||
|   cors: { | ||||
|     origin: '*', | ||||
|   } | ||||
|   // config
 | ||||
| }); | ||||
| 
 | ||||
| io.on("connection", (socket) => { | ||||
| 
 | ||||
|     console.log('Connected'); | ||||
| 
 | ||||
|     // Handle data received from the client
 | ||||
|     socket.on('data', (data) => { | ||||
|         console.log('Received:', data.toString()); | ||||
|  |  | |||
|  | @ -16,7 +16,7 @@ services: | |||
|       - 1000:8000 | ||||
|       - 1001:8001 | ||||
|     networks: | ||||
|       laravel: | ||||
|       - laravel | ||||
|     depends_on: | ||||
|       - redis | ||||
| 
 | ||||
|  | @ -24,9 +24,18 @@ services: | |||
|     build: | ||||
|       context: ./.docker/puppeteer | ||||
|       dockerfile: Dockerfile | ||||
|     shm_size: '512M' | ||||
|     networks: | ||||
|       - laravel | ||||
| 
 | ||||
|   socketio: | ||||
|     build: | ||||
|       context: ./.docker/socketio | ||||
|       dockerfile: Dockerfile | ||||
|     ports: | ||||
|       - 4000:4000 | ||||
|     shm_size: '256M' | ||||
|       - 3000:3000 | ||||
|     networks: | ||||
|       - laravel | ||||
| 
 | ||||
|   redis: | ||||
|     image: redis | ||||
|  |  | |||
|  | @ -0,0 +1,36 @@ | |||
| <!DOCTYPE html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
|     <meta charset="UTF-8"> | ||||
|     <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||||
|     <title>Socket.IO Client</title> | ||||
|     <!-- Include Socket.IO client library --> | ||||
|     <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.3.1/socket.io.js"></script> | ||||
| </head> | ||||
| <body> | ||||
|     <h1>Socket.IO Client</h1> | ||||
|     <div id="messages"></div> | ||||
| 
 | ||||
|     <script> | ||||
|         // Connect to the Socket.IO server
 | ||||
|         const socket = io('http://localhost:3000'); // Replace with your server URL
 | ||||
| 
 | ||||
|         // Event handler for successful connection
 | ||||
|         socket.on('connect', () => { | ||||
|             console.log('Connected to server'); | ||||
|         }); | ||||
| 
 | ||||
|         // Event handler for receiving messages from the server
 | ||||
|         socket.on('message', (data) => { | ||||
|             const messagesDiv = document.getElementById('messages'); | ||||
|             messagesDiv.innerHTML += `<p>${data}</p>`; | ||||
|         }); | ||||
| 
 | ||||
|         // Function to send a message to the server
 | ||||
|         function sendMessage() { | ||||
|             const message = document.getElementById('messageInput').value; | ||||
|             socket.emit('message', message); | ||||
|         } | ||||
|     </script> | ||||
| </body> | ||||
| </html> | ||||
|  | @ -1,68 +0,0 @@ | |||
| <!DOCTYPE html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
|     <meta charset="UTF-8"> | ||||
|     <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||||
|     <title>Socket Client</title> | ||||
| </head> | ||||
| <body> | ||||
| 
 | ||||
|     <h1>Socket Client</h1> | ||||
| 
 | ||||
|     <div id="messages"></div> | ||||
| 
 | ||||
|     <script> | ||||
|         // Create a WebSocket instance
 | ||||
|         const socket = new WebSocket('ws://192.168.56.101:2346'); | ||||
| 
 | ||||
|         socket.onopen = function (event) { | ||||
|             console.log("Connected to the server"); | ||||
|             console.log({socket, event}); | ||||
| 
 | ||||
|             // Send an initial payload upon connection
 | ||||
|             const username = 'kai.1'; | ||||
|             const payload = { | ||||
|                 username: username | ||||
|             }; | ||||
|             socket.send(JSON.stringify(payload)); | ||||
|         }; | ||||
| 
 | ||||
|         socket.onmessage = function (event) { | ||||
|             console.log("Received message from the server:", event.data); | ||||
|         }; | ||||
| 
 | ||||
|         // Event handler for when the connection is opened
 | ||||
|         socket.addEventListener('open', (event) => { | ||||
|             console.log('Connected to the server'); | ||||
|         }); | ||||
| 
 | ||||
|         // Event handler for when a message is received from the server
 | ||||
|         socket.addEventListener('message', (event) => { | ||||
|             // Display the received message on the HTML page
 | ||||
|             const messagesDiv = document.getElementById('messages'); | ||||
|             messagesDiv.innerHTML += '<p>' + event.data + '</p>'; | ||||
|         }); | ||||
| 
 | ||||
|         // Event handler for errors
 | ||||
|         socket.addEventListener('error', (event) => { | ||||
|             console.error('Error occurred:', event); | ||||
|         }); | ||||
| 
 | ||||
|         // Event handler for when the connection is closed
 | ||||
|         socket.addEventListener('close', (event) => { | ||||
|             console.log('Connection closed:', event); | ||||
|         }); | ||||
| 
 | ||||
|         // Function to send a message to the server
 | ||||
|         function sendMessage() { | ||||
|             const message = prompt('Enter a message to send:'); | ||||
|             if (message) { | ||||
|                 socket.send(message); | ||||
|             } | ||||
|         } | ||||
|     </script> | ||||
| 
 | ||||
|     <button onclick="sendMessage()">Send Message</button> | ||||
| 
 | ||||
| </body> | ||||
| </html> | ||||
|  | @ -1,6 +1,8 @@ | |||
| <?php | ||||
| 
 | ||||
| use ElephantIO\Client; | ||||
| use GuzzleHttp\Client as GuzzleHttpClient; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Support\Facades\Route; | ||||
| 
 | ||||
| /* | ||||
|  | @ -18,5 +20,4 @@ Route::get('/', function () { | |||
|     return view('welcome'); | ||||
| }); | ||||
| 
 | ||||
| Route::get('/socket', function () { | ||||
| }); | ||||
| Route::view('/queue', 'queue'); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue