changed getting web client func
parent
eaa8d0b142
commit
a90e1245d1
|
@ -76,12 +76,10 @@ func HandleWebMessage(isVoice bool, conn *websocket.Conn, uuid string, status in
|
||||||
} else { // web
|
} else { // web
|
||||||
if isVoice { // message from voice
|
if isVoice { // message from voice
|
||||||
if dest == kraProtocol.DestMobile { // forwarding message to mobile
|
if dest == kraProtocol.DestMobile { // forwarding message to mobile
|
||||||
connForDest := getConnForDest(dest, uuid) // get conn for mobile
|
if webClient.MobileConn != nil { // mobile is connected
|
||||||
|
|
||||||
if connForDest != nil { // mobile is connected
|
|
||||||
raw = kraProtocol.EncodeWebMessage(kraProtocol.StatusReply, cmdID, cmdNumber, args)
|
raw = kraProtocol.EncodeWebMessage(kraProtocol.StatusReply, cmdID, cmdNumber, args)
|
||||||
|
|
||||||
err = webClient.SendBinaryMessage(connForDest, raw)
|
err = webClient.SendBinaryMessage(webClient.MobileConn, raw)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.WebVoice.Warnln("write:", err)
|
logger.WebVoice.Warnln("write:", err)
|
||||||
|
@ -111,12 +109,10 @@ func HandleWebMessage(isVoice bool, conn *websocket.Conn, uuid string, status in
|
||||||
}
|
}
|
||||||
} else { // message from mobile
|
} else { // message from mobile
|
||||||
if dest == kraProtocol.DestVoice { // forwarding message to voice
|
if dest == kraProtocol.DestVoice { // forwarding message to voice
|
||||||
connForDest := getConnForDest(dest, uuid) // get conn for voice
|
if webClient.VoiceConn != nil { // voice connected
|
||||||
|
|
||||||
if connForDest != nil { // voice connected
|
|
||||||
raw = kraProtocol.EncodeWebMessage(kraProtocol.StatusSend, cmdID, cmdNumber, args)
|
raw = kraProtocol.EncodeWebMessage(kraProtocol.StatusSend, cmdID, cmdNumber, args)
|
||||||
|
|
||||||
err = webClient.SendBinaryMessage(connForDest, raw)
|
err = webClient.SendBinaryMessage(webClient.VoiceConn, raw)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.WebMobile.Warnln("write:", err)
|
logger.WebMobile.Warnln("write:", err)
|
||||||
|
@ -261,6 +257,22 @@ func getWebClientByConn(conn *websocket.Conn) *structs.WebClient {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetWebClientOrCreateNewByUuid(uuid string) *structs.WebClient {
|
||||||
|
webClient := GetWebClientByUuid(uuid)
|
||||||
|
|
||||||
|
if webClient == nil {
|
||||||
|
// add to clients list
|
||||||
|
client := &structs.WebClient{Uuid: uuid}
|
||||||
|
|
||||||
|
cache.WebClients[uuid] = client
|
||||||
|
|
||||||
|
logger.Web.Debugln("new client")
|
||||||
|
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
return webClient
|
||||||
|
}
|
||||||
|
|
||||||
func GetWebClientByUuid(Uuid string) *structs.WebClient {
|
func GetWebClientByUuid(Uuid string) *structs.WebClient {
|
||||||
logger.Web.Debugln("len clients", len(cache.WebClients))
|
logger.Web.Debugln("len clients", len(cache.WebClients))
|
||||||
|
|
||||||
|
@ -271,21 +283,18 @@ func GetWebClientByUuid(Uuid string) *structs.WebClient {
|
||||||
return client
|
return client
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
// add to clients list
|
|
||||||
client := &structs.WebClient{Uuid: Uuid}
|
|
||||||
|
|
||||||
cache.WebClients[Uuid] = client
|
|
||||||
|
|
||||||
logger.Web.Debugln("new client")
|
|
||||||
|
|
||||||
return client
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Deprecated
|
||||||
func IsVoiceAndMobileSocketConnected(uuid string) string {
|
func IsVoiceAndMobileSocketConnected(uuid string) string {
|
||||||
client := GetWebClientByUuid(uuid)
|
webClient := GetWebClientByUuid(uuid)
|
||||||
|
|
||||||
if client.MobileConn == nil && client.VoiceConn == nil {
|
if webClient == nil {
|
||||||
|
return "0"
|
||||||
|
}
|
||||||
|
|
||||||
|
if webClient.MobileConn == nil && webClient.VoiceConn == nil {
|
||||||
return "0"
|
return "0"
|
||||||
} else {
|
} else {
|
||||||
return "1"
|
return "1"
|
||||||
|
|
Loading…
Reference in New Issue