const socket = io("https://server-domain.com");
localhost:3000
const io = require('socket.io');
let players = {};
io.on('connection', function(socket) {
socket.on('new player', function() {
players[socket.id] = {
x: 300,
y: 300
};
});
socket.on('movement', function(data) {
var player = players[socket.id] || {};
if (data.left) {
player.x -= 5;
}
if (data.up) {
player.y -= 5;
}
if (data.right) {
player.x += 5;
}
if (data.down) {
player.y += 5;
}
});
});
setInterval(function() {
io.sockets.emit('state', players);
}, 1000 / 60);
const replacePhone = (phone) => phone.split('').map((el, i) => i === 1 || i === 4 || i === 7 || i === 9 ? el+' ' : el).join('');
console.log(replacePhone('+79031002020'));
const express = require("express");
const app = express();
server = app.listen(11050, function () {
console.log("server is running on port 11050");
});
const io = require("socket.io")(server);
io.on("connection", (socket) => {
console.log("Users component is connected");
socket.on("disconnect", () => {
console.log("Users component was disconnected");
});
setInterval(() => {
socket.emit("newNumber", generateRandomNumber());
}, 1000);
});
function generateRandomNumber() {
let number = Math.floor(Math.random() * 100);
const dateTime = new Date().getTime();
let item = {
x: dateTime,
y: number,
};
return item;
}
module.exports = { io };
const { io } = require('путь_к_файлу_донору');
io.on('connection', (socket) => {
// Логика текущего роута
})
<div className={styles.social}>
<div className={`${styles.socItem} fab fa-vk`} onClick={(e) => activeSoc(e, 'vk')}/>
<div className={`${styles.socItem} fab fa-twitter`} onClick={(e) => activeSoc(e)}/>
<div className={`${styles.socItem} fab fa-telegram`} onClick={(e) => activeSoc(e)}/>
<div className={`${styles.socItem} fab fa-facebook`} onClick={(e) => activeSoc(e, 'facebook')}/>
<div className={`${styles.socItem} fab fa-google`} onClick={(e) => activeSoc(e)}/>
<div className={`${styles.socItem} fab fa-yandex`} onClick={(e) => activeSoc(e)}/>
<div className={`${styles.socItem} fas fa-envelope`} onClick={(e) => activeSoc(e)}/>
</div></button>