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

RxAVRealtime #5

Open
wujun4code opened this issue May 28, 2017 · 0 comments
Open

RxAVRealtime #5

wujun4code opened this issue May 28, 2017 · 0 comments
Labels

Comments

@wujun4code
Copy link
Member

wujun4code commented May 28, 2017

RxAVRealtime

聊天模块的基础类,它负责提供创建对话,发送消息,接收消息等接口

RxAVRealtime.sharedInstance

建议全局使用默认提供的单例模式

登录到聊天服务器

RxAVRealtime.sharedInstance.connect(clientId: "junwu").subscribe(onNext: { success in
            print(success)// true 则表示连接聊天服务器成功
        })

创建对话

try! RxAVRealtime.sharedInstance.connect(clientId: "junwu").flatMap { (connected) -> Observable<IAVIMConversation> in
    let conversation = AVIMConversation(members: ["hey"], creator: "junwu")
    return try RxAVRealtime.sharedInstance.create(options: AVIMConversationCreateOptions(conversation: conversation))
}.subscribe(onNext: { conversation in
    print(conversation.conversationId)
})

发送消息

try! RxAVRealtime.sharedInstance.connect(clientId: "junwu").flatMap { (connected) -> Observable<IAVIMConversation> in
    let conversation = AVIMConversation(members: ["hey"], creator: "junwu")
    return try RxAVRealtime.sharedInstance.create(options: AVIMConversationCreateOptions(conversation: conversation))
}.flatMap({ (conversation) -> Observable<IAVIMMessage> in
    return try RxAVRealtime.sharedInstance.send(conversationId: conversation.conversationId, jsonData: ["type": "text", "text": "hello world"])
}).subscribe(onNext: { message in
    print(message.id)
})

接收消息

try! RxAVRealtime.sharedInstance.connect(clientId: "junwu").flatMap { (connected) -> Observable<IAVIMMessage> in
    return RxAVRealtime.sharedInstance.onMessage
}.subscribe(onNext: { message in
    print(message.id, message.raw)
})
@wujun4code wujun4code added the doc label May 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant