Skip to content

Commit

Permalink
Improved reliability, still not Ok..
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonito committed Mar 10, 2019
1 parent 881cd9f commit e2ed0ea
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions cmd/send/session/session.go
Expand Up @@ -24,6 +24,7 @@ type Session struct {
peerConnection *webrtc.PeerConnection
dataChannel *webrtc.DataChannel
dataBuff []byte
msgToBeSent []outputMsg

// Control
done chan struct{}
Expand Down
24 changes: 19 additions & 5 deletions cmd/send/session/state.go
Expand Up @@ -25,6 +25,7 @@ func (s *Session) writeToNetwork() {
defer fmt.Println("Stopped sending data...")

for {
SELECT:
select {
case <-s.stopSending:
fmt.Printf("Pausing network I/O... (remaining at least %v packets)", len(s.output))
Expand All @@ -36,12 +37,25 @@ func (s *Session) writeToNetwork() {
return
}

// Writing packet
if err := s.dataChannel.Send(data.buff); err != nil {
fmt.Printf("Error, cannot send to client: %v\n", err)
return
s.msgToBeSent = append(s.msgToBeSent, data)

for len(s.msgToBeSent) != 0 {
cur := s.msgToBeSent[0]

// TODO: Correct check
if s.dataChannel.ReadyState != webrtc.DataChannelStateOpen {
fmt.Printf("Status: %v, dropping %v bytes\n", s.dataChannel.ReadyState, data.n)
break SELECT
}

// Writing packet
if err := s.dataChannel.Send(cur.buff); err != nil {
fmt.Printf("Error, cannot send to client: %v\n", err)
return
}
s.nbBytesSent += uint64(cur.n)
s.msgToBeSent = s.msgToBeSent[1:]
}
s.nbBytesSent += uint64(data.n)
}
}
}
Expand Down

0 comments on commit e2ed0ea

Please sign in to comment.