@@ -34,7 +34,7 @@ import { ObjLogger, prettyPrint } from "@scramjet/obj-logger";
3434
3535import { CommonLogsPipe } from "./common-logs-pipe" ;
3636import { CPMConnector } from "./cpm-connector" ;
37- import { InstanceStore } from "./instance-store" ;
37+ import { IInstanceStore , InstanceStore } from "./instance-store" ;
3838
3939import { DuplexStream } from "@scramjet/api-server" ;
4040import { ConfigService , development } from "@scramjet/sth-config" ;
@@ -65,6 +65,7 @@ import { loadModule, logger as loadModuleLogger } from "@scramjet/module-loader"
6565import { CSIDispatcher , DispatcherChimeEvent as DispatcherChimeEventData , DispatcherErrorEventData , DispatcherInstanceEndEventData , DispatcherInstanceEstablishedEventData , DispatcherInstanceTerminatedEventData } from "./csi-dispatcher" ;
6666
6767import { parse } from "path" ;
68+ import { RPCService } from "./rpc-service" ;
6869
6970const buildInfo = readJsonFile ( "build.info" , __dirname , ".." ) ;
7071const packageFile = findPackage ( __dirname ) . next ( ) ;
@@ -125,13 +126,18 @@ export class Host implements IComponent {
125126 /**
126127 * Object to store CSIControllers.
127128 */
128- instancesStore = InstanceStore ;
129+ instancesStore : IInstanceStore = InstanceStore ;
129130
130131 /**
131132 * Sequences store.
132133 */
133134 sequenceStore = new SequenceStore ( ) ;
134135
136+ /**
137+ * RPC service.
138+ */
139+ rpcService : RPCService ;
140+
135141 /**
136142 * Instance of class providing logging utilities.
137143 */
@@ -165,6 +171,7 @@ export class Host implements IComponent {
165171 private instanceProxy : HostProxy = {
166172 onInstanceRequest : ( socket : Duplex ) => { this . api . server . emit ( "connection" , socket ) ; } ,
167173 } ;
174+ rpcBase : string ;
168175
169176 public get service ( ) : string {
170177 return name ;
@@ -205,6 +212,8 @@ export class Host implements IComponent {
205212 ObjLogger . levels [ ObjLogger . levels . length - 1 ]
206213 ) ;
207214
215+ this . rpcService = new RPCService ( this . logger , this . instancesStore ) ;
216+
208217 const prettyLog = new DataStream ( ) . map ( prettyPrint ( { colors : this . config . logColors } ) ) ;
209218
210219 this . logger . addOutput ( prettyLog ) ;
@@ -269,6 +278,7 @@ export class Host implements IComponent {
269278
270279 this . apiBase = this . config . host . apiBase ;
271280 this . instanceBase = `${ this . config . host . apiBase } /instance` ;
281+ this . rpcBase = `${ this . config . host . apiBase } /rpc` ;
272282 this . topicsBase = `${ this . config . host . apiBase } /topic` ;
273283
274284 this . csiDispatcher = new CSIDispatcher ( {
@@ -692,6 +702,8 @@ export class Host implements IComponent {
692702 this . api . use ( `${ this . apiBase } /cpm` , ( req , res ) => this . spaceMiddleware ( req , res ) ) ;
693703
694704 this . api . use ( `${ this . instanceBase } /:id` , ( req , res , next ) => this . instanceMiddleware ( req , res , next ) ) ;
705+
706+ this . api . use ( `${ this . rpcBase } /:topic` , ( req , res , next ) => this . rpcService . handleRequest ( req , res , next ) ) ;
695707 }
696708
697709 /**
0 commit comments