GET http://127.0.0.1:8000/socket.io/?EIO=4&transport=polling&t=OLNuZgo 404 (Not Found)
var app = require('express')(); var http = require('http').Server(app); var io = require('socket.io')(http); const port = process.env.PORT || 8000; var users =[]; http.listen(port, function () { console.log(`Listening to port ${port}`); }); io.on('connection', function (socket) { socket.on("user_connected", function (user_id) { users[user_id] = socket.id; io.emit('updateUserStatus', users); console.log("user connected "+ user_id); }); });
@push('scripts') <script> $(function (){ let user_id = "{{ Session::get('loginId'), }}"; let ip_address = '127.0.0.1'; let socket_port = '8000'; let socket = io(ip_address + ':' + socket_port); socket.on('connect', function() { socket.emit('user_connected', user_id); }); socket.on('updateUserStatus', (data) => { let $userStatusIcon = $('.user-status-icon'); $userStatusIcon.removeClass('text-success'); $userStatusIcon.attr('title', 'Away'); $.each(data, function (key, val) { if (val !== null && val !== 0) { let $userIcon = $(".user-icon-"+key); $userIcon.addClass('text-success'); $userIcon.attr('title','Online'); } }); }); }); </script> @endpush
console.log(`Listening to port ${port}`);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)