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)
}
}
}