pixelflut 1.7.4 → 1.8.0
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/cli.js +0 -25
- package/dist/cjs/index.js +0 -129
- package/dist/cjs/index.test.js +0 -32
- package/dist/cjs/package.json +0 -3
- package/dist/esm/cli.d.ts +0 -2
- package/dist/esm/index.d.ts +0 -21
- package/dist/esm/index.test.d.ts +0 -1
- package/dist/esm/package.json +0 -3
- /package/dist/{cjs/cli.d.ts → cli.d.ts} +0 -0
- /package/dist/{esm/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/{esm/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.4
|
|
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.0",
|
|
26
|
+
"gitHead": "f1a74d8ec9721d5b52a00e41b2ec73278e048290"
|
|
31
27
|
}
|
package/dist/cjs/cli.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
import { Pixelflut } from './index.js';
|
|
12
|
-
void (() => __awaiter(void 0, void 0, void 0, function* () {
|
|
13
|
-
try {
|
|
14
|
-
// eslint-disable-next-line no-magic-numbers
|
|
15
|
-
const data = yield new Pixelflut('localhost', 8080, 0).sendPixel(200, 200, 'ff0000');
|
|
16
|
-
if (data) {
|
|
17
|
-
console.info('data:', data);
|
|
18
|
-
}
|
|
19
|
-
process.exit();
|
|
20
|
-
}
|
|
21
|
-
catch (error) {
|
|
22
|
-
console.error(error);
|
|
23
|
-
process.exit(1);
|
|
24
|
-
}
|
|
25
|
-
}))();
|
package/dist/cjs/index.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
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
|
-
import dgram from 'dgram';
|
|
11
|
-
import net from 'net';
|
|
12
|
-
export class Pixelflut {
|
|
13
|
-
// eslint-disable-next-line no-magic-numbers
|
|
14
|
-
constructor(server, port, errorTolerance = 10, udp = false) {
|
|
15
|
-
this.errors = [];
|
|
16
|
-
this.udp = false;
|
|
17
|
-
this.server = server;
|
|
18
|
-
this.port = port;
|
|
19
|
-
this.udp = udp;
|
|
20
|
-
this.errorTolerance = errorTolerance;
|
|
21
|
-
if (udp) {
|
|
22
|
-
console.info('Note: UDP is not supported right now. Switching to TCP.');
|
|
23
|
-
this.udp = false;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
createTCPConnection() {
|
|
27
|
-
return new Promise((resolve, reject) => {
|
|
28
|
-
let data;
|
|
29
|
-
this.tcpSocket = new net.Socket();
|
|
30
|
-
this.tcpSocket
|
|
31
|
-
.on('data', bytes => (data += bytes.toString('utf8')))
|
|
32
|
-
.on('error', error => {
|
|
33
|
-
if (this.failed(error.message)) {
|
|
34
|
-
reject(error);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
resolve(undefined);
|
|
38
|
-
}
|
|
39
|
-
})
|
|
40
|
-
.on('close', () => {
|
|
41
|
-
if (this.failed('TCP Connection closed')) {
|
|
42
|
-
reject(new Error('TCP Connection closed'));
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
resolve(data);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
this.tcpSocket.connect(this.port, this.server, () => resolve(undefined));
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
createUDPConnection() {
|
|
52
|
-
return new Promise((resolve, reject) => {
|
|
53
|
-
this.udpSocket = dgram.createSocket('udp4');
|
|
54
|
-
let data;
|
|
55
|
-
this.udpSocket
|
|
56
|
-
.on('data', bytes => (data += bytes.toString('utf8')))
|
|
57
|
-
.on('error', error => {
|
|
58
|
-
if (this.failed(error.message)) {
|
|
59
|
-
reject(error);
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
resolve();
|
|
63
|
-
}
|
|
64
|
-
})
|
|
65
|
-
.on('close', () => {
|
|
66
|
-
if (this.failed('UDP Connection closed')) {
|
|
67
|
-
reject(new Error('UDP Connection closed'));
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
resolve();
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
if (this.tcpSocket) {
|
|
74
|
-
this.tcpSocket.connect(this.port, this.server, () => resolve());
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
reject(new Error('No TCP socket available'));
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
sendPixel(xPosition, yPosition, color) {
|
|
82
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
-
console.info(`Sending #${color} at <${xPosition}, ${yPosition}> over ${this.udp ? 'UDP' : 'TCP'} to ${this.server}:${this.port}`);
|
|
84
|
-
const message = `PX ${xPosition} ${yPosition} ${color}\n`;
|
|
85
|
-
yield this.createTCPConnection();
|
|
86
|
-
return this.writeToTCP(message);
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
sendPixels(pixels) {
|
|
90
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
-
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}`);
|
|
92
|
-
const messages = pixels.map(pixel => `PX ${pixel.xPosition} ${pixel.yPosition} ${pixel.color}\n`);
|
|
93
|
-
yield this.createTCPConnection();
|
|
94
|
-
const values = yield Promise.all(messages.map(message => this.writeToTCP(message)));
|
|
95
|
-
return values.filter(value => typeof value !== 'undefined');
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
writeToUDP(message) {
|
|
99
|
-
return new Promise((resolve, reject) => {
|
|
100
|
-
if (this.udpSocket) {
|
|
101
|
-
this.udpSocket.send(message, 0, message.length, this.port, this.server, (err, bytes) => {
|
|
102
|
-
if (err) {
|
|
103
|
-
reject(err);
|
|
104
|
-
}
|
|
105
|
-
else if (bytes) {
|
|
106
|
-
resolve(bytes.toString());
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
reject(new Error('No UDP socket available'));
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
failed(message) {
|
|
116
|
-
this.errors.push(message);
|
|
117
|
-
return this.errors.length > this.errorTolerance;
|
|
118
|
-
}
|
|
119
|
-
writeToTCP(message) {
|
|
120
|
-
return new Promise((resolve, reject) => {
|
|
121
|
-
if (this.tcpSocket) {
|
|
122
|
-
this.tcpSocket.write(message, error => (error ? reject(error) : resolve(undefined)));
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
reject(new Error('No TCP socket available'));
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
}
|
package/dist/cjs/index.test.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
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
|
-
/* eslint-disable no-magic-numbers */
|
|
11
|
-
import { describe, test } from 'vitest';
|
|
12
|
-
import { Pixelflut } from './index.js';
|
|
13
|
-
describe.skip('Pixelflut', () => {
|
|
14
|
-
const pf = new Pixelflut('localhost', 8080, 0);
|
|
15
|
-
test('sends a pixel', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
-
const data = yield pf.sendPixel(200, 200, 'ff0000');
|
|
17
|
-
if (data) {
|
|
18
|
-
console.info(data);
|
|
19
|
-
}
|
|
20
|
-
}));
|
|
21
|
-
test('sends many pixels', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
-
const pixels = Array.from(Array(100), (_, index) => ({
|
|
23
|
-
color: '00ff00',
|
|
24
|
-
xPosition: index,
|
|
25
|
-
yPosition: index,
|
|
26
|
-
}));
|
|
27
|
-
const data = yield pf.sendPixels(pixels);
|
|
28
|
-
if (data) {
|
|
29
|
-
console.info('data', data);
|
|
30
|
-
}
|
|
31
|
-
}));
|
|
32
|
-
});
|
package/dist/cjs/package.json
DELETED
package/dist/esm/cli.d.ts
DELETED
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/package.json
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|