Throwing spatial data over the fence
Fri Feb 26 2021 19:52:42 GMT+0000 (Coordinated Universal Time)
Saved by
@surrealemily
@WebSocket
public class LocationDataWebSocket {
private final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
static double x;
static double y;
static double z;
static double yaw;
@OnWebSocketClose
public void onClose(int statusCode, String reason) {
HifiMC.LOGGER.info("Close: " + reason);
}
@OnWebSocketError
public void onError(Throwable t) {
HifiMC.LOGGER.error("Error: ", t);
}
@OnWebSocketConnect
public void onConnect(Session session) {
HifiMC.LOGGER.info("Connect: " + session.getRemoteAddress().getAddress());
executorService.scheduleAtFixedRate(() -> {
try {
session.getRemote().sendString("{" +
"\"x\":" + x + ", " +
"\"y\":" + y + ", " +
"\"z\":" + z + ", " +
"\"yaw\": " + yaw + "} ");
} catch (IOException e) {
try {
session.getRemote().sendString(e.toString());
} catch (IOException ef) {
}
}
},
100, 100, TimeUnit.MILLISECONDS);
}
@OnWebSocketMessage
public void onMessage(String message) {
HifiMC.LOGGER.info("Message: " + message);
}
}
content_copyCOPY
Comments