-
Notifications
You must be signed in to change notification settings - Fork 0
/
bundle.js
132 lines (109 loc) · 3.25 KB
/
bundle.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
var NetworkNode = require('./NetworkNode');
class Cable extends NetworkNode {
/**
*
* @param {Int} lifetime
*/
constructor(htmlNode, lifetime = 1000) {
super(htmlNode);
this.lifetime = lifetime;
// A ========= B
this.interfaces = {
0: null,
1: null
};
this.timer = null;
}
receive(data, input) {
super.receive(data, input);
if(this.timer !== null) {
clearTimeout(this.timer);
}
this.timer = setTimeout(() => {
console.log(`Clearing data ${this.data}`);
this.data = null;
this.timer = null;
this.updateHTML();
}, this.lifetime);
}
}
module.exports = Cable;
},{"./NetworkNode":2}],2:[function(require,module,exports){
var Packet = require('./Packet');
var ID_COUNTER = 0;
class NetworkNode {
/**
*
* @param {HTMLObjectElement} htmlNode
*/
constructor(htmlNode = null) {
this.interfaces = {};
this.data = null;
this.htmlNode = htmlNode;
}
updateHTML() {
this.htmlNode.innerHTML = this.data;
}
/**
*
* @param {*} data
* @param {NetworkNode} input
*/
receive(data, input) {
if(this.data == null) {
this.data = data;
} else {
this.data = `ERR{${this.data^data}}`;
}
this.updateHTML();
}
/**
* @param {*} data
* @param {NetworkNode} recipient
*/
send(recipient, data) {
this.interfaces[recipient].receive(data, this);
}
/**
*
* @param {NetworkNode} Cable
* @param {String} id
*/
join(node, id = 0) {
this.interfaces[id] = node;
}
}
module.exports = NetworkNode;
},{"./Packet":3}],3:[function(require,module,exports){
class Packet {
constructor(data, from, to) {
this.data = data;
this.from = from;
this.to = to;
}
toString() {
return this.data;
}
}
module.exports = Packet;
},{}],4:[function(require,module,exports){
var Packet = require('./Packet');
var Cable = require('./Cable');
var c1 = new Cable(document.getElementById('cable1'));
var c2 = new Cable(document.getElementById('cable2'));
var topology = document.getElementById('topology');
function generateCirce(target, computersNum, cableLength) {
var nodes = [];
var tmpCable;
var centerX = target.clientWidth / 2;
var centerY = target.clientHeight / 2;
for(let i = 0; i < computersNum*cableLength; i += 1) {
tmpCable = document.createElement('span');
tmpCable.style.
topology.appendChild(tmpCable);
nodes.push(new Cable(tmpCable))
}
}
generateCirce(topology, 5, 3);
},{"./Cable":1,"./Packet":3}]},{},[4]);