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 CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  ## Installation
9
9
 
10
- ℹ️ This is a hybrid [CommonJS](https://nodejs.org/docs/latest/api/modules.html#modules-commonjs-modules) / [ESM](https://nodejs.org/api/esm.html#introduction) module.
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
 
@@ -1,5 +1,5 @@
1
- import dgram from 'dgram';
2
- import net from 'net';
1
+ import dgram from 'node:dgram';
2
+ import net from 'node:net';
3
3
  export class Pixelflut {
4
4
  // eslint-disable-next-line no-magic-numbers
5
5
  constructor(server, port, errorTolerance = 10, udp = false) {
package/package.json CHANGED
@@ -1,31 +1,27 @@
1
1
  {
2
2
  "author": "Florian Imdahl <git@ffflorian.de>",
3
- "bin": "dist/cjs/cli.js",
3
+ "bin": "dist/cli.js",
4
4
  "description": "Flood pixels",
5
5
  "devDependencies": {
6
- "rimraf": "5.0.7",
7
- "typescript": "5.4.5",
8
- "vitest": "1.6.0"
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
- "main": "dist/cjs/index.js",
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": "yarn build:cjs && yarn build:esm && yarn generate:packagejson",
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.7.4",
30
- "gitHead": "28c184f53a87d8eb082cc27c923ef7b352bbe875"
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
- }
@@ -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
- });
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }
package/dist/esm/cli.d.ts DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
@@ -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
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }
File without changes
File without changes
File without changes
File without changes
File without changes