Skip to content

MQTT Subscriber Setup with Channelize API SDK

rohitphogat19 edited this page Mar 12, 2019 · 3 revisions

In IOS SDKs, we have implemented MQTT as the pub sub protocol that is user for delivering data.

Add or Remove Conversation Data Delegate

To receive certain events happening in the conversations from Channelize server you need to register CHConversationDataDelegate with it's unique ID. You need to implement the following functions/events to keep getting the information related to the conversations.

// ViewController.swift
class ViewController: UIViewController, CHConversationDataDelegate {
    override func viewdidLoad() {
        
        // ...
        Channelize.addConversationDelegate(self, identifier: UNIQUE_DELEGATE_ID)
        
        // ...
    }

    func didGetChatInfo(conversation: CHConversation?) {
    }

    func didReceiveNewMessage(message: CHMessage?){
    }

    func didDeleteChat(conversation: CHConversation?){
    }

    func didClearChat(conversation: CHConversation?){
    }

    func didDeleteMessage(conversation: CHConversation?){
    }

    func didMemberAdded(conversation: CHConversation?){
    }

    func didMemberRemoved(conversation: CHConversation?){
    }

    func didAdminAdded(conversationId:String?, isAdmin:Bool, userId:String?){
    }

    func didMarkAsRead(messageId:String?,conversationId:String?,userId:String?,status:Int?,isMe:Bool){
    }

    func didChangeTypingStatus(conversationId:String?,userId:String?,isTyping:Bool){
    }

    func didMessagesDeleted(messageIds:[String],topic:String){
    }
}

The following code shows how to remove the event data delegate.

Channelize.removeDelegate(forDelegateId: UNIQUE_DELEGATE_ID)

Add or Remove User Event Delegate

To receive certain events happening related to the users from Channelize server you need to register CHUserEventDelegate with it's unique ID. You need to implement the following functions/events to keep getting the information related to the users.

// ViewController.swift
class ViewController: UIViewController, CHUserEventDelegate {
    override func viewdidLoad() {
        
        // ...
        Channelize.addUserDelegate(self, identifier: UNIQUE_DELEGATE_ID)
        
        // ...
    }
    func didUserAdded(user: CHUser?) {
    }

    func didUserRemoved(user: CHUser?) {
    }

    func didChangeUserStatus(user: CHUser?){
    }

    func didUserBlocked(isMe:Bool,userId:String?){
    }

    func didUserUnblocked(isMe:Bool,user: CHUser?){
    }
}

Add or Remove Connection Delegate

To receive certain events related to the server connection you need to register CHConnectionDelegate with it's unique ID. You need to implement the following functions/events to keep getting the information related to the users.

// ViewController.swift
class ViewController: UIViewController, CHConnectionDelegate {
    override func viewdidLoad() {
        
        // ...
        Channelize.addConnectionDelegate(self, identifier: UNIQUE_DELEGATE_ID)
        
        // ...
    }
     
    func didStartReconnection(){
    }
    
    func didServerConnected(){
    }
    
    func didServerDisconnected(){
    }
    
    func didConnectionFailed(){
    }
}
Clone this wiki locally