pixelflut 1.7.4 → 1.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli.js +3 -12
- package/dist/cjs/index.js +11 -24
- package/dist/cjs/index.test.js +6 -15
- package/package.json +3 -3
package/dist/cjs/cli.js
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
import { Pixelflut } from './index.js';
|
|
12
|
-
void (() =>
|
|
3
|
+
void (async () => {
|
|
13
4
|
try {
|
|
14
5
|
// eslint-disable-next-line no-magic-numbers
|
|
15
|
-
const data =
|
|
6
|
+
const data = await new Pixelflut('localhost', 8080, 0).sendPixel(200, 200, 'ff0000');
|
|
16
7
|
if (data) {
|
|
17
8
|
console.info('data:', data);
|
|
18
9
|
}
|
|
@@ -22,4 +13,4 @@ void (() => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
22
13
|
console.error(error);
|
|
23
14
|
process.exit(1);
|
|
24
15
|
}
|
|
25
|
-
})
|
|
16
|
+
})();
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import dgram from 'dgram';
|
|
11
2
|
import net from 'net';
|
|
12
3
|
export class Pixelflut {
|
|
@@ -78,22 +69,18 @@ export class Pixelflut {
|
|
|
78
69
|
}
|
|
79
70
|
});
|
|
80
71
|
}
|
|
81
|
-
sendPixel(xPosition, yPosition, color) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return this.writeToTCP(message);
|
|
87
|
-
});
|
|
72
|
+
async sendPixel(xPosition, yPosition, color) {
|
|
73
|
+
console.info(`Sending #${color} at <${xPosition}, ${yPosition}> over ${this.udp ? 'UDP' : 'TCP'} to ${this.server}:${this.port}`);
|
|
74
|
+
const message = `PX ${xPosition} ${yPosition} ${color}\n`;
|
|
75
|
+
await this.createTCPConnection();
|
|
76
|
+
return this.writeToTCP(message);
|
|
88
77
|
}
|
|
89
|
-
sendPixels(pixels) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return values.filter(value => typeof value !== 'undefined');
|
|
96
|
-
});
|
|
78
|
+
async sendPixels(pixels) {
|
|
79
|
+
console.info(`Sending ${pixels.length} pixels from <${pixels[0].xPosition}, ${pixels[pixels.length - 1].yPosition}> to <${pixels[pixels.length - 1].xPosition}, ${pixels[0].yPosition}> over ${this.udp ? 'UDP' : 'TCP'} to ${this.server}:${this.port}`);
|
|
80
|
+
const messages = pixels.map(pixel => `PX ${pixel.xPosition} ${pixel.yPosition} ${pixel.color}\n`);
|
|
81
|
+
await this.createTCPConnection();
|
|
82
|
+
const values = await Promise.all(messages.map(message => this.writeToTCP(message)));
|
|
83
|
+
return values.filter(value => typeof value !== 'undefined');
|
|
97
84
|
}
|
|
98
85
|
writeToUDP(message) {
|
|
99
86
|
return new Promise((resolve, reject) => {
|
package/dist/cjs/index.test.js
CHANGED
|
@@ -1,32 +1,23 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
/* eslint-disable no-magic-numbers */
|
|
11
2
|
import { describe, test } from 'vitest';
|
|
12
3
|
import { Pixelflut } from './index.js';
|
|
13
4
|
describe.skip('Pixelflut', () => {
|
|
14
5
|
const pf = new Pixelflut('localhost', 8080, 0);
|
|
15
|
-
test('sends a pixel', () =>
|
|
16
|
-
const data =
|
|
6
|
+
test('sends a pixel', async () => {
|
|
7
|
+
const data = await pf.sendPixel(200, 200, 'ff0000');
|
|
17
8
|
if (data) {
|
|
18
9
|
console.info(data);
|
|
19
10
|
}
|
|
20
|
-
})
|
|
21
|
-
test('sends many pixels', () =>
|
|
11
|
+
});
|
|
12
|
+
test('sends many pixels', async () => {
|
|
22
13
|
const pixels = Array.from(Array(100), (_, index) => ({
|
|
23
14
|
color: '00ff00',
|
|
24
15
|
xPosition: index,
|
|
25
16
|
yPosition: index,
|
|
26
17
|
}));
|
|
27
|
-
const data =
|
|
18
|
+
const data = await pf.sendPixels(pixels);
|
|
28
19
|
if (data) {
|
|
29
20
|
console.info('data', data);
|
|
30
21
|
}
|
|
31
|
-
})
|
|
22
|
+
});
|
|
32
23
|
});
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"description": "Flood pixels",
|
|
5
5
|
"devDependencies": {
|
|
6
6
|
"rimraf": "5.0.7",
|
|
7
|
-
"typescript": "5.
|
|
7
|
+
"typescript": "5.5.2",
|
|
8
8
|
"vitest": "1.6.0"
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
@@ -26,6 +26,6 @@
|
|
|
26
26
|
"test": "vitest run"
|
|
27
27
|
},
|
|
28
28
|
"type": "module",
|
|
29
|
-
"version": "1.7.
|
|
30
|
-
"gitHead": "
|
|
29
|
+
"version": "1.7.5",
|
|
30
|
+
"gitHead": "f7a6a79286e4eb85392b5f2d33942ab166142109"
|
|
31
31
|
}
|