PantelisGeorgiadis / dcmjs-dimse

DICOM DIMSE implementation for Node.js using the dcmjs library
MIT License
74 stars 14 forks source link

Feature request: Emitting event on server listening #55

Closed jimOnAir closed 1 year ago

jimOnAir commented 1 year ago

Hello. I've faced the problem that I can't handle exceptions on the SCP server start properly cause it lacks a listening event. If I start the server with promise, it either never resolves or doesn't handle network error. So I've created a subclass of Server with an overriding listen method.

private async listen(pacsOptions: IPacsOptions) {
    return new Promise<Server & EventEmitter>((resolve, reject) => {
      const pacsServer = (new DIMSEServer(DimseScp)) as DIMSEServer & EventEmitter;

      pacsServer.on('networkError', (error: Error) => {
        reject(error);
      });

      pacsServer.listen(pacsOptions.port, {
        ...pacsOptions.scp,
        datasetWriteOptions: { fragmentMultiframe: false },
        logCommandDatasets: false,
        logDatasets: false,
        logger: new LogService(this.pathService, DimseScp.name),
      });

    resolve(pacsServer); // Resolve before 'networkError' emitted
    });
  }

It would be helpful if Server emits some event once it is ready (propogate net.Server and tls.Server 'listening' event).

PantelisGeorgiadis commented 1 year ago

Thank you @jimOnAir for reporting this! Version 0.1.23 now propagates the net.Server and tls.Server listening event.

PantelisGeorgiadis commented 1 year ago

Hello @jimOnAir! Did you have the chance to test this?

jimOnAir commented 1 year ago

Hello @PantelisGeorgiadis . Yes, it works like a charm, thank you

PantelisGeorgiadis commented 1 year ago

Great to hear that!