pixelflut 1.7.5 → 1.8.1
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/README.md +1 -1
- package/dist/{esm/index.js → index.js} +2 -2
- package/package.json +8 -12
- package/dist/cjs/index.js +0 -116
- package/dist/cjs/package.json +0 -3
- package/dist/esm/cli.d.ts +0 -2
- package/dist/esm/cli.js +0 -16
- package/dist/esm/index.d.ts +0 -21
- package/dist/esm/index.test.d.ts +0 -1
- package/dist/esm/index.test.js +0 -23
- package/dist/esm/package.json +0 -3
- /package/dist/{cjs/cli.d.ts → cli.d.ts} +0 -0
- /package/dist/{cjs/cli.js → cli.js} +0 -0
- /package/dist/{cjs/index.d.ts → index.d.ts} +0 -0
- /package/dist/{cjs/index.test.d.ts → index.test.d.ts} +0 -0
- /package/dist/{cjs/index.test.js → index.test.js} +0 -0
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
## Installation
|
|
9
9
|
|
|
10
|
-
ℹ️ This is a
|
|
10
|
+
ℹ️ This is a pure [ESM](https://nodejs.org/api/esm.html#introduction) module.
|
|
11
11
|
|
|
12
12
|
Run `yarn add pixelflut` or `npm i pixelflut`.
|
|
13
13
|
|
package/package.json
CHANGED
|
@@ -1,31 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Florian Imdahl <git@ffflorian.de>",
|
|
3
|
-
"bin": "dist/
|
|
3
|
+
"bin": "dist/cli.js",
|
|
4
4
|
"description": "Flood pixels",
|
|
5
5
|
"devDependencies": {
|
|
6
|
-
"rimraf": "
|
|
7
|
-
"typescript": "5.5.
|
|
8
|
-
"vitest": "
|
|
6
|
+
"rimraf": "6.0.1",
|
|
7
|
+
"typescript": "5.5.4",
|
|
8
|
+
"vitest": "2.0.5"
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
11
|
"dist"
|
|
12
12
|
],
|
|
13
13
|
"license": "GPL-3.0",
|
|
14
|
-
"
|
|
15
|
-
"module": "dist/esm/index.js",
|
|
14
|
+
"module": "dist/index.js",
|
|
16
15
|
"name": "pixelflut",
|
|
17
16
|
"repository": "https://github.com/ffflorian/node-packages/tree/main/packages/pixelflut",
|
|
18
17
|
"scripts": {
|
|
19
|
-
"build": "
|
|
20
|
-
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
21
|
-
"build:esm": "tsc -p tsconfig.json",
|
|
18
|
+
"build": "tsc -p tsconfig.json",
|
|
22
19
|
"clean": "rimraf dist",
|
|
23
20
|
"dist": "yarn clean && yarn build",
|
|
24
|
-
"generate:packagejson": "../../bin/generate-hybrid-package-json.sh",
|
|
25
21
|
"start": "node --loader ts-node/esm src/cli.ts",
|
|
26
22
|
"test": "vitest run"
|
|
27
23
|
},
|
|
28
24
|
"type": "module",
|
|
29
|
-
"version": "1.
|
|
30
|
-
"gitHead": "
|
|
25
|
+
"version": "1.8.1",
|
|
26
|
+
"gitHead": "aadf648655ecd0f6bea0c989542a16ff636c71a7"
|
|
31
27
|
}
|
package/dist/cjs/index.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import dgram from 'dgram';
|
|
2
|
-
import net from 'net';
|
|
3
|
-
export class Pixelflut {
|
|
4
|
-
// eslint-disable-next-line no-magic-numbers
|
|
5
|
-
constructor(server, port, errorTolerance = 10, udp = false) {
|
|
6
|
-
this.errors = [];
|
|
7
|
-
this.udp = false;
|
|
8
|
-
this.server = server;
|
|
9
|
-
this.port = port;
|
|
10
|
-
this.udp = udp;
|
|
11
|
-
this.errorTolerance = errorTolerance;
|
|
12
|
-
if (udp) {
|
|
13
|
-
console.info('Note: UDP is not supported right now. Switching to TCP.');
|
|
14
|
-
this.udp = false;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
createTCPConnection() {
|
|
18
|
-
return new Promise((resolve, reject) => {
|
|
19
|
-
let data;
|
|
20
|
-
this.tcpSocket = new net.Socket();
|
|
21
|
-
this.tcpSocket
|
|
22
|
-
.on('data', bytes => (data += bytes.toString('utf8')))
|
|
23
|
-
.on('error', error => {
|
|
24
|
-
if (this.failed(error.message)) {
|
|
25
|
-
reject(error);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
resolve(undefined);
|
|
29
|
-
}
|
|
30
|
-
})
|
|
31
|
-
.on('close', () => {
|
|
32
|
-
if (this.failed('TCP Connection closed')) {
|
|
33
|
-
reject(new Error('TCP Connection closed'));
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
resolve(data);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
this.tcpSocket.connect(this.port, this.server, () => resolve(undefined));
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
createUDPConnection() {
|
|
43
|
-
return new Promise((resolve, reject) => {
|
|
44
|
-
this.udpSocket = dgram.createSocket('udp4');
|
|
45
|
-
let data;
|
|
46
|
-
this.udpSocket
|
|
47
|
-
.on('data', bytes => (data += bytes.toString('utf8')))
|
|
48
|
-
.on('error', error => {
|
|
49
|
-
if (this.failed(error.message)) {
|
|
50
|
-
reject(error);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
resolve();
|
|
54
|
-
}
|
|
55
|
-
})
|
|
56
|
-
.on('close', () => {
|
|
57
|
-
if (this.failed('UDP Connection closed')) {
|
|
58
|
-
reject(new Error('UDP Connection closed'));
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
resolve();
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
if (this.tcpSocket) {
|
|
65
|
-
this.tcpSocket.connect(this.port, this.server, () => resolve());
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
reject(new Error('No TCP socket available'));
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
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);
|
|
77
|
-
}
|
|
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');
|
|
84
|
-
}
|
|
85
|
-
writeToUDP(message) {
|
|
86
|
-
return new Promise((resolve, reject) => {
|
|
87
|
-
if (this.udpSocket) {
|
|
88
|
-
this.udpSocket.send(message, 0, message.length, this.port, this.server, (err, bytes) => {
|
|
89
|
-
if (err) {
|
|
90
|
-
reject(err);
|
|
91
|
-
}
|
|
92
|
-
else if (bytes) {
|
|
93
|
-
resolve(bytes.toString());
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
reject(new Error('No UDP socket available'));
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
failed(message) {
|
|
103
|
-
this.errors.push(message);
|
|
104
|
-
return this.errors.length > this.errorTolerance;
|
|
105
|
-
}
|
|
106
|
-
writeToTCP(message) {
|
|
107
|
-
return new Promise((resolve, reject) => {
|
|
108
|
-
if (this.tcpSocket) {
|
|
109
|
-
this.tcpSocket.write(message, error => (error ? reject(error) : resolve(undefined)));
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
reject(new Error('No TCP socket available'));
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
}
|
package/dist/cjs/package.json
DELETED
package/dist/esm/cli.d.ts
DELETED
package/dist/esm/cli.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { Pixelflut } from './index.js';
|
|
3
|
-
void (async () => {
|
|
4
|
-
try {
|
|
5
|
-
// eslint-disable-next-line no-magic-numbers
|
|
6
|
-
const data = await new Pixelflut('localhost', 8080, 0).sendPixel(200, 200, 'ff0000');
|
|
7
|
-
if (data) {
|
|
8
|
-
console.info('data:', data);
|
|
9
|
-
}
|
|
10
|
-
process.exit();
|
|
11
|
-
}
|
|
12
|
-
catch (error) {
|
|
13
|
-
console.error(error);
|
|
14
|
-
process.exit(1);
|
|
15
|
-
}
|
|
16
|
-
})();
|
package/dist/esm/index.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export declare class Pixelflut {
|
|
2
|
-
errors: string[];
|
|
3
|
-
private readonly errorTolerance;
|
|
4
|
-
private readonly port;
|
|
5
|
-
private readonly server;
|
|
6
|
-
private tcpSocket?;
|
|
7
|
-
private readonly udp;
|
|
8
|
-
private udpSocket?;
|
|
9
|
-
constructor(server: string, port: number, errorTolerance?: number, udp?: boolean);
|
|
10
|
-
createTCPConnection(): Promise<string | void>;
|
|
11
|
-
createUDPConnection(): Promise<void>;
|
|
12
|
-
sendPixel(xPosition: number, yPosition: number, color: string): Promise<string>;
|
|
13
|
-
sendPixels(pixels: Array<{
|
|
14
|
-
color: string;
|
|
15
|
-
xPosition: number;
|
|
16
|
-
yPosition: number;
|
|
17
|
-
}>): Promise<string[]>;
|
|
18
|
-
writeToUDP(message: string): Promise<any>;
|
|
19
|
-
private failed;
|
|
20
|
-
private writeToTCP;
|
|
21
|
-
}
|
package/dist/esm/index.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/esm/index.test.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-magic-numbers */
|
|
2
|
-
import { describe, test } from 'vitest';
|
|
3
|
-
import { Pixelflut } from './index.js';
|
|
4
|
-
describe.skip('Pixelflut', () => {
|
|
5
|
-
const pf = new Pixelflut('localhost', 8080, 0);
|
|
6
|
-
test('sends a pixel', async () => {
|
|
7
|
-
const data = await pf.sendPixel(200, 200, 'ff0000');
|
|
8
|
-
if (data) {
|
|
9
|
-
console.info(data);
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
test('sends many pixels', async () => {
|
|
13
|
-
const pixels = Array.from(Array(100), (_, index) => ({
|
|
14
|
-
color: '00ff00',
|
|
15
|
-
xPosition: index,
|
|
16
|
-
yPosition: index,
|
|
17
|
-
}));
|
|
18
|
-
const data = await pf.sendPixels(pixels);
|
|
19
|
-
if (data) {
|
|
20
|
-
console.info('data', data);
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
});
|
package/dist/esm/package.json
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|