-
Bug
-
Resolution: Done
-
Major
-
None
-
None
-
False
-
None
-
False
-
---
-
-
- includes refactoring of the server part so that we can reuse as much as possible
We introduce 2 new concepts for the client part:
- client endpoints; using the same programming model as server endpoints, except that annotated with `@WebSocketConnection` and built around the `WebSocketClientConnection` (unlike `@WebSocket` and `WebSocketConnection` on the server)
- WebSocket connector API - this API is used to configure and create new connections
```java
@WebSocket(path = "/end/
public class ServerEndpoint {
@OnTextMessage
String echo(String message, WebSocketConnection connection, @PathParam String name) { // do something with connection and name return message; }
}
@WebSocketClient(path = "/end/{name}
")
public class ClientEndpoint {
@OnTextMessage
String echo(String message, WebSocketClientConnection connection, @PathParam String name)
}
```
The `WebSocketConnector` can be injected in any bean:
```java
@Singleton
public class Service {
@Inject
WebSocketConnector<ClientEndpoint> connector;
void connectToClientEndpoint()
{ connector. .baseUri(uri) // base URI is configurable per endpoint .pathParam("name", "Lu") .addHeader("X-Test", "foo") .connectAndAwait(); }}
```
-
- TODO
- [x] add more tests
- [x] fail the build if `@OnTextMessage.broadcast()=true`/ `@OnBinaryMessage.broadcast()=true` on a client endpoint
- [x] Dev UI update (just make sure the server part works fine)
~-`@WebSocketClient#autoConnect()` - connect the client automatically when the app starts~ removed from the list, not a high priority, maybe later...
NOTE: We decided to include the client part in the same extension as the server part. Therefore, we will get rid of `extensions/websockets-next/server` in a follow-up PR; i.e. the deployment module will be moved from `extensions/websockets-next/server/deployment` to `extensions/websockets-next/deployment` and the runtime module will be moved from `extensions/websockets-next/server/runtime` to `extensions/websockets-next/runtime`.