Add audio stream close

This commit is contained in:
Nonoo 2020-10-18 13:19:52 +02:00
parent 276e31b111
commit c80ecd2d3b
4 changed files with 22 additions and 5 deletions

View file

@ -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)

View file

@ -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() {

11
main.go
View file

@ -14,12 +14,21 @@ var streams struct {
}
func exit(err error) {
if err != nil {
log.Error(err.Error())
}
log.Print("disconnecting")
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)
}
}

View file

@ -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)})
}