diff --git a/client.go b/client.go index 3980218..6c534d4 100644 --- a/client.go +++ b/client.go @@ -271,7 +271,8 @@ func (c *Client) Close() { func (c *Client) doClose() { closed := c.closed.Add(1) - if closed == 1 { + switch closed { + case 1: c.mu.Lock() defer c.mu.Unlock() if c.conn != nil { @@ -279,7 +280,7 @@ func (c *Client) doClose() { c.conn.Close() c.conn = nil } - } else if closed == 2 { + case 2: // Both the read pump and message processing must be finished before closing. c.closer.Close() <-c.messagesDone diff --git a/hub_test.go b/hub_test.go index cf191e4..16b2341 100644 --- a/hub_test.go +++ b/hub_test.go @@ -349,9 +349,10 @@ func processAuthRequest(t *testing.T, w http.ResponseWriter, r *http.Request, re if len(request.Auth.Params) > 0 { require.NoError(json.Unmarshal(request.Auth.Params, ¶ms)) } - if params.UserId == "" { + switch params.UserId { + case "": params.UserId = testDefaultUserId - } else if params.UserId == authAnonymousUserId { + case authAnonymousUserId: params.UserId = "" } diff --git a/mcu_proxy.go b/mcu_proxy.go index 8dff7b4..a50a835 100644 --- a/mcu_proxy.go +++ b/mcu_proxy.go @@ -749,9 +749,10 @@ func (c *mcuProxyConnection) reconnect() { c.scheduleReconnect() return } - if u.Scheme == "http" { + switch u.Scheme { + case "http": u.Scheme = "ws" - } else if u.Scheme == "https" { + case "https": u.Scheme = "wss" } diff --git a/mcu_test.go b/mcu_test.go index 1fb6841..6db0db6 100644 --- a/mcu_test.go +++ b/mcu_test.go @@ -200,13 +200,14 @@ func (p *TestMCUPublisher) SendMessage(ctx context.Context, message *MessageClie sdp := data.Payload["sdp"] if sdp, ok := sdp.(string); ok { p.sdp = sdp - if sdp == MockSdpOfferAudioOnly { + switch sdp { + case MockSdpOfferAudioOnly: callback(nil, map[string]interface{}{ "type": "answer", "sdp": MockSdpAnswerAudioOnly, }) return - } else if sdp == MockSdpOfferAudioAndVideo { + case MockSdpOfferAudioAndVideo: callback(nil, map[string]interface{}{ "type": "answer", "sdp": MockSdpAnswerAudioAndVideo, diff --git a/proxy/proxy_remote.go b/proxy/proxy_remote.go index 81a7bbf..fadc4d0 100644 --- a/proxy/proxy_remote.go +++ b/proxy/proxy_remote.go @@ -118,9 +118,10 @@ func (c *RemoteConnection) reconnect() { c.scheduleReconnect() return } - if u.Scheme == "http" { + switch u.Scheme { + case "http": u.Scheme = "ws" - } else if u.Scheme == "https" { + case "https": u.Scheme = "wss" } diff --git a/room.go b/room.go index e6e04fb..46f6cff 100644 --- a/room.go +++ b/room.go @@ -979,14 +979,15 @@ func (r *Room) NotifySessionChanged(session Session, flags SessionChangeFlag) { } if joinLeave != 0 { - if joinLeave == 1 { + switch joinLeave { + case 1: r.mu.Lock() if !r.inCallSessions[session] { r.inCallSessions[session] = true log.Printf("Session %s joined call %s", session.PublicId(), r.id) } r.mu.Unlock() - } else if joinLeave == 2 { + case 2: r.mu.Lock() delete(r.inCallSessions, session) r.mu.Unlock()