mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
can stop sending
This commit is contained in:
parent
b8689c8eeb
commit
c58aaf860d
3 changed files with 18 additions and 15 deletions
|
@ -76,10 +76,12 @@ func (s *Session) onBufferedAmountLow() func() {
|
|||
|
||||
func (s *Session) writeToNetwork() {
|
||||
// Set callback, as transfer may be paused
|
||||
fmt.Println("\nwriting")
|
||||
s.dataChannel.OnBufferedAmountLow(s.onBufferedAmountLow())
|
||||
|
||||
fmt.Println("\ndone")
|
||||
<-s.stopSending
|
||||
fmt.Println("\nstopped sending")
|
||||
s.dataChannel.OnBufferedAmountLow(nil)
|
||||
s.sess.NetworkStats.Pause()
|
||||
log.Infof("Pausing network I/O... (remaining at least %v packets)\n", len(s.output))
|
||||
s.sess.NetworkStats.Pause()
|
||||
}
|
||||
|
|
|
@ -7,11 +7,15 @@ import (
|
|||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func (s *Session) StopSending() {
|
||||
s.stopSending <- struct{}{}
|
||||
}
|
||||
|
||||
func (s *Session) onConnectionStateChange() func(connectionState webrtc.ICEConnectionState) {
|
||||
return func(connectionState webrtc.ICEConnectionState) {
|
||||
log.Infof("ICE Connection State has changed: %s\n", connectionState.String())
|
||||
if connectionState == webrtc.ICEConnectionStateDisconnected {
|
||||
s.stopSending <- struct{}{}
|
||||
s.StopSending()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -392,7 +392,10 @@ func (c *Client) processMessage(m Message) (err error) {
|
|||
// start receiving data
|
||||
pathToFile := path.Join(c.FilesToTransfer[c.FilesToTransferCurrentNum].FolderRemote, c.FilesToTransfer[c.FilesToTransferCurrentNum].Name)
|
||||
c.recvSess.ReceiveData(pathToFile)
|
||||
|
||||
fmt.Println("\ndone receiving")
|
||||
err = c.redisdb.Publish(c.nameOutChannel, Message{
|
||||
Type: "close-sender",
|
||||
}.String()).Err()
|
||||
case "datachannel-answer":
|
||||
c.log.Debug("got answer:", m.Message)
|
||||
// Apply the answer as the remote description
|
||||
|
@ -400,22 +403,16 @@ func (c *Client) processMessage(m Message) (err error) {
|
|||
pathToFile := path.Join(c.FilesToTransfer[c.FilesToTransferCurrentNum].FolderSource, c.FilesToTransfer[c.FilesToTransferCurrentNum].Name)
|
||||
c.sendSess.TransferFile(pathToFile)
|
||||
case "close-sender":
|
||||
c.peerConnection[m.Num].Close()
|
||||
c.peerConnection[m.Num] = nil
|
||||
c.dataChannel[m.Num].Close()
|
||||
c.dataChannel[m.Num] = nil
|
||||
// c.Step4FileTransfer = false
|
||||
// c.Step3RecipientRequestFile = false
|
||||
c.Step4FileTransfer = false
|
||||
c.Step3RecipientRequestFile = false
|
||||
c.sendSess.StopSending()
|
||||
err = c.redisdb.Publish(c.nameOutChannel, Message{
|
||||
Type: "close-recipient",
|
||||
Num: m.Num,
|
||||
}.String()).Err()
|
||||
case "close-recipient":
|
||||
c.peerConnection[m.Num].Close()
|
||||
c.peerConnection[m.Num] = nil
|
||||
c.dataChannel[m.Num] = nil
|
||||
// c.Step4FileTransfer = false
|
||||
// c.Step3RecipientRequestFile = false
|
||||
c.Step4FileTransfer = false
|
||||
c.Step3RecipientRequestFile = false
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue