瀏覽代碼

Try again with websockets

master
Pete Shadbolt 8 年之前
父節點
當前提交
2a6abed48c
共有 3 個文件被更改,包括 21 次插入16 次删除
  1. +0
    -2
      abp/clifford.py
  2. +3
    -2
      server/static/main.js
  3. +18
    -12
      server/static/poll.js

+ 0
- 2
abp/clifford.py 查看文件

@@ -146,8 +146,6 @@ try:
with open(temp("by_name.json")) as f:
by_name = json.load(f)


print "Loaded tables from cache"
except IOError:
# Spend time building the tables
unitaries = get_unitaries()


+ 3
- 2
server/static/main.js 查看文件

@@ -31,6 +31,7 @@ function startMainLoop() {
scene = makeScene();
controls.addEventListener("change", render);
poll();
render();
}

// Someone resized the window
@@ -63,12 +64,12 @@ function init() {
controls = new THREE.OrbitControls(camera);

// Center the camera
// TODO: frustrum
controls.center.set(0, 0, 0);
controls.rotateSpeed = 0.2;
camera.position.set(0, 0, 20);
camera.position.set(0, 0, 40);

// Start polling
setInterval(poll, 1000);

// Run
startMainLoop();


+ 18
- 12
server/static/poll.js 查看文件

@@ -1,19 +1,25 @@

function poll() {
var xhr = new XMLHttpRequest();

xhr.onload = function() {
var state = JSON.parse(xhr.responseText);
updateScene(state);
var ws = new WebSocket("ws://localhost:5000/echo");
ws.onopen = function()
{
// Web Socket is connected, send data using send()
ws.send("Hello from the browser! I connected okay");
console.log("Sent a message to the server");
};

xhr.onerror = function(e){
//soft_console.innerHTML = "\n" + "Lost connection to server";
ws.onmessage = function (evt)
{
var received_msg = evt.data;
console.log("I got a message from the server:");
console.log(evt.data);
};
ws.onclose = function()
{
ws.send("Bye by from the browser");
console.log("Connection is closed...");
};

xhr.open("GET", "/state", true);
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
xhr.send();
}

function updateScene(state) {


Loading…
取消
儲存