Socket Connection
In order to connect the user and the doctor, there should be a channel that reflects the status update of the consultation. We provide the TBISocket class to manage the socket connection.
Socket Attributes
For initiating the socket, you need the socketChannel and socketKey from the Consultation object.
Here is the consultation data once the consultation is created:
{
"id": 123,
"pusherChannel": "channel",
"pusherAppKey": "key"
// ... Other Consultation properties
}
TBISocket initiateSocket
Using the initiateSocket method, the connection will be established and subscribed.
You need the following:
appKey: This is thesocketKeyfrom theConsultationobject.channelName: This is thesocketChannelfrom theConsultationobject.onEvent: This is a closure to handle events and data from the socket connection.
Check the code below:
import AltibbiTelehealth
// Get appKey and channelName from the created consultation info
let appKey = consultation.socketKey ?? ""
let channelName = consultation.socketChannel ?? ""
func onEvent(name: String, data: String?) {
if let data = data {
if data == "accepted" {
// This indicates that the doctor accepted the consultation but it's still not started
} else if data == "in_progress" {
// This indicates that the consultation has started
}
}
}
TBISocket.initiateSocket(
appKey: appKey,
channelName: channelName,
onEvent: onEvent
)
Next Step (Move to Consultation)
From the onEvent function, the data returned will be the status that indicates the acceptance and starting of the consultation.
During the socket connection, you can use getConsultationInfo to check if the Consultation Config is ready.
For chat consultation, the data will include the chatConfig object.
For voip consultations, it will include the voipConfig object.
For video consultations, it will include the videoConfig object.
Config Structs
struct ChatConfig {
var id: Int?
var consultationId: Int?
var groupId: String?
var chatUserId: String?
var appId: String?
var chatUserToken: String?
}
// For both voipConfig and videoConfig
struct VoipConfig {
var id: Int?
var consultationId: Int?
var apiKey: String?
var callId: String?
var token: String?
}