diff --git a/audiostream.go b/audiostream.go index eee84db..dd9e550 100644 --- a/audiostream.go +++ b/audiostream.go @@ -10,6 +10,10 @@ type audioStream struct { common streamCommon } +func (s *audioStream) sendDisconnect() { + s.common.sendDisconnect() +} + func (s *audioStream) start() { s.common.open("audio", 50003) diff --git a/controlstream.go b/controlstream.go index cdf848d..752a56c 100644 --- a/controlstream.go +++ b/controlstream.go @@ -102,9 +102,7 @@ func (s *controlStream) sendDisconnect() { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}) - s.common.send([]byte{0x10, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, - byte(s.common.localSID >> 24), byte(s.common.localSID >> 16), byte(s.common.localSID >> 8), byte(s.common.localSID), - byte(s.common.remoteSID >> 24), byte(s.common.remoteSID >> 16), byte(s.common.remoteSID >> 8), byte(s.common.remoteSID)}) + s.common.sendDisconnect() } func (s *controlStream) sendPkt0() { diff --git a/main.go b/main.go index 5c02651..b71fc9b 100644 --- a/main.go +++ b/main.go @@ -14,12 +14,21 @@ var streams struct { } func exit(err error) { + if err != nil { + log.Error(err.Error()) + } log.Print("disconnecting") - streams.control.sendDisconnect() + + if streams.audio.common.conn != nil { + streams.audio.sendDisconnect() + } + if streams.control.common.conn != nil { + streams.control.sendDisconnect() + } + if err == nil { os.Exit(0) } else { - log.Error(err.Error()) os.Exit(1) } } diff --git a/streamcommon.go b/streamcommon.go index dd36af5..0105f71 100644 --- a/streamcommon.go +++ b/streamcommon.go @@ -149,3 +149,9 @@ func (s *streamCommon) sendPkt7() { func (s *streamCommon) sendPkt7Reply(replyID []byte, seq uint16) { s.sendPkt7Do(replyID, seq) } + +func (s *streamCommon) sendDisconnect() { + s.send([]byte{0x10, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + byte(s.localSID >> 24), byte(s.localSID >> 16), byte(s.localSID >> 8), byte(s.localSID), + byte(s.remoteSID >> 24), byte(s.remoteSID >> 16), byte(s.remoteSID >> 8), byte(s.remoteSID)}) +}