- Android
- iOS
- JavaScript
聊天室消息通过统一的 消息监听 返回。 聊天室加入退出监听,可以设置多个。
JIM.getInstance().getChatroomManager().addListener("main", this);
@Override
public void onChatroomJoin(String chatroomId) {
Log.i("TAG", "onChatroomJoin, chatroomId is " + chatroomId);
}
@Override
public void onChatroomQuit(String chatroomId) {
Log.i("TAG", "onChatroomQuit, chatroomId is " + chatroomId);
}
@Override
public void onChatroomJoinFail(String chatroomId, int errorCode) {
Log.i("TAG", "onChatroomJoinFail, chatroomId is " + chatroomId + ", errorCode is " + errorCode);
}
@Override
public void onChatroomQuitFail(String chatroomId, int errorCode) {
Log.i("TAG", "onChatroomQuitFail, chatroomId is " + chatroomId + ", errorCode is " + errorCode);
}
@Override
public void onChatroomKick(String chatroomId) {
Log.i("TAG", "onChatroomKick, chatroomId is " + chatroomId);
}
@Override
public void onChatroomDestroy(String chatroomId) {
Log.i("TAG", "onChatroomDestroy, chatroomId is " + chatroomId);
}
聊天室属性变更监听,可以设置多个。
JIM.getInstance().getChatroomManager().addAttributesListener("main", this);
@Override
public void onAttributesUpdate(String chatroomId, Map<String, String> attributes) {
Log.i("TAG", "onAttributesUpdate, chatroomId is " + chatroomId + ", count is " + attributes);
}
@Override
public void onAttributesDelete(String chatroomId, Map<String, String> attributes) {
Log.i("TAG", "onAttributesDelete, chatroomId is " + chatroomId + ", count is " + attributes);
}
聊天室消息通过统一的 消息监听 返回。 聊天室加入退出监听,可以设置多个。
[JIM.shared.chatroomManager addDelegate:self];
- (void)chatroomDidJoin:(NSString *)chatroomId {
NSLog(@"chatroomDidJoin, chatroomId is %@", chatroomId);
}
- (void)chatroomDidQuit:(NSString *)chatroomId {
NSLog(@"chatroomDidQuit, chatroomId is %@", chatroomId);
}
- (void)chatroomJoinFail:(NSString *)chatroomId errorCode:(JErrorCode)errorCode {
NSLog(@"chatroomJoinFail, chatroomId is %@, errorCode is %ld", chatroomId, errorCode);
}
- (void)chatroomQuitFail:(NSString *)chatroomId errorCode:(JErrorCode)errorCode {
NSLog(@"chatroomQuitFail, chatroomId is %@, errorCode is %ld", chatroomId, errorCode);
}
- (void)chatroomDidDestroy:(NSString *)chatroomId {
NSLog(@"chatroomDidDestroy, chatroomId is %@", chatroomId);
}
- (void)chatroomDidKick:(NSString *)chatroomId {
NSLog(@"chatroomDidKick, chatroomId is %@", chatroomId);
}
聊天室属性变更监听,可以设置多个。
[JIM.shared.chatroomManager addAttributesDelegate:self];
- (void)attributesDidDelete:(NSDictionary<NSString *,NSString *> *)attributes forChatroom:(NSString *)chatroomId {
NSLog(@"attributesDidDelete, count is %ld, chatroom is %@", attributes.count, chatroomId);
}
- (void)attributesDidUpdate:(NSDictionary<NSString *,NSString *> *)attributes forChatroom:(NSString *)chatroomId {
NSLog(@"attributesDidUpdate, count is %ld, chatroom is %@", attributes.count, chatroomId);
}
聊天室监听包含 属性变更
和 成员变更
两大类监听,聊天室消息会通过统一 消息监听 返回
// 当前用户重新加入事件,断网恢复后 SDK 会自动重新加入聊天室
jim.on(Event.CHATROOM_USER_REJOINED, (user) => {
// user => { id: '10002', name: 'xiaokele' }
});
// 当前用户加入房间
jim.on(Event.CHATROOM_USER_JOINED, (user) => {
// user => { id: '10002', name: 'xiaokele' }
});
// 当前用户退出房间
jim.on(Event.CHATROOM_USER_QUIT, (user) => {
// user => { id: '10002', name: 'xiaokele' }
});
// 聊天室成员加入事件
jim.on(Event.CHATROOM_MEMBER_JOINED, (member) => {
// member => { id: '10001', name: 'xiaoshan' }
});
// 聊天室成员退出事件
jim.on(Event.CHATROOM_MEMBER_QUIT, (member) => {
// member => { id: '10001', name: 'xiaoshan' }
});
// 聊天室销毁事件,通过 Server API 可销毁聊天室
jim.on(Event.CHATROOM_DESTROYED, (chatroom) => {
// chatroom => { id: 'chatroom1001' }
});
// 聊天室属性删除通知
jim.on(Event.CHATROOM_ATTRIBUTE_DELETED, (chatroom) => {
console.log('chatroom attributes deleted', chatroom);
/*
chatroom =>
{
id: 'chatroom1001',
attributes:[{ key: 'name' }]
}
*/
});
// 聊天室属性更新通知
jim.on(Event.CHATROOM_ATTRIBUTE_UPDATED, (chatroom) => {
console.log('chatroom attributes updated', chatroom);
/*
chatroom =>
{
id: 'chatroom1001',
attributes:[{ key: 'name', value: 'xiaoshan', userId: '更新 Key 的用户 Id' }]
}
*/
});