Anders and Briegel in Python
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

websocket.js 1.1KB

il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
123456789101112131415161718192021222324252627282930313233343536
  1. var websocket = {};
  2. websocket.update = undefined;
  3. websocket.connect = function(update) {
  4. websocket.ws = new WebSocket("ws://localhost:5000");
  5. if (update){
  6. websocket.update = update;
  7. }
  8. websocket.ws.onopen = function(evt) {
  9. gui.serverMessage("Connected to server.");
  10. };
  11. websocket.ws.onerror = function(err) {
  12. gui.serverMessage("Could not connect to server.");
  13. };
  14. websocket.ws.onmessage = function(evt) {
  15. json = JSON.parse(evt.data);
  16. for (var i in json.node) {
  17. var pos = json.node[i].position;
  18. json.node[i].position = new THREE.Vector3(pos.x, pos.y, pos.z);
  19. if (json.node[i].vop === undefined){
  20. json.node[i].vop = 0;
  21. }
  22. }
  23. websocket.update(json);
  24. };
  25. websocket.ws.onclose = function(evt) {
  26. gui.serverMessage("No connection to server. <a href='#' onclick='javascript:websocket.connect()'>Reconnect</a>.", true);
  27. };
  28. };
  29. websocket.edit = function (data) {
  30. websocket.ws.send("edit:"+JSON.stringify(data));
  31. };