Commit 829f49c8 authored by Nathan Bean's avatar Nathan Bean

Fixed port for ws and added queue

parent cf9cebc1
......@@ -23,3 +23,25 @@ class Stack:
response = requests.get(url)
if(response.status_code != 200):
raise RuntimeError
class Queue:
def __init__(self):
url = "http://localhost:{}/queues/new".format(PORT)
response = requests.get(url)
if response.status_code == 200:
self.id = response.text
else:
raise RuntimeError
def enqueue(self, item):
url = "http://localhost:{}/queues/{}/enqueue/{}".format(PORT, self.id, item)
response = requests.get(url)
if response.status_code != 200:
raise RuntimeError
def dequeue(self, item):
url = "http://localhost:{}/queues/{}/dequeue".format(PORT, self.id)
response = requests.get(url)
if(response.status_code != 200):
raise RuntimeError
......@@ -7,17 +7,18 @@ import queue from './queue';
const body = d3.select('body');
body.append('h1')
.text("Data Structure Visualizations");
.text("Data Structure Visualizations");
body.append('div')
.attr('id', 'visualizations');
.attr('id', 'visualizations');
// Create the websocket
const socket = new WebSocket('ws://localhost:8080');
const socket = new WebSocket(`ws://${window.location.host}`);
// Connection opened
socket.addEventListener('open', function (event) {
socket.send('Hello Server!');
// TODO: Send connection message?
//socket.send('Hello Server!');
});
// Listen for messages from the socket
......
......@@ -6,6 +6,7 @@ import * as d3 from 'd3';
* @param {Array} data - the contents of the queue
*/
export default function queue(id, data) {
console.log(id, data);
var viz = d3.select('#visualizations')
.select('#' + id);
......
......@@ -25,12 +25,10 @@ app.use(webpackDevMiddleware(compiler, {
}));
wss.on('connection', function connection(ws) {
console.log(ws);
ws.on('message', function incoming(message) {
console.log('received: %s', message);
// TODO: Handle client messages
// console.log('received: %s', message);
});
ws.send('{"type": "queue", "id": "bar", "data": [1,3,2,4,8, 2, 2323, 4, 0, 8, "foo"]}');
});
server.listen(PORT, () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment