menu
announcement

Spectrum is now read-only. Learn more about the decision in our official announcement.

Theia

Eclipse Theia - Cloud & Desktop IDE

Channels
Team

How to use Emitter to emit events from backend to frontend

July 3, 2019 at 9:31am

How to use Emitter to emit events from backend to frontend

July 3, 2019 at 9:31am
I would like to send notifications from backend to frontend. How do i use the Emitter class from /core to emit events/notifications from backend to frontend. Can i have any sample implementation?

July 3, 2019 at 2:47pm
No, you will need to provide a JSON-RPC client to notify it by a server.
on the frontend though you can implement such client using events

July 4, 2019 at 12:23pm
Thank you. will check that.

July 30, 2019 at 9:43am
I have tried with filesystem watcher using JSON RPC. It seems to be complicated. Could not understand the flow mechanism how it is being used in frontend and backend.
Could you elaborate which part is not clear?
like-fill
1
  • define server and client interrfaces
  • implement server on backend, in order to notify a client call a corresponing method
  • implement client on frontend which converts calls into events
  • bind server implementation in the backend module, and client implementation in the frontend module
I don't have time right now to prepare an example. If you do a sample extension, i can review it and help fixing it.
Edited

July 31, 2019 at 9:56am
Thank you very much. Shall update you with my code implementation soon.

August 1, 2019 at 11:53am
Hi here is the sample code implementation, https://github.com/manjup18/sample-event-extension
I have used JsonRPC to communicate from frontend to backend by passing the client interface to backend method. I am able to receive the client object from backend, however in the backend using the client object could not access the client method.
We have mentioned few comments to make you understand the implementation we are trying to achieve. Let me know if you need any clarifications. Thank you.
setClient is never called on the server on the backend, it should be:
bind(ConnectionHandler).toDynamicValue(ctx =>
new JsonRpcConnectionHandler<TestClient>(testPath, client => {
const server = ctx.container.get<TestServer>(TestServer);
server.setClient(client);
return server;
})
).inSingletonScope();
Edited
like-fill
1
also if you want to have a new server per a connection then you should not put in singleton scope, but in transient
and dispose a server when a client is gone
Edited
i.e. client.onDidCloseConnection(() => server.dispose());
like-fill
1

August 7, 2019 at 5:27am
Thank you very much. It worked.