Hi,
I’m a newbie.
I set out to learn by creating a custom socket to do some latency type measurements.
In javascript I created a regular websocket.
I am using @behaviour Phoenix.Socket.Transport
Authentication and part of the sending of messages work.
’ this.socket.send(“start”);’ in javascript
and
@impl true
def handle_in({"start", _opts}, state) do
Rtc.Generic.Dev.debug_msg("handle in ", fn -> "handle_in : start: #{inspect(state)}" end)
{:ok, %{"beat"=>"beat"}}
end
results in ‘handle_in : start: %{token: “CGhIJW1MLzlNJBtNRSQyWAw”}’
Reading the data from the client is a different matter though.
sendHeartBeat(token, heartbeat_rate) {
if (this.socket) {
var sum = 0;
for(let key in this.timesArray) {
sum += this.timesArray[key]
};
var average = Math.round(sum/10);
var maxi = Math.max(...this.timesArray);
this.socket.send("heart", { token: token, avg: average, max: maxi});
}
this.scheduleHeartBeat(token, heartbeat_rate);
}
Does get sent.
@impl true
def handle_in({text, _opts}, state) do
tx = text
|> Jason.decode()
|> elem(1)
{:reply, :ok, {:text, "beat"}, state}
end
Seemed to work at one point, but when I came back to the code it stopped working.
The state does contain the token though.
I tried changing the information sent from javascript, working with patternmatching on various handel_in defs and to construct a case within a handle_in, but nothing sticks.
Any suggestion would be appreciated, thanks