Skip to content

Commit

Permalink
Add transfer_started and transfer_terminated events. Update event nam…
Browse files Browse the repository at this point in the history
…es from server. Fix bug on connection data being removed on disconnect event.
  • Loading branch information
stuartcaunt committed Jan 5, 2024
1 parent b8666be commit 28223d5
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 24 deletions.
7 changes: 4 additions & 3 deletions lib/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@illgrenoble/visa-print-client",
"description": "",
"version": "1.0.2",
"version": "1.1.0",
"repository": {
"type": "git",
"url": "git+https://github.com/ILLGrenoble/visa-print-client.git"
Expand Down
1 change: 0 additions & 1 deletion lib/src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ export * from './print-job.model';
export * from './print-event.model';
export * from './print-job-chunk-event.model';
export * from './print-job-available-event.model';
export * from './print-job-handled-event.model';
export * from './error-event.model';
6 changes: 3 additions & 3 deletions lib/src/models/print-event.model.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {ErrorEvent} from "./error-event.model";
import {PrintJobChunkEvent} from "./print-job-chunk-event.model";
import {PrintJobAvailableEvent} from "./print-job-available-event.model";
import {PrintJobHandledEvent} from "./print-job-handled-event.model";

export class PrintEvent {
type: 'CONNECTING' | 'CONNECTED' | 'DISCONNECTED' | 'ERROR' | 'PRINT_JOB_CHUNK_RECEIVED' | 'PRINT_JOB_AVAILABLE' | 'PRINT_JOB_HANDLED' | 'PRINT_ENABLED' | 'PRINT_DISABLED';
type: 'CONNECTING' | 'CONNECTED' | 'DISCONNECTED' | 'ERROR' | 'PRINT_JOB_CHUNK_RECEIVED' | 'PRINT_JOB_TRANSFER_STARTED' | 'PRINT_JOB_TRANSFER_TERMINATED' | 'PRINT_JOB_AVAILABLE' | 'PRINT_JOB_HANDLED' | 'PRINT_ENABLED' | 'PRINT_DISABLED';
connectionId: string;
data?: ErrorEvent | PrintJobChunkEvent | PrintJobAvailableEvent | PrintJobHandledEvent;
jobId?: number;
data?: ErrorEvent | PrintJobChunkEvent | PrintJobAvailableEvent;

constructor(data?: Partial<PrintEvent>) {
Object.assign(this, data);
Expand Down
7 changes: 0 additions & 7 deletions lib/src/models/print-job-handled-event.model.ts

This file was deleted.

18 changes: 12 additions & 6 deletions lib/src/services/visa-print.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {Injectable} from "@angular/core";
import {BehaviorSubject, filter, Observable, Subject} from "rxjs";
import {BehaviorSubject, Observable, Subject} from "rxjs";
import {
PrintEvent,
PrintJob,
ErrorEvent,
PrintJobHandledEvent,
PrintJobChunkEvent,
PrintJobAvailableEvent
} from "../models";
Expand Down Expand Up @@ -82,15 +81,14 @@ export type Connection = {

socket.on('print_job_handled', (jobId: number) => {
connection.printables = connection.printables.filter(printable => printable.jobId !== jobId);
printEvents$.next(new PrintEvent({type: 'PRINT_JOB_HANDLED', connectionId, data: new PrintJobHandledEvent({jobId})}));
printEvents$.next(new PrintEvent({type: 'PRINT_JOB_HANDLED', connectionId, jobId}));
});

socket.on('connect_error', (error) => {
printEvents$.next(new PrintEvent({type: 'ERROR', connectionId, data: new ErrorEvent({type: 'CONNECTION_ERROR', message: error.message})}));
});

socket.on('disconnect', () => {
this._connections = this._connections.filter(connection => connection.id !== connectionId);
printEvents$.next(new PrintEvent({type: 'DISCONNECTED', connectionId}));
});

Expand All @@ -102,7 +100,15 @@ export type Connection = {
printEvents$.next(new PrintEvent({type: 'ERROR', connectionId, data: new ErrorEvent({type: 'EXCEPTION', message: e.message})}));
});

socket.on('print', (printJob: PrintJob, ack) => {
socket.on('print_job_start', (jobId: number) => {
printEvents$.next(new PrintEvent({type: 'PRINT_JOB_TRANSFER_STARTED', connectionId, jobId}));
});

socket.on('print_job_end', (jobId: number) => {
printEvents$.next(new PrintEvent({type: 'PRINT_JOB_TRANSFER_TERMINATED', connectionId, jobId}));
});

socket.on('print_job_data', (printJob: PrintJob, ack) => {
const {jobId, chunkId, chunkCount, chunkLength, data} = printJob;
if (chunkLength !== data.length) {
console.error(`printer job data of chunk ${chunkId}/${chunkCount} for job ${jobId} ${printJob.fileName} has incorrect length`)
Expand All @@ -112,7 +118,7 @@ export type Connection = {
}

ack(true);
printEvents$.next(new PrintEvent({type: 'PRINT_JOB_CHUNK_RECEIVED', connectionId, data: new PrintJobChunkEvent({jobId, chunkId, chunkCount, chunkLength})}));
printEvents$.next(new PrintEvent({type: 'PRINT_JOB_CHUNK_RECEIVED', connectionId, jobId, data: new PrintJobChunkEvent({jobId, chunkId, chunkCount, chunkLength})}));
this.handlePrintJob(connection, printJob);
});

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@illgrenoble/visa-print-client",
"description": "Receives print requests from a VISA instance via the VISA Print Server using a websocket",
"version": "1.0.2",
"version": "1.1.0",
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.conf.json",
Expand Down

0 comments on commit 28223d5

Please sign in to comment.