새로운 채팅방
새로운 채팅방을 생성하기 위해서는 임의 채팅방에 접속이 되어있어야 가능합니다. 반대로 생성한 채팅방도 삭제가 가능하며 동일한 아이디로 삭제를 해야 동작합니다. 준비에 관한 세부 내용은 준비사항
을 참고하면 되겠습니다.
채팅방 생성
새로운 채팅방을 생성하기 위해서는 VChatCloud
객채를 생성할 때 반드시 serviceId
값을 입력해야 하는데, CMS 계정을 설정해주시면 됩니다. 설정하지 않는 경우 10901:RECIPIENT_FAILURE
오류가 발생합니다.
js
let openRoomId = "유니크한 룸ID";
const vChatCloud = new VChatCloud({ serviceId: "YOUR_CMS_ACCOUNT" });
privateChannel = vChatCloud.openChannel(
{
roomId: openRoomId,
clientKey: channel.clientKey, // 메인으로 접속한 channel
},
function (err, res) {
console.log(res);
}
);
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
푸시 결과 값
값 식별자 설명 err String 오류인 경우 리턴되는 객체 res String 성공인 경우 리턴되는 객체
프로젝트에 적용할 코드
js
privateChannel = vChatCloud.openChannel(
{
roomId: openRoomId,
clientKey: channel.clientKey,
},
function (err, res) {
if (res) {
console.log("성공");
} else if (err) {
console.log("오류", err);
}
}
);
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
채팅방 삭제 이벤트
js
let openRoomId = "생성한 룸ID";
vChatCloud.closeChannel(
{
roomId: openRoomId,
clientKey: channel.clientKey, // 메인으로 접속한 channel
},
function (err, res) {
console.log(res);
}
);
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
푸시 결과 값
값 식별자 설명 err String 오류인 경우 리턴되는 객체 res String 성공인 경우 리턴되는 객체
프로젝트에 적용할 코드
js
vChatCloud.closeChannel(
{
roomId: openRoomId,
clientKey: channel.clientKey,
},
function (err, res) {
if (res) {
console.log("성공");
} else if (err) {
console.log("오류", err);
}
}
);
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13