Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

채팅방 화면 구현 #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions backend-spring/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 19 additions & 24 deletions backend-spring/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,30 @@ plugins {
kotlin("plugin.spring") version "1.6.10"
}

allprojects {
repositories {
mavenCentral()
}
repositories {
mavenCentral()
}

subprojects {

apply { plugin("org.gradle.application") }
apply { plugin("org.gradle.idea") }
apply { plugin("org.springframework.boot") }
apply { plugin("io.spring.dependency-management") }
apply { plugin("org.jetbrains.kotlin.jvm") }
apply { plugin("org.jetbrains.kotlin.plugin.spring") }
dependencies {
implementation(platform(kotlin("bom")))
implementation(kotlin("stdlib"))
implementation(kotlin("reflect"))
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.springframework.boot:spring-boot-starter-rsocket")
implementation("org.springframework.boot:spring-boot-starter-data-r2dbc")
implementation("org.hibernate.validator:hibernate-validator")
implementation("io.r2dbc:r2dbc-h2")

dependencies {
implementation(platform(kotlin("bom")))
implementation(kotlin("stdlib"))
implementation(kotlin("reflect"))
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
runtimeOnly("com.h2database:h2")

developmentOnly("org.springframework.boot:spring-boot-devtools")
}
developmentOnly("org.springframework.boot:spring-boot-devtools")
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
freeCompilerArgs = freeCompilerArgs + listOf("-Xjsr305=strict", "-Xemit-jvm-type-annotations")
jvmTarget = "11"
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
freeCompilerArgs = freeCompilerArgs + listOf("-Xjsr305=strict", "-Xemit-jvm-type-annotations")
jvmTarget = "11"
}
}

Expand Down
1 change: 0 additions & 1 deletion backend-spring/domain/build.gradle.kts

This file was deleted.

8 changes: 0 additions & 8 deletions backend-spring/rest-api/build.gradle.kts

This file was deleted.

4 changes: 0 additions & 4 deletions backend-spring/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,3 @@
*/

rootProject.name = "backend-spring"

include("rest-api")
include("stomp-broker")
include("domain")
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.jacknie.sample.chat.config

import com.jacknie.sample.chat.handler.ChatCategoryHandler
import com.jacknie.sample.chat.handler.ChatRoomHandler
import com.jacknie.sample.chat.webflux.handler.ChatCategoryHandler
import com.jacknie.sample.chat.webflux.handler.ChatRoomHandler
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.boot.web.codec.CodecCustomizer
import org.springframework.context.annotation.Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.jacknie.sample.chat.rsocket.controller

import org.springframework.messaging.handler.annotation.MessageMapping
import org.springframework.stereotype.Controller

@Controller
class TestController {

@MessageMapping("request-response")
fun echo(request: String): String {
return request
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.jacknie.sample.chat.handler
package com.jacknie.sample.chat.webflux.handler

import com.jacknie.sample.chat.model.ChatCategory
import com.jacknie.sample.chat.model.ChatCategoryFilter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.jacknie.sample.chat.handler
package com.jacknie.sample.chat.webflux.handler

import com.jacknie.sample.chat.model.ChatRoom
import com.jacknie.sample.chat.model.ChatRoomFilter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.jacknie.sample.chat.handler
package com.jacknie.sample.chat.webflux.handler

import javax.validation.constraints.NotBlank
import javax.validation.constraints.Positive
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.jacknie.sample.chat.handler
package com.jacknie.sample.chat.webflux.handler

import javax.validation.constraints.NotBlank
import javax.validation.constraints.NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.jacknie.sample.chat.handler
package com.jacknie.sample.chat.webflux.handler

import org.springframework.data.domain.Page
import org.springframework.data.domain.PageRequest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.jacknie.sample.chat.handler
package com.jacknie.sample.chat.webflux.handler

import org.springframework.http.HttpStatus
import org.springframework.stereotype.Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ spring.r2dbc.password=

spring.sql.init.mode=embedded

spring.rsocket.server.port=9080
spring.rsocket.server.transport=websocket

server.port=8080

logging.level.org.springframework.r2dbc=DEBUG
3 changes: 0 additions & 3 deletions backend-spring/stomp-broker/build.gradle.kts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

48 changes: 47 additions & 1 deletion frontend-react/components/ChatRooms/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { Button, Pagination, Stack } from "@mui/material";
import { useMemo, useState } from "react";
import { useEffect, useMemo, useState } from "react";
import {
Encodable,
IdentitySerializer,
JsonSerializer,
RSocketClient,
} from "rsocket-core";
import RSocketWebsocketClient from "rsocket-websocket-client";
import { PageRequest, SortRequest } from "types";
import ChatRoomList from "./ChatRoomList";
import useChatRooms from "./hooks/chat-rooms";
Expand All @@ -12,6 +19,7 @@ const basePageRequest = {
};

function ChatRooms() {
useTestRSocket();
const [totalCount, setTotalCount] = useState<number>(0);
const pageSize = useMemo(
() =>
Expand Down Expand Up @@ -44,4 +52,42 @@ function ChatRooms() {
);
}

function useTestRSocket() {
const rsocketClient = useMemo(() => createRSocketClient(), []);

useEffect(() => {
rsocketClient.then(client => {
client
.requestResponse({
data: { value: "Hello RSocket!!" },
metadata:
String.fromCharCode("request-response".length) + "request-response",
})
.subscribe({
onComplete: value => console.log(value),
onError: error => console.error(error),
onSubscribe: cancel => {},
});
});
}, [rsocketClient]);
}

function createRSocketClient() {
const transport = new RSocketWebsocketClient({ url: "ws://localhost:9080" });
const client = new RSocketClient<any, Encodable>({
serializers: {
data: JsonSerializer,
metadata: IdentitySerializer,
},
setup: {
keepAlive: 1000000,
lifetime: 100000,
dataMimeType: "application/json",
metadataMimeType: "message/x.rsocket.routing.v0",
},
transport,
});
return client.connect();
}

export default ChatRooms;
4 changes: 4 additions & 0 deletions frontend-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@
"@mui/material": "^5.2.8",
"@stomp/stompjs": "^6.1.2",
"@types/lodash": "^4.14.178",
"@types/rsocket-core": "^0.0.7",
"@types/rsocket-websocket-client": "^0.0.4",
"@types/sockjs-client": "^1.5.1",
"lodash": "^4.17.21",
"next": "12.0.7",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-hook-form": "^7.24.0",
"rsocket-core": "^0.0.27",
"rsocket-websocket-client": "^0.0.27",
"sockjs-client": "^1.5.2",
"swr": "^1.1.2",
"websocket": "^1.0.34"
Expand Down