Solved: Missing serverData in connection object of second participant

I’m running the openvidu-js-java tutorial and made some modifications by using PHP (instead of java) to get the token session and token- all that works for the first person in the room.

When a second person joins, I get a js error
Unexpected token u in JSON at position 0
This related to the appendUserData function which uses the connection object- this part of the function
if (connection.nickName) { // Appending local video data
clientData = connection.nickName;
serverData = connection.userName;
nodeId = 'main-videodata';
} else {
clientData = JSON.parse(connection.data.split('%/%')[0]).clientData;
serverData = JSON.parse(connection.data.split('%/%')[1]).serverData;
nodeId = connection.connectionId;
}
As it’s looking not for local video data, but this line:
serverData = JSON.parse(connection.data.split('%/%')[1]).serverData;
I took a look at the connection object being passed and it looks like this:
Connection {session: Session, disposed: false, options: {…}, connectionId: "con_YF0I8w1oNL", creationTime: 1589541252652, …}
connectionId: "con_YF0I8w1oNL"
creationTime: 1589541252652
data: "{"clientData":"admin2"}"
disposed: false
options: {id: "con_YF0I8w1oNL", createdAt: 1589541252652, metadata:"{"clientData":"admin2"}", streams: Array(1)}
...

As you can see, there is no serverData element in the ‘data’ within the connection object.

As I’ve added my own session and login functionality, it’s not using SessionController.java which the docs say ‘It also stores our active video-calls and the users connected to them’. Is this the issue?

Can anyone confirm that is the issue, and if so, how I might implement it in PHP?

When setting up the token, the data needed to be passed to the server in the postdata, along with the sessionid. Because it couldn’t find this json data when trying to append it to the video frame, the whole thing was erroring out. The local video (ie. the one from your camera, didn’t need to pull this data from the servers session object, so it was fine. Hope this helps others