Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gsoc22] Fix realtime data update example #141

Merged
merged 4 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions examples/data/netjsonnode/package.json

This file was deleted.

6 changes: 3 additions & 3 deletions examples/netjson-updateData.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<link href="../src/css/netjsongraph.css" rel="stylesheet">
</head>
<body>
<script type="text/javascript" src="../lib/js/socket.io.js"></script>
<script src="https://cdn.socket.io/4.5.0/socket.io.min.js" integrity="sha384-7EyYLQZgWBi67fBtVxw60/OWl1kjsfrPFcaU0pp0nAh+i8FD068QogUvg85Ewy1k" crossorigin="anonymous"></script>
<script type="text/javascript" src="../dist/netjsongraph.min.js"></script>
<script type="text/javascript">
/*
Expand All @@ -25,7 +25,7 @@

graph.render();

const socket = io("http://localhost:8078");
const socket = io("http://localhost:3000/",{ transports : ['websocket'] });

socket.on("connect", function() {
console.log("client connect");
Expand All @@ -37,4 +37,4 @@
// Update view when the data changes. override old data defaultly.
socket.on("netjsonChange", graph.utils.JSONDataUpdate.bind(graph));
</script>
</html>
</html>
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
const io = require("socket.io")(8078);
const express = require("express");
const http = require("http");
const {Server} = require("socket.io");

const app = express();
const server = http.createServer(app);
const io = new Server(server);

app.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader(
"Access-Control-Allow-Methods",
"POST, GET, OPTIONS, PUT, PATCH, DELETE",
);
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
next();
});

let JSONData = {
type: "NetworkGraph",
label: "Ninux Roma",
Expand Down Expand Up @@ -155,7 +172,7 @@ let JSONData = {
};

io.on("connection", function (socket) {
console.log("client connection");
console.log("client connected");

socket.on("disconnect", function () {
console.log("client disconnected");
Expand All @@ -164,3 +181,11 @@ io.on("connection", function (socket) {
socket.emit("netjsonChange", JSONData);
}, 5000);
});

app.use("/", (req, res) => {
res.json(JSONData);
});

server.listen(3000, () => {
console.log("listening on:3000");
});
16 changes: 16 additions & 0 deletions examples/realtime_server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "realtime_server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.18.1",
"socket.io": "^4.5.1"
}
}
9 changes: 0 additions & 9 deletions lib/js/socket.io.js

This file was deleted.