This repository has been archived by the owner on Jun 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add UI server factory with server class abstraction
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
- Loading branch information
Jérôme Benoit
committed
May 13, 2022
1 parent
6627109
commit fe94fce
Showing
7 changed files
with
63 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import AbstractUIService from './ui-services/AbstractUIService'; | ||
import { Server as HttpServer } from 'http'; | ||
import { ProtocolVersion } from '../../types/UIProtocol'; | ||
import { Server as WSServer } from 'ws'; | ||
|
||
export abstract class AbstractUIServer { | ||
public readonly chargingStations: Set<string>; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jerome-benoit
via email
Owner
|
||
protected readonly uiServices: Map<ProtocolVersion, AbstractUIService>; | ||
protected uiServer: WSServer | HttpServer; | ||
|
||
public constructor() { | ||
this.chargingStations = new Set<string>(); | ||
this.uiServices = new Map<ProtocolVersion, AbstractUIService>(); | ||
} | ||
|
||
public abstract start(): void; | ||
public abstract stop(): void; | ||
public abstract sendResponse(message: string): void; | ||
public abstract logPrefix(): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { AbstractUIServer } from './AbstractUIServer'; | ||
import { ApplicationProtocol } from '../../types/UIProtocol'; | ||
import Configuration from '../../utils/Configuration'; | ||
import { ServerOptions } from '../../types/ConfigurationData'; | ||
import UIWebSocketServer from './UIWebSocketServer'; | ||
|
||
export default class UIServerFactory { | ||
private constructor() { | ||
// This is intentional | ||
} | ||
|
||
public static getUIServerImplementation( | ||
applicationProtocol: ApplicationProtocol, | ||
options?: ServerOptions, | ||
callback?: () => void | ||
): AbstractUIServer | null { | ||
switch (applicationProtocol) { | ||
case ApplicationProtocol.WS: | ||
return new UIWebSocketServer(options ?? Configuration.getUIServer().options, callback); | ||
default: | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
why is that in abstractUIServer ? shouldn't this class only be concerned with server in general ? (well i would also question it's presence in UIWebSocketServer, as it should also only be concerned with server although more specific)