Skip to content

Commit

Permalink
refactor: register web service method to accept socket io srv
Browse files Browse the repository at this point in the history
Adds a second parameter after the epxress object. The second parameter
is a SocketIO server object which plugins will be able to use to
register their asynchronous/streaming endpoints which do not use
traditional REST nor necessarily HTTP as the transport (think websocket
or SocketIO)

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
  • Loading branch information
petermetz committed May 24, 2021
1 parent 45a3dbd commit a52f3a9
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ export class ApiServer {
.map(async (plugin: ICactusPlugin) => {
const p = plugin as IPluginWebService;
await p.getOrCreateWebServices();
const webSvcs = await p.registerWebServices(app);
const webSvcs = await p.registerWebServices(app, null as any);
return webSvcs;
});

Expand Down
173 changes: 173 additions & 0 deletions packages/cactus-core-api/package-lock.json

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

3 changes: 2 additions & 1 deletion packages/cactus-core-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
},
"homepage": "https://github.com/hyperledger/cactus#readme",
"devDependencies": {
"@types/express": "4.17.8"
"@types/express": "4.17.8",
"socket.io": "4.0.1"
},
"dependencies": {
"@hyperledger/cactus-common": "0.5.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ import { Optional } from "typescript-optional";
import { Application } from "express";
import { IWebServiceEndpoint } from "./i-web-service-endpoint";
import { ICactusPlugin } from "../i-cactus-plugin";
import type { Server as SocketIoServer } from "socket.io";

export interface IPluginWebService extends ICactusPlugin {
getOrCreateWebServices(): Promise<IWebServiceEndpoint[]>;
registerWebServices(expressApp: Application): Promise<IWebServiceEndpoint[]>;

registerWebServices(
expressApp: Application,
wsApi: SocketIoServer,
): Promise<IWebServiceEndpoint[]>;

getHttpServer(): Optional<Server | SecureServer>;
shutdown(): Promise<void>;
}
Expand Down

0 comments on commit a52f3a9

Please sign in to comment.