Elephant.io + Socket.io return [对象对象]

Elephant.io + Socket.io return [object Object]

我试图在 symfony2 应用程序上与 Elephant.io(Elephantio 捆绑包)和 Socket.io 进行实时聊天。

socket.io 服务器和我的 symfony 应用程序之间的连接运行良好,但是当我尝试将数据传递给 socket.io 它时 return [object Object].

我是这样做的:

#Config.yml
nc_elephant_io:
    clients:
        default:
            connection: http://localhost:3006
            version: 1.x
        socketio_key:
            connection: http://localhost:3000
            version: 1.x

我的控制器

public function indexAction()
{
    $client = $this->get('elephantio_client.socketio_key');
    $elephantIOClient = $client->getElephantIO();

    $elephantIOClient->initialize();
    $elephantIOClient->emit('chat message', ['msg' => 'bar']);
    $elephantIOClient->close();

    return $this->render('default/index.html.twig');
}

我的server.js

var io = require('socket.io').listen(3000);

io.on('connection', function(socket){
    console.log('a user connected');
    
    socket.on('chat message', function(msg){
        console.log('message: ' + msg);
    });

    socket.on('disconnect', function(){
        console.log('user disconnected');
    });
});

当我刷新我的索引页面时 return

a user connected

但是我的“消息”数据就在这里声明

$elephantIOClient->emit('chat message', ['msg' => 'bar']);

未呈现或未传递给 socket.io 并且它 return

a user connected

message: [object Object]

user disconnected

我已经阅读过关于这个问题的主题,但从未阅读过 php / elephant.io 实现。

有人遇到过这个问题吗?或者您有解决这个问题的想法吗?

谢谢。

抱歉回复晚了,但由于我正在我的项目中处理 socket.io 和 elephant.io,所以才来到这里。 不管怎样,你的连接是完美的,因为你在客户端记录一个对象 console.log('message: ' + msg); 你得到 [object Object] 作为结果。尝试 . 运算符来获取实际数据。

socket.on('chat message', function(msg){  
   console.log('message: ' + msg.msg);
                               //^^^^-- here since you are sending your object as "msg" from server
}