//Client connects to host. Client and host send messages to each other //and server doesn't process these messages, just forwards them func actSelectHost(data *interface{}, client *wserver.Client) { name, _ := (*data).(string) host, ok := hostConnections.GetByLogin(name) if !ok { client.SendJson(&Action{"SELECT_FAIL", "host not exist"}) return } host.Lock() defer func() { host.Unlock() log.Println("-----------UNLOCK") }() if host.Active { client.SendJson(&Action{"SELECT_FAIL", "host busy"}) return } host.Active = true host.Conn.SendJson(&Action{"CLIENT_CONNECT", ""}) log.Println("-----------LOCKED1") host.Wait() log.Println("-----------LOCKED2") if host.Active == false { client.SendJson(&Action{"SELECT_FAIL", "denied"}) return } host.Conn.SetOnmessage(copyMessage(client)) client.SetOnmessage(copyMessage(host.Conn)) chRelay.Add(client, host) client.SendJson(&Action{"SELECT_SUCCESS", ""}) }