본문으로 건너뛰기

시작하기

HOST : api.maxverse.io/chat
  • PASSPORT에서 토큰발급

채팅 메시지 받기

웹소켓(STOMP) 연결하고, subscribe 요청을 통해 메시지를 받을 수 있다. token 인증은 현재 반영 안됨. 코드 반영 후 관련 정보 업데이트 예정

1. 웹소켓(STOMP) 연결

https://api.maxverse.io/chat/ws

2. Subscribe 요청

/sub/chat/rooms/{room_uuid}

예제코드 (SockJS / Stomp / java script)

var stompClient = null;

function connect() {
const socket = new SockJS("https://api.maxverse.io/chat/ws");
stompClient = Stomp.over(socket);

// STOMP 연결에 필요한 헤더 정보를 지정합니다.
const headers = {
Authorization: `Bearer ${token}`,
};

stompClient.connect(headers, function (frame) {
subscribeRoom("${room_uuid}", handlingReceivedMessage);
});
}

function subscribeRoom(room_uuid, callback) {
if (stompClient != null) {
stompClient.subscribe(`/sub/chat/rooms/${room_uuid}`, callback);
}
}

function handlingReceivedMessage(message) {
console.log(JSON.parse(message.body));
}

채팅 메시지 보내기

POST https://api.maxverse.io/chat/v1/chat-room/{room_uuid}/pub

Request Parameters

NameDescriptionRemarkRequired
room_uuid채팅방 UUID36자리 uuidO

Request body

NameDescriptionRemarkRequired
user_id발신자의 고유 아이디O
message메시지 내용O
chat_data_typeTEXT, FILEO

Request

POST /chat/v1/chat-room/{room_uuid}/pub   HTTP/1.1
Content-Type: application/json
Authorization: Bearer {token}
Host: api.maxverse.io

{
"user_id": "choon-sick",
"message": "안녕하세요!",
"chat_data_type": "TEXT"
}

Response[Success]

HTTP/1.1 200 OK
content-type: application/json

{"status":"success"}

Response[Failure]

HTTP/1.1 403 Forbidden
content-type: application/json

{
"status": "error",
"error": {
"message": "This userID is not part of the chatroom"
}
}