Anders and Briegel in Python
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

websocket.js 742B

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
12345678910111213141516171819202122232425
  1. var websocket = {};
  2. websocket.connect = function(update) {
  3. var ws = new WebSocket("ws://localhost:5000");
  4. ws.onopen = function(evt) {
  5. gui.serverMessage("Connected to server.");
  6. };
  7. ws.onerror = function(err) {
  8. gui.serverMessage("Could not connect to server.");
  9. };
  10. ws.onmessage = function(evt) {
  11. json = JSON.parse(evt.data);
  12. for (var i in json.node) {
  13. var pos = json.node[i].position;
  14. json.node[i].position = new THREE.Vector3(pos.x, pos.y, pos.z);
  15. }
  16. update(json);
  17. };
  18. ws.onclose = function(evt) {
  19. gui.serverMessage("No connection to server. <a href='#' onclick='javascript:websocket.connect()'>Reconnect</a>.", true);
  20. };
  21. };