ngx-web-serial 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -1,22 +1,22 @@
1
- [![npm version](https://badge.fury.io/js/angular-web-serial.svg?icon=si%3Anpm)](https://badge.fury.io/js/angular-web-serial)
2
1
  [![Publish to GitHub Packages](https://github.com/mattfors/ngx-web-serial/actions/workflows/build.yml/badge.svg)](https://github.com/mattfors/ngx-web-serial/actions/workflows/build.yml)
3
- [![codecov](https://codecov.io/github/mattfors/ngx-web-serial/graph/badge.svg?token=GRL2B8OCW5)](https://codecov.io/github/mattfors/ngx-web-serial)
4
2
 
5
- # Angular Web Serial
3
+ # NgxWebSerial
6
4
 
7
- Angular Web Serial is an angular module for connecting to serial devices with the Web Serial API.
5
+ NgxWebSerial is an angular library for connecting to serial devices with the Web Serial API and RxJS.
6
+
7
+ Connecting, transmitting and receiving data are abstracted to RxJS observables which will be familiar to anyone using Angular.
8
8
 
9
9
  ## Installation
10
10
 
11
11
  ```shell
12
- npm i angular-web-serial
12
+ npm i ngx-web-serial
13
13
  ```
14
14
 
15
15
  ## Usage
16
- Below is the basic usage of the module. A pipe is used to accumulate the raw data from the serial port.
16
+ Below demonstrates the basic usage. A pipe is used to accumulate the raw data from the serial port.
17
17
  ```typescript
18
18
  import { Component } from '@angular/core';
19
- import { AngularSerialService, provideAngularSerial } from '../../../ngx-web-serial/src';
19
+ import { NgxWebSerial, provideNgxWebSerial } from 'ngx-web-serial';
20
20
  import { Observable, scan } from 'rxjs';
21
21
  import { AsyncPipe } from '@angular/common';
22
22
 
@@ -24,7 +24,7 @@ import { AsyncPipe } from '@angular/common';
24
24
  selector: 'app-root',
25
25
  standalone: true,
26
26
  imports: [AsyncPipe],
27
- providers: [provideAngularSerial()],
27
+ providers: [provideNgxWebSerial()],
28
28
  template: `
29
29
  <button (click)="open()">Open</button>
30
30
  <input #inputField
@@ -40,7 +40,7 @@ export class AppComponent {
40
40
 
41
41
  data$: Observable<string>;
42
42
 
43
- constructor(private serial: AngularSerialService) {
43
+ constructor(private serial: NgxWebSerial) {
44
44
  this.data$ = this.serial.read().pipe(
45
45
  scan((acc, value) => acc + value, '')
46
46
  );
@@ -51,7 +51,7 @@ export class AppComponent {
51
51
  }
52
52
 
53
53
  write(value: string): void {
54
- this.serial.write(value + '\r').subscribe();
54
+ this.serial.write(value).subscribe();
55
55
  }
56
56
 
57
57
  }
@@ -61,5 +61,5 @@ export class AppComponent {
61
61
  ## Mock serial device
62
62
  The module can be used with a mock serial device for testing or if you do not have a real serial device. Provide a function which takes and returns a string. In this example, the text transmitted to the serial device will be echoed back with 'Hello'.
63
63
  ```typescript
64
- providers: [provideAngularSerialTest(i => `Hello ${i}!\n`)]
64
+ providers: [provideNgxWebSerialTest(i => `Hello ${i}!\n`)]
65
65
  ```
@@ -3,7 +3,7 @@ import { BehaviorSubject, catchError, filter, firstValueFrom, from, interval, ma
3
3
  import { DOCUMENT } from '@angular/common';
4
4
  import { MockSerial } from './mock-serial';
5
5
  import * as i0 from "@angular/core";
6
- export class NgxWebSerialService {
6
+ export class NgxWebSerial {
7
7
  constructor(serial, ngZone) {
8
8
  this.serial = serial;
9
9
  this.ngZone = ngZone;
@@ -92,18 +92,18 @@ export class NgxWebSerialService {
92
92
  this.abortController.abort();
93
93
  }
94
94
  }
95
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: NgxWebSerialService, deps: [{ token: 'Serial' }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable }); }
96
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: NgxWebSerialService }); }
95
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: NgxWebSerial, deps: [{ token: 'Serial' }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable }); }
96
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: NgxWebSerial }); }
97
97
  }
98
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: NgxWebSerialService, decorators: [{
98
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: NgxWebSerial, decorators: [{
99
99
  type: Injectable
100
100
  }], ctorParameters: () => [{ type: undefined, decorators: [{
101
101
  type: Inject,
102
102
  args: ['Serial']
103
103
  }] }, { type: i0.NgZone }] });
104
- export function provideAngularSerial() {
104
+ export function provideNgxWebSerial() {
105
105
  return [
106
- NgxWebSerialService,
106
+ NgxWebSerial,
107
107
  {
108
108
  provide: 'Serial',
109
109
  useFactory: (document) => document.defaultView?.navigator?.serial,
@@ -111,9 +111,9 @@ export function provideAngularSerial() {
111
111
  }
112
112
  ];
113
113
  }
114
- export function provideAngularSerialTest(responseFunction) {
114
+ export function provideNgxWebSerialTest(responseFunction) {
115
115
  return [
116
- NgxWebSerialService,
116
+ NgxWebSerial,
117
117
  {
118
118
  provide: 'Serial',
119
119
  useFactory: () => new MockSerial(responseFunction || ((input) => input)),
@@ -121,4 +121,4 @@ export function provideAngularSerialTest(responseFunction) {
121
121
  }
122
122
  ];
123
123
  }
124
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmd4LXdlYi1zZXJpYWwuc2VydmljZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3Byb2plY3RzL25neC13ZWItc2VyaWFsL3NyYy9saWIvbmd4LXdlYi1zZXJpYWwuc2VydmljZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQW1CLE1BQU0sRUFBRSxVQUFVLEVBQW9CLE1BQU0sZUFBZSxDQUFDO0FBQ3RGLE9BQU8sRUFDTCxlQUFlLEVBQ2YsVUFBVSxFQUNWLE1B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4gICAgICBkZXBzOiBbXVxuICAgIH0gYXMgRmFjdG9yeVByb3ZpZGVyXG4gIF07XG59XG4iXX0=
@@ -34,7 +34,7 @@ class MockSerial {
34
34
  }
35
35
  }
36
36
 
37
- class NgxWebSerialService {
37
+ class NgxWebSerial {
38
38
  constructor(serial, ngZone) {
39
39
  this.serial = serial;
40
40
  this.ngZone = ngZone;
@@ -123,18 +123,18 @@ class NgxWebSerialService {
123
123
  this.abortController.abort();
124
124
  }
125
125
  }
126
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: NgxWebSerialService, deps: [{ token: 'Serial' }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable }); }
127
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: NgxWebSerialService }); }
126
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: NgxWebSerial, deps: [{ token: 'Serial' }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable }); }
127
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: NgxWebSerial }); }
128
128
  }
129
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: NgxWebSerialService, decorators: [{
129
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: NgxWebSerial, decorators: [{
130
130
  type: Injectable
131
131
  }], ctorParameters: () => [{ type: undefined, decorators: [{
132
132
  type: Inject,
133
133
  args: ['Serial']
134
134
  }] }, { type: i0.NgZone }] });
135
- function provideAngularSerial() {
135
+ function provideNgxWebSerial() {
136
136
  return [
137
- NgxWebSerialService,
137
+ NgxWebSerial,
138
138
  {
139
139
  provide: 'Serial',
140
140
  useFactory: (document) => document.defaultView?.navigator?.serial,
@@ -142,9 +142,9 @@ function provideAngularSerial() {
142
142
  }
143
143
  ];
144
144
  }
145
- function provideAngularSerialTest(responseFunction) {
145
+ function provideNgxWebSerialTest(responseFunction) {
146
146
  return [
147
- NgxWebSerialService,
147
+ NgxWebSerial,
148
148
  {
149
149
  provide: 'Serial',
150
150
  useFactory: () => new MockSerial(responseFunction || ((input) => input)),
@@ -161,5 +161,5 @@ function provideAngularSerialTest(responseFunction) {
161
161
  * Generated bundle index. Do not edit.
162
162
  */
163
163
 
164
- export { NgxWebSerialService, provideAngularSerial, provideAngularSerialTest };
164
+ export { NgxWebSerial, provideNgxWebSerial, provideNgxWebSerialTest };
165
165
  //# sourceMappingURL=ngx-web-serial.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"ngx-web-serial.mjs","sources":["../../../projects/ngx-web-serial/src/lib/mock-serial.ts","../../../projects/ngx-web-serial/src/lib/ngx-web-serial.service.ts","../../../projects/ngx-web-serial/src/public-api.ts","../../../projects/ngx-web-serial/src/ngx-web-serial.ts"],"sourcesContent":["export class MockSerial {\n private readableController: ReadableStreamDefaultController<Uint8Array> | null = null;\n readonly responseFunction: (input: string) => string;\n readonly readableStream: ReadableStream<Uint8Array>;\n constructor(responseFunction: (input: string) => string) {\n this.responseFunction = responseFunction;\n this.readableStream = new ReadableStream({\n start: (controller) => {\n this.readableController = controller;\n },\n cancel: () => {\n this.readableController = null;\n }\n });\n }\n\n requestPort(options?: SerialPortRequestOptions): Promise<SerialPort> {\n return Promise.resolve({\n open: () => Promise.resolve(),\n close: () => this.readableStream.cancel(),\n readable: this.readableStream,\n writable: new WritableStream({\n write: (chunk) => {\n const input = new TextDecoder().decode(chunk);\n const response = this.responseFunction(input);\n if (this.readableController) {\n this.readableController.enqueue(new TextEncoder().encode(response));\n }\n }\n })\n } as any as SerialPort);\n }\n}\n","import { FactoryProvider, Inject, Injectable, NgZone, Provider } from '@angular/core';\nimport {\n BehaviorSubject,\n catchError,\n filter,\n firstValueFrom,\n from,\n interval,\n map,\n Observable,\n Subject,\n Subscriber,\n takeUntil,\n throwError,\n timer\n} from 'rxjs';\nimport { DOCUMENT } from '@angular/common';\nimport { MockSerial } from './mock-serial';\n\n@Injectable()\nexport class NgxWebSerialService {\n\n private port: SerialPort | null = null;\n private abortController: AbortController | null = null;\n private dataStream: WritableStream | null = null;\n private dataSubject: Subject<string> = new Subject<string>();\n private writer: WritableStreamDefaultWriter<Uint8Array> | null = null;\n private connectedSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);\n\n private readonly sink: UnderlyingSink = {\n write: (chunk: any) => {\n this.ngZone.run(() => {\n this.dataSubject.next(chunk);\n });\n }\n }\n\n constructor(\n @Inject('Serial') readonly serial: Serial | undefined,\n private ngZone: NgZone\n ) {\n }\n\n /**\n * Establishes a connection to a serial port using the Web Serial API.\n */\n open(serialOptions: SerialOptions = { baudRate: 9600 }, options?: SerialPortRequestOptions): Observable<void> {\n return new Observable<void>((observer: Subscriber<void>) => {\n if (!this.serial) {\n observer.error('Web serial not supported.');\n return;\n }\n this.serial.requestPort(options)\n .then((port: SerialPort) => {\n this.port = port;\n return this.port.open(serialOptions);\n })\n .then(() => {\n if (!this.port?.readable || !this.port?.writable) {\n observer.error('Port is not readable or writable.');\n return;\n }\n this.connectedSubject.next(true);\n this.abortController = new AbortController();\n this.dataStream = new WritableStream(this.sink);\n this.writer = this.port?.writable.getWriter();\n observer.next();\n return this.port.readable\n .pipeThrough(new TextDecoderStream())\n .pipeTo(this.dataStream, {signal: this.abortController.signal})\n .catch(() => this.closePort().catch((err) => observer.error(err)));\n })\n .catch((err) => observer.error(err))\n .finally(() => observer.complete());\n });\n }\n\n isConnected(): Observable<boolean> {\n return this.connectedSubject.asObservable();\n }\n\n read(): Observable<string> {\n return this.dataSubject.asObservable();\n }\n\n write(data: string): Observable<void> {\n if (this.writer) {\n return from(this.writer.write(new TextEncoder().encode(data)));\n\n }\n return throwError(() => new Error('No writer available.'));\n }\n\n\n private waitForReadableUnlock(period: number = 50, timeout: number = 5000): Promise<void> {\n return firstValueFrom(interval(period).pipe(\n filter(() => !this.port?.readable?.locked),\n map(() => undefined),\n takeUntil(timer(timeout)),\n catchError(() => throwError(() => new Error('Timeout waiting for readable stream to unlock')))\n ));\n }\n\n private closePort(): Promise<void> {\n this.abortController = null;\n if (this.writer) {\n this.writer.releaseLock();\n this.writer = null;\n }\n if (this.port) {\n return this.waitForReadableUnlock()\n .then(() => this.port!.close())\n .then(() => {\n this.port = null;\n this.connectedSubject.next(false);\n });\n } else {\n return Promise.resolve();\n }\n }\n close(): void {\n if (this.abortController) {\n this.abortController.abort();\n }\n }\n}\n\nexport function provideAngularSerial(): Provider[] {\n return [\n NgxWebSerialService,\n {\n provide: 'Serial',\n useFactory: (document: Document) => document.defaultView?.navigator?.serial,\n deps: [DOCUMENT]\n }\n ];\n}\n\nexport function provideAngularSerialTest(responseFunction?: (input: string) => string): Provider[] {\n return [\n NgxWebSerialService,\n {\n provide: 'Serial',\n useFactory: () => new MockSerial(responseFunction || ((input: string) => input)),\n deps: []\n } as FactoryProvider\n ];\n}\n","/*\n * Public API Surface of ngx-web-serial\n */\n\nexport * from './lib/ngx-web-serial.service';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;MAAa,UAAU,CAAA;AAIrB,IAAA,WAAA,CAAY,gBAA2C,EAAA;QAH/C,IAAkB,CAAA,kBAAA,GAAuD,IAAI;AAInF,QAAA,IAAI,CAAC,gBAAgB,GAAG,gBAAgB;AACxC,QAAA,IAAI,CAAC,cAAc,GAAG,IAAI,cAAc,CAAC;AACvC,YAAA,KAAK,EAAE,CAAC,UAAU,KAAI;AACpB,gBAAA,IAAI,CAAC,kBAAkB,GAAG,UAAU;aACrC;YACD,MAAM,EAAE,MAAK;AACX,gBAAA,IAAI,CAAC,kBAAkB,GAAG,IAAI;;AAEjC,SAAA,CAAC;;AAGJ,IAAA,WAAW,CAAC,OAAkC,EAAA;QAC5C,OAAO,OAAO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,YAAA,UAAU,EAAE,MAAM,IAAI,UAAU,CAAC,gBAAgB,KAAK,CAAC,KAAa,KAAK,KAAK,CAAC,CAAC;AAChF,YAAA,IAAI,EAAE;AACY;KACrB;AACH;;ACnJA;;AAEG;;ACFH;;AAEG;;;;"}
1
+ {"version":3,"file":"ngx-web-serial.mjs","sources":["../../../projects/ngx-web-serial/src/lib/mock-serial.ts","../../../projects/ngx-web-serial/src/lib/ngx-web-serial.service.ts","../../../projects/ngx-web-serial/src/public-api.ts","../../../projects/ngx-web-serial/src/ngx-web-serial.ts"],"sourcesContent":["export class MockSerial {\n private readableController: ReadableStreamDefaultController<Uint8Array> | null = null;\n readonly responseFunction: (input: string) => string;\n readonly readableStream: ReadableStream<Uint8Array>;\n constructor(responseFunction: (input: string) => string) {\n this.responseFunction = responseFunction;\n this.readableStream = new ReadableStream({\n start: (controller) => {\n this.readableController = controller;\n },\n cancel: () => {\n this.readableController = null;\n }\n });\n }\n\n requestPort(options?: SerialPortRequestOptions): Promise<SerialPort> {\n return Promise.resolve({\n open: () => Promise.resolve(),\n close: () => this.readableStream.cancel(),\n readable: this.readableStream,\n writable: new WritableStream({\n write: (chunk) => {\n const input = new TextDecoder().decode(chunk);\n const response = this.responseFunction(input);\n if (this.readableController) {\n this.readableController.enqueue(new TextEncoder().encode(response));\n }\n }\n })\n } as any as SerialPort);\n }\n}\n","import { FactoryProvider, Inject, Injectable, NgZone, Provider } from '@angular/core';\nimport {\n BehaviorSubject,\n catchError,\n filter,\n firstValueFrom,\n from,\n interval,\n map,\n Observable,\n Subject,\n Subscriber,\n takeUntil,\n throwError,\n timer\n} from 'rxjs';\nimport { DOCUMENT } from '@angular/common';\nimport { MockSerial } from './mock-serial';\n\n@Injectable()\nexport class NgxWebSerial {\n\n private port: SerialPort | null = null;\n private abortController: AbortController | null = null;\n private dataStream: WritableStream | null = null;\n private dataSubject: Subject<string> = new Subject<string>();\n private writer: WritableStreamDefaultWriter<Uint8Array> | null = null;\n private connectedSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);\n\n private readonly sink: UnderlyingSink = {\n write: (chunk: any) => {\n this.ngZone.run(() => {\n this.dataSubject.next(chunk);\n });\n }\n }\n\n constructor(\n @Inject('Serial') readonly serial: Serial | undefined,\n private ngZone: NgZone\n ) {\n }\n\n /**\n * Establishes a connection to a serial port using the Web Serial API.\n */\n open(serialOptions: SerialOptions = { baudRate: 9600 }, options?: SerialPortRequestOptions): Observable<void> {\n return new Observable<void>((observer: Subscriber<void>) => {\n if (!this.serial) {\n observer.error('Web serial not supported.');\n return;\n }\n this.serial.requestPort(options)\n .then((port: SerialPort) => {\n this.port = port;\n return this.port.open(serialOptions);\n })\n .then(() => {\n if (!this.port?.readable || !this.port?.writable) {\n observer.error('Port is not readable or writable.');\n return;\n }\n this.connectedSubject.next(true);\n this.abortController = new AbortController();\n this.dataStream = new WritableStream(this.sink);\n this.writer = this.port?.writable.getWriter();\n observer.next();\n return this.port.readable\n .pipeThrough(new TextDecoderStream())\n .pipeTo(this.dataStream, {signal: this.abortController.signal})\n .catch(() => this.closePort().catch((err) => observer.error(err)));\n })\n .catch((err) => observer.error(err))\n .finally(() => observer.complete());\n });\n }\n\n isConnected(): Observable<boolean> {\n return this.connectedSubject.asObservable();\n }\n\n read(): Observable<string> {\n return this.dataSubject.asObservable();\n }\n\n write(data: string): Observable<void> {\n if (this.writer) {\n return from(this.writer.write(new TextEncoder().encode(data)));\n\n }\n return throwError(() => new Error('No writer available.'));\n }\n\n\n private waitForReadableUnlock(period: number = 50, timeout: number = 5000): Promise<void> {\n return firstValueFrom(interval(period).pipe(\n filter(() => !this.port?.readable?.locked),\n map(() => undefined),\n takeUntil(timer(timeout)),\n catchError(() => throwError(() => new Error('Timeout waiting for readable stream to unlock')))\n ));\n }\n\n private closePort(): Promise<void> {\n this.abortController = null;\n if (this.writer) {\n this.writer.releaseLock();\n this.writer = null;\n }\n if (this.port) {\n return this.waitForReadableUnlock()\n .then(() => this.port!.close())\n .then(() => {\n this.port = null;\n this.connectedSubject.next(false);\n });\n } else {\n return Promise.resolve();\n }\n }\n close(): void {\n if (this.abortController) {\n this.abortController.abort();\n }\n }\n}\n\nexport function provideNgxWebSerial(): Provider[] {\n return [\n NgxWebSerial,\n {\n provide: 'Serial',\n useFactory: (document: Document) => document.defaultView?.navigator?.serial,\n deps: [DOCUMENT]\n }\n ];\n}\n\nexport function provideNgxWebSerialTest(responseFunction?: (input: string) => string): Provider[] {\n return [\n NgxWebSerial,\n {\n provide: 'Serial',\n useFactory: () => new MockSerial(responseFunction || ((input: string) => input)),\n deps: []\n } as FactoryProvider\n ];\n}\n","/*\n * Public API Surface of ngx-web-serial\n */\n\nexport * from './lib/ngx-web-serial.service';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;MAAa,UAAU,CAAA;AAIrB,IAAA,WAAA,CAAY,gBAA2C,EAAA;QAH/C,IAAkB,CAAA,kBAAA,GAAuD,IAAI;AAInF,QAAA,IAAI,CAAC,gBAAgB,GAAG,gBAAgB;AACxC,QAAA,IAAI,CAAC,cAAc,GAAG,IAAI,cAAc,CAAC;AACvC,YAAA,KAAK,EAAE,CAAC,UAAU,KAAI;AACpB,gBAAA,IAAI,CAAC,kBAAkB,GAAG,UAAU;aACrC;YACD,MAAM,EAAE,MAAK;AACX,gBAAA,IAAI,CAAC,kBAAkB,GAAG,IAAI;;AAEjC,SAAA,CAAC;;AAGJ,IAAA,WAAW,CAAC,OAAkC,EAAA;QAC5C,OAAO,OAAO,CAAC,OAAO,CAAC;AACrB,YAAA,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,EAAE;YAC7B,KAAK,EAAE,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE;YACzC,QAAQ,EAAE,IAAI,CAAC,cAAc;YAC7B,QAAQ,EAAE,IAAI,cAAc,CAAC;AAC3B,gBAAA,KAAK,EAAE,CAAC,KAAK,KAAI;oBACf,MAAM,KAAK,GAAG,IA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AC;AACnC,aAAC,CAAC;;aACC;AACL,YAAA,OAAO,OAAO,CAAC,OAAO,EAAE;;;IAG5B,KAAK,GAAA;AACH,QAAA,IAAI,IAAI,CAAC,eAAe,EAAE;AACxB,YAAA,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE;;;AAtGrB,IAAA,SAAA,IAAA,CAAA,IAAA,GAAA,EAAA,CAAA,kBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,YAAY,kBAkBb,QAAQ,EAAA,EAAA,EAAA,KAAA,EAAA,EAAA,CAAA,MAAA,EAAA,CAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA;mHAlBP,YAAY,EAAA,CAAA,CAAA;;4FAAZ,YAAY,EAAA,UAAA,EAAA,CAAA;kBADxB;;0BAmBI,MAAM;2BAAC,QAAQ;;SAyFJ,mBAAmB,GAAA;IACjC,OAAO;QACL,YAAY;AACZ,QAAA;AACE,YAAA,OAAO,EAAE,QAAQ;AACjB,YAAA,UAAU,EAAE,CAAC,QAAkB,KAAK,QAAQ,CAAC,WAAW,EAAE,SAAS,EAAE,MAAM;YAC3E,IAAI,EAAE,CAAC,QAAQ;AAChB;KACF;AACH;AAEM,SAAU,uBAAuB,CAAC,gBAA4C,EAAA;IAClF,OAAO;QACL,YAAY;AACZ,QAAA;AACE,YAAA,OAAO,EAAE,QAAQ;AACjB,YAAA,UAAU,EAAE,MAAM,IAAI,UAAU,CAAC,gBAAgB,KAAK,CAAC,KAAa,KAAK,KAAK,CAAC,CAAC;AAChF,YAAA,IAAI,EAAE;AACY;KACrB;AACH;;ACnJA;;AAEG;;ACFH;;AAEG;;;;"}
@@ -2,7 +2,7 @@
2
2
  import { NgZone, Provider } from '@angular/core';
3
3
  import { Observable } from 'rxjs';
4
4
  import * as i0 from "@angular/core";
5
- export declare class NgxWebSerialService {
5
+ export declare class NgxWebSerial {
6
6
  readonly serial: Serial | undefined;
7
7
  private ngZone;
8
8
  private port;
@@ -23,8 +23,8 @@ export declare class NgxWebSerialService {
23
23
  private waitForReadableUnlock;
24
24
  private closePort;
25
25
  close(): void;
26
- static ɵfac: i0.ɵɵFactoryDeclaration<NgxWebSerialService, never>;
27
- static ɵprov: i0.ɵɵInjectableDeclaration<NgxWebSerialService>;
26
+ static ɵfac: i0.ɵɵFactoryDeclaration<NgxWebSerial, never>;
27
+ static ɵprov: i0.ɵɵInjectableDeclaration<NgxWebSerial>;
28
28
  }
29
- export declare function provideAngularSerial(): Provider[];
30
- export declare function provideAngularSerialTest(responseFunction?: (input: string) => string): Provider[];
29
+ export declare function provideNgxWebSerial(): Provider[];
30
+ export declare function provideNgxWebSerialTest(responseFunction?: (input: string) => string): Provider[];
package/package.json CHANGED
@@ -1,6 +1,23 @@
1
1
  {
2
2
  "name": "ngx-web-serial",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
+ "description": "Angular library for Web Serial API with RxJS",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/mattfors/ngx-web-serial"
8
+ },
9
+ "author": "Matthew Fors",
10
+ "license": "MIT",
11
+ "publishConfig": {
12
+ "registry": "https://registry.npmjs.org"
13
+ },
14
+ "keywords": [
15
+ "serial",
16
+ "rs232",
17
+ "angular",
18
+ "arduino",
19
+ "RxJS"
20
+ ],
4
21
  "peerDependencies": {
5
22
  "@angular/common": "^17.3.0",
6
23
  "@angular/core": "^17.3.0"