Now my frontend can subsribe the events emit from the backend, but my question is how can i fire the backend events? Should my backend starts a http server and listens on a port?
You can refer to JsonRpcServer
based file system implementation here:
- packages/filesystem/src/common/filesystem.ts - the interface declarations
- packages/filesystem/src/node/node-filesystem.ts - the file system implementation in the backend
-
setClient(...)
method in FileSystemNode - this method sets the client that needs to receive the notification -
interface FileSystemClient
is the interface the client on the frontend needs to implement. - Frontend client needs to call
setClient
to register itself as a client that receives notifications from backend. - Refer to
FileSystemWatcher
inpackages/filesystem/src/browser/filesystem-watcher.ts
where it calls the following:
this.filesystem.setClient({
/* ... */
});
- The following code in
FileSystemNode
backend is an example of how the notification can be sent to frontend:
this.client.onWillMove(sourceUri, targetUri);
orthis.client.onDidMove(sourceUri, targetUri);
Hope this helps.
2 Likes
OK i try it later, thank you very much.