ElephantIO / elephant.io

Send events to a socket.io server through PHP
https://elephantio.github.io/elephant.io/
MIT License
105 stars 34 forks source link

check for valid JSON #2

Closed Anubarak closed 7 months ago

Anubarak commented 1 year ago

My Socket.IO v4 Server response for the namespace confirmation was always something like

{"sid":"JoSL0DC6A4HghxIWDBtU"}-41

instead of

{"sid":"JoSL0DC6A4HghxIWDBtU"}

So your

if (null !== ($data = json_decode($seq->getData(), true))) {

always failed since it's no valid JSON.

All I did was to confirm it always contains valid JSON and strip other data.

$data = $seq->getData();
// make sure it really is valid JSON
preg_match('#\{(?:[^{}]|(?R))*\}#s', $data, $matches);
if(\count($matches) && $matches[0]){
    $data = $matches[0];
}

Let me know if I missed anything. However with these lines everything works for me now.

tohenk commented 11 months ago

What's your server setup? It needs to be replicated so the problem can be confirmed.

Anubarak commented 10 months ago

Sorry for the late response. What do you need to know exactly? Unfortunately I'm not really into dev-ops so I have to ask specific questions to someone else