This repository has been archived by the owner on May 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulp-server.js
79 lines (61 loc) · 3.77 KB
/
gulp-server.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
'use strict';
var _ = require('lodash');
module.exports = function (gulp) {
gulp.task('server', function () {
var express = require('express');
var httpLib = require('http');
var socketIo = require('socket.io');
var app = express();
var http = httpLib.Server(app);
var io = socketIo(http);
var orders = generateOrders();
setInterval(sendOrders, 10000);
http.listen(3030, function () {
console.log('express starting on 3030');
});
function sendOrders() {
changeOrders(orders);
io.emit('orders', orders);
}
});
};
function generateOrders() {
var size = 312 * 10;
var orders = [];
for (var i = 0; i < size; i++) {
var order = orders[i] = {id: i};
randomizeStatusAndImg(order);
}
return orders;
}
function randomizeStatusAndImg(order) {
order.img = imgs[_.random(0, imgs.length - 1)];
order.status = statuses[_.random(0, statuses.length - 1)];
}
function changeOrders(orders) {
var numberToChange = _.random(0, orders.length - 1);
var indicesToChange = {};
for (let i = 0; i < numberToChange; i++) {
var index;
do {
index = _.random(0, orders.length - 1);
} while (indicesToChange[index]);
indicesToChange[index] = true;
}
indicesToChange = _.keys(indicesToChange);
for (let i = 0; i < indicesToChange.length; i++) {
var order = orders[parseInt(indicesToChange[i])];
randomizeStatusAndImg(order);
}
}
var imgs = [
'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2NjIpLCBxdWFsaXR5ID0gNjUK/9sAQwALCAgKCAcLCgkKDQwLDREcEhEPDxEiGRoUHCkkKyooJCcnLTJANy0wPTAnJzhMOT1DRUhJSCs2T1VORlRAR0hF/9sAQwEMDQ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