Namespace 연결
const opt = {
auth: {
token: `Bearer ${accessToken}`,
},
};
const helloSocket = io(`${url}:${port}/socket/commu-${communiyId}`, opt);
커뮤니티 별 채널 정보 전달
helloSocket.emit('join', { channels: ['a', 'b', 'c'] });
새로운 메세지 전달
저장
POST http://{{ip}}:{{api_port}}/api/channels/:channel_id/chat
수정
PATCH http://{{ip}}:{{api_port}}/api/channels/:channel_id/chats/:chat_id
삭제
DELETE http://{{ip}}:{{api_port}}/api/channels/:channel_id/chats/:chat_id
// sender
helloSocket.emit(
'chat',
{
chatType: 'new'
channelId: string,
content: string,
} as data,
callback,
);
api body = {
type: 'TEXT',
content: data.message,
}
const apiResult = {
"id": 51,
"type": "TEXT",
"content": "hi",
"senderId": "6394cc8fd1a615bf564d7e75",
"createdAt": "2022-12-11T16:13:24.957Z",
"updatedAt": "2022-12-11T16:13:24.957Z",
"channelId": "6394cd01d1a615bf564d9e4c",
"communityId" : "",
}
reponse: { written: true; chatInfo : apiResult } | { written: false }
helloSocket.on('new-chat', apiResult );
수정된 메세지 전달
소켓전달하는건 chatId
실제로 api에서 저장하는건 chat.id → chatId
// sender (작성자만 수정 가능)
helloSocket.emit(
'chat',
{
chatType: 'modify',
channelId: string,
chatId: number, // 이거 number아닌가요?
content: string,
} as data,
callback,
);
const apiResult = {
"id": 51,
"type": "TEXT",
"content": "hi",
"senderId": "6394cc8fd1a615bf564d7e75",
"createdAt": Date(),
"updatedAt": Date(),
"channelId": "6394cd01d1a615bf564d9e4c",
"communityId" : "",
}
reponse: { written: true; chatInfo : apiResult } | { written: false }
helloSocket.on('modify-chat', apiResult );
삭제할 메세지 전달
// sender (커뮤니티 매니저, 채널 매니저, 작성자만 지우기 가능)
helloSocket.emit(
'chat',
{
chatType: 'delete',
channelId: string,
chatId: number, // number아닌가?
} as data,
callback,
);
const apiResult = {
"id": 51,
"type": "TEXT",
"content": "hi",
"createdAt": Date(),
"updatedAt": Date(),
"senderId": "6394cc8fd1a615bf564d7e75",
"communityId" : "",
"channelId": "6394cd01d1a615bf564d9e4c",
}
reponse: { written: true; chatInfo : apiResult } | { written: false }
helloSocket.on('delete-chat', apiResult );
채널 초대
// 초대 sender
helloSocket.emit(
'invite-users-to-channel',
{
community_id: string; // 이거 카멜케이스?
channel_id: string; // 이거 카멜케이스?
users: string[];
}
callback,
);
// 초대 receiver
helloSocket.on(
'invited-to-channel',
{
_id: '63946d71d0e70368d5be77fa',
managerId: '63908bdc2258e789af7d73ba',
name: 'dfa',
isPrivate: true,
description: '',
type: 'Channel',
// users: [ '63908bdc2258e789af7d73ba', '63908bcc2258e789af7d73ad' ],
createdAt: '2022-12-10T11:28:49.904Z',
updatedAt: '2022-12-10T11:28:59.207Z',
existUnreadChat: false,
//
communityId : '', // 이거 카멜케이스?
}
);