forked from OpenFPGAduino/Arduinojs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync.html
More file actions
48 lines (35 loc) · 1.3 KB
/
sync.html
File metadata and controls
48 lines (35 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Data sync</title>
<script src="/socket.io/socket.io.js"></script>
<script src="https://wzrd.in/standalone/diffsync"></script>
<script>
// if installed from standalone script or browserify / webpack
var DiffSyncClient = diffsync.Client || require('diffsync').Client
// socket.io standalone or browserify / webpack
var socket = window.io || require('socket.io-client')
// pass the connection and the id of the data you want to synchronize
var client = new DiffSyncClient(socket(), "lizhizhou");
var data = {};
client.on('connected', function() {
// the initial data has been loaded,
// you can initialize your application
data = client.getData();
});
client.on('synced', function() {
// an update from the server has been applied
// you can perform the updates in your application now
data = client.getData();
});
client.initialize();
/* --- somewhere in your code --- */
data.randomChange = Math.random();
// schedule a sync cycle - this will sync your changes to the server
client.sync();
</script>
</head>
<body>
</body>
</html>