-1

I am working on an IOS application(SWIFT) in which i have used tokbox sdk for adding video chat into ios app. now i want to add text chat option during video call!

Can anyone guide how to add text chat option during video call in iOS app using tokbox sdk?

1 Answers1

1

You can use signal for chat and sending data between clients connected to an OpenTok session.

Here is the reference like : https://tokbox.com/developer/guides/signaling/ios-swift/

In doc have full information. Here is the sample code.

import OpenTok

enum TokBoxSignalType: String {
    case message = "message"
}

class ViewController: UIViewController {
    
    private var openTokSession: OTSession?
    
    @IBAction func onSendMessage(_ sender: UIButton) {
        //send message to OTSignal
        var error: OTError?
        defer {
            self.handleOTError(error)
        }
        openTokSession?.signal(withType: TokBoxSignalType.message.rawValue, string: "send_chat_message", connection: nil, error: &error)
    }
    
    
    //Handle OpenTok errors
    private func handleOTError(_ error: OTError?) {
        if let error = error {
            print("There is an error : ", error.localizedDescription)
        }
    }
    
}


//MARK : Signal Methods
extension ViewController {
    func session(_ session: OTSession, receivedSignalType type: String?, from connection: OTConnection?, with string: String?) {
        guard let typeEnum = TokBoxSignalType(rawValue: type ?? "") else {
            return
        }
        
        switch typeEnum {
        case .message:
            print(string)
        }
    }
}
Raja Kishan
  • 16,767
  • 2
  • 26
  • 52
  • thanks for sharing the reference link! Is there any sample project (ios swift) github that uses signal for text chat during video call ? – Moulali Pinjari Jun 23 '21 at 09:13
  • Yes, I checked before but now I can't find the link. – Raja Kishan Jun 23 '21 at 09:14
  • 1
    We have an example project but it is in objc. But works just the same https://github.com/opentok/opentok-ios-sdk-samples/tree/main/Signaling – abdulajet Jun 23 '21 at 09:29
  • 1
    @MoulaliPinjari here I attached the sample code demo. – Raja Kishan Jun 23 '21 at 09:37
  • @abdulajet, im trying to implement text chat during video call.i have some doubts regarding implementation of text chat. should i build my own user interface for text chat ? can u share if u have any working sample of implementing text chat in ios app (swift) – Moulali Pinjari Jun 28 '21 at 05:13
  • My above comment has a sample in objc, but the API and principals are the same in swift. You can also build your own chat UI if you prefer, it is just a sample – abdulajet Jun 28 '21 at 09:50
  • @abdulajet, i found a text chat sample in swift https://github.com/sbuxar/TokBox-Text-Chat-in-swift but it is not working, can u have a look at it once. – Moulali Pinjari Jun 29 '21 at 08:24