My game works with other browsers but with Firefox, there is a one small but major issue. Why firefox does not emit the "new-player" message after socket connection, other browsers work OK , all browsers output HELLO to console...and register themself.
我的游戏适用于其他浏览器,但使用Firefox,有一个小但很重要的问题。为什么firefox在套接字连接后没有发出“new-player”消息,其他浏览器工作正常,所有浏览器都输出HELLO到控制台......并注册自己。
const newPlayer = (socket, player) => {
socket.on('connect', () => {
console.log("HELLO this row appears in all browsers");
socket.emit('new-player', {
x: player.sprite.body.x,
y: player.sprite.body.y,
angle: player.sprite.rotation,
playerName: {
name: String(socket.id),
x: player.playerName.x,
y: player.playerName.y
},
speed: {
value: player.speed,
x: player.speed.x,
y: player.speed.y
}
})
})
}
export default newPlayer
problem on server side: new-player message not received with firefox, other browsers ok:
服务器端的问题:firefox没有收到新玩家消息,其他浏览器没问题:
io.on('connection', socket => { // When a player connects
socket.on('new-player', state => {
console.log(socket.id+'New player joined with state:', state)
players[socket.id] = state //stones[socket.id] = state
// Emit the update-players method in the client side
io.emit('update-players', players) //io.emit('update-stones', stones) })
// note the following invalid move command occurs on firefox see logs
socket.on('move-player', data => {
// If the player is invalid, return
if (players[socket.id] === undefined) {
console.log(socket.id+' invalid move')
return
}
server output with firefox:
使用firefox的服务器输出:
> [nodemon] 1.14.10 [nodemon] to restart at any time, enter `rs`
> [nodemon] watching: *.* [nodemon] starting `babel-node
> server/index.js` Game server running on: 8000 O14Q_E5LXJi3oYmGAAAA
> invalid move O14Q_E5LXJi3oYmGAAAA invalid move O14Q_E5LXJi3oYmGAAAA
> invalid move O14Q_E5LXJi3oYmGAAAA invalid move O14Q_E5LXJi3oYmGAAAA
> invalid move
server output with CHROME browser OR if the server is restarted (while firefox stays open , game on screen )
使用CHROME浏览器输出服务器或重启服务器(当firefox保持打开状态时,屏幕上的游戏)
> nodemon server/index.js --exec babel-node
[nodemon] 1.14.10
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `babel-node server/index.js`
Game server running on: 8000
55e5xgecEJ-QX_MqAAAANew player joined with state: { x: 2164.6852111816406,
y: 298.809814453125,
angle: 0,
playerName:
{ name: '55e5xgecEJ-QX_MqAAAA',
x: 2162.938232421875,
y: 298.80773544311523 },
speed: { value: 105 } }
1 个解决方案
#1
0
it seems this makes it work
这似乎使它成功
const newPlayer = (socket, player) => {
socket.on('connect', () => {
console.log("do nothing here actually, just log "+socket);
})
socket.emit('new-player', {
x: player.sprite.body.x,
y: player.sprite.body.y,
angle: player.sprite.rotation,
playerName: {
name: String(socket.id),
x: player.playerName.x,
y: player.playerName.y
},
speed: {
value: player.speed,
x: player.speed.x,
y: player.speed.y
}
})
}
export default newPlayer
#1
0
it seems this makes it work
这似乎使它成功
const newPlayer = (socket, player) => {
socket.on('connect', () => {
console.log("do nothing here actually, just log "+socket);
})
socket.emit('new-player', {
x: player.sprite.body.x,
y: player.sprite.body.y,
angle: player.sprite.rotation,
playerName: {
name: String(socket.id),
x: player.playerName.x,
y: player.playerName.y
},
speed: {
value: player.speed,
x: player.speed.x,
y: player.speed.y
}
})
}
export default newPlayer