From d2d2dedf92775982250839bc5fae2f323931202f Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 11 Apr 2020 18:02:50 +0200 Subject: [PATCH] Can request to close a connection --- relay.go | 12 ++++++++++++ ws.go | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/relay.go b/relay.go index cfdbbf3..6f8ef6c 100644 --- a/relay.go +++ b/relay.go @@ -411,6 +411,18 @@ func newCall(mainOffer receivedSignal, r activeRelay) { log.Printf("Err tried to add ICE Candidate for non ready peer connection!") } + } else if newMessage.sigType == CloseConnection { + + // Check if we have to close the whole connection or just a client + if newMessage.peerID == "0" { + askForClose(r) + return + } else if val, ok := clients[newMessage.peerID]; ok { + // Close a single client + val.Close() + delete(clients, newMessage.peerID) + } + } } } diff --git a/ws.go b/ws.go index 4a86177..67bb22d 100644 --- a/ws.go +++ b/ws.go @@ -82,6 +82,11 @@ func openWs(conf *Config) { onSignal(msg.CallHash, msg.PeerID, msg.Data.(map[string]interface{})) break + // Close a connection + case "close_conn": + onCloseConnection(msg.CallHash, msg.PeerID) + break + default: println("Received unkown message type!") log.Printf("recv: %s", message)