- Mono<ChatRoomInfoTo> createChatRoom(String name)
- {
- return webClient
- .post()
- .uri("/create")
- .contentType(MediaType.TEXT_PLAIN)
- .bodyValue(name)
- .accept(MediaType.APPLICATION_JSON)
- .exchangeToMono(response ->
- {
- if (response.statusCode().equals(HttpStatus.OK))
- {
- return response.bodyToMono(ChatRoomInfoTo.class);
- }
- else
- {
- return response.createError();
- }
- });
- }
-
- Mono<MessageTo> sendMessage(
- ChatRoomInfoTo chatRoom,
- User user,
- String message)
- {
- return webClient
- .put()
- .uri(
- "/{chatRoomId}/{username}/{serial}",
- chatRoom.getId(),
- user.getName(),
- user.nextSerial())
- .contentType(MediaType.TEXT_PLAIN)
- .accept(MediaType.APPLICATION_JSON)
- .bodyValue(message)
- .exchangeToMono(response ->
- {
- if (response.statusCode().equals(HttpStatus.OK))
- {
- return response.bodyToMono(MessageTo.class);
- }
- else
- {
- return response.createError();
- }
- });
- }
-
- Flux<ServerSentEvent<String>> receiveMessages(ChatRoomInfoTo chatRoom)
- {
- return webClient
- .get()
- .uri(
- "/{chatRoomId}/listen",
- chatRoom.getId())
- .accept(MediaType.TEXT_EVENT_STREAM)
- .retrieve()
- .bodyToFlux(SSE_TYPE);
- }
-
-
- WebClient webClient;
-