Socket Connection
In order to connect the user and the doctor
there should be a channel that reflects the status update of the consultation,
So we have the Socket
.
Socket
For initiating the socket, there is a needed data, It is already included in the consultation data
import com.altibbi.telehealth.TBISocket
import com.altibbi.telehealth.TBISocketEventListener
import com.altibbi.telehealth.TBISubscribeEventListener
val socket = TBISocket();
socket.init(
channelName = response.socketChannel!!,
appKey = response.appKey!!,
connectionCallback = object : TBISocketEventListener {
override fun onConnectionStateChange(
previousState: String?,
currentState: String?
) {
if(currentState == "CONNECTED"){
}
}
override fun onError(
message: String,
code: String?,
e: Exception?
) {
}
},
subscribeCallback = object : TBISubscribeEventListener {
override fun onEvent(event: JSONObject) {
}
override fun onAuthenticationFailure(
message: String?,
e: Exception?
) {
}
override fun onSubscriptionSucceeded(channelName: String) {
}
}
)
Use Socket Service To Listen To Consultation Event Initializing the Socket Service:
socket.subscribe("call-status", object : TBISubscribeEventListener { // call-status its the Event name
override fun onEvent(event: JSONObject) {
val status = event.getString("status")
if (status == "in_progress"){
}else if (status == "closed"){
}
}
override fun onAuthenticationFailure(
message: String?,
e: Exception?
) {
print("onAuthenticationFailure $message")
}
override fun onSubscriptionSucceeded(channelName: String) {
println("onSubscriptionSucceeded 1$channelName")
}
})
Next Step (Move to Consultation)
On listening to the events, the event call-status
reflects the status of the consultation,
So you need to check the consultation data on event listener and call getConsultationInfo
to check the config of the consultation
and once the consultation status is in_progress
and the config is ready you can move to the consultation screen
For Chat
consultation the data will include the chatConfig
object
For Voip
consultations the data will include the voipConfig
object
For Video
consultations the data will include the videoConfig
object
Config Classes
import com.google.gson.annotations.SerializedName
data class ChatConfig(
val id: Int?,
@SerializedName("consultation_id") val consultationId: Int?,
@SerializedName("group_id") val groupId: String?,
@SerializedName("app_id") val appId: String?,
@SerializedName("chat_user_id") val chatUserId: String?,
@SerializedName("chat_user_token") val chatUserToken: String?
) {
companion object {
fun fromJson(json: Map<String, Any?>): ChatConfig {
return ChatConfig(
id = json["id"] as? Int,
consultationId = json["consultation_id"] as? Int,
groupId = json["group_id"] as? String,
appId = json["app_id"] as? String,
chatUserId = json["chat_user_id"] as? String,
chatUserToken = json["chat_user_token"] as? String
)
}
}
}
For Both, voipConfig and videoConfig
import com.google.gson.annotations.SerializedName
data class VoipConfig(
val id: Int?,
@SerializedName("consultation_id") val consultationId: Int?,
@SerializedName("api_key") val apiKey: String?,
@SerializedName("call_id") val callId: String?,
@SerializedName("token") val token: String?,
) {
companion object {
fun fromJson(json: Map<String, Any>): VoipConfig {
return VoipConfig(
json["id"] as? Int,
json["consultation_id"] as? Int,
json["api_key"] as? String,
json["call_id"] as? String,
json["token"] as? String
)
}
}
}