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() {
|
func (s *Session) writeToNetwork() {
|
||||||
// Set callback, as transfer may be paused
|
// Set callback, as transfer may be paused
|
||||||
|
fmt.Println("\nwriting")
|
||||||
s.dataChannel.OnBufferedAmountLow(s.onBufferedAmountLow())
|
s.dataChannel.OnBufferedAmountLow(s.onBufferedAmountLow())
|
||||||
|
fmt.Println("\ndone")
|
||||||
<-s.stopSending
|
<-s.stopSending
|
||||||
|
fmt.Println("\nstopped sending")
|
||||||
s.dataChannel.OnBufferedAmountLow(nil)
|
s.dataChannel.OnBufferedAmountLow(nil)
|
||||||
s.sess.NetworkStats.Pause()
|
|
||||||
log.Infof("Pausing network I/O... (remaining at least %v packets)\n", len(s.output))
|
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"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (s *Session) StopSending() {
|
||||||
|
s.stopSending <- struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Session) onConnectionStateChange() func(connectionState webrtc.ICEConnectionState) {
|
func (s *Session) onConnectionStateChange() func(connectionState webrtc.ICEConnectionState) {
|
||||||
return func(connectionState webrtc.ICEConnectionState) {
|
return func(connectionState webrtc.ICEConnectionState) {
|
||||||
log.Infof("ICE Connection State has changed: %s\n", connectionState.String())
|
log.Infof("ICE Connection State has changed: %s\n", connectionState.String())
|
||||||
if connectionState == webrtc.ICEConnectionStateDisconnected {
|
if connectionState == webrtc.ICEConnectionStateDisconnected {
|
||||||
s.stopSending <- struct{}{}
|
s.StopSending()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -392,7 +392,10 @@ func (c *Client) processMessage(m Message) (err error) {
|
||||||
// start receiving data
|
// start receiving data
|
||||||
pathToFile := path.Join(c.FilesToTransfer[c.FilesToTransferCurrentNum].FolderRemote, c.FilesToTransfer[c.FilesToTransferCurrentNum].Name)
|
pathToFile := path.Join(c.FilesToTransfer[c.FilesToTransferCurrentNum].FolderRemote, c.FilesToTransfer[c.FilesToTransferCurrentNum].Name)
|
||||||
c.recvSess.ReceiveData(pathToFile)
|
c.recvSess.ReceiveData(pathToFile)
|
||||||
|
fmt.Println("\ndone receiving")
|
||||||
|
err = c.redisdb.Publish(c.nameOutChannel, Message{
|
||||||
|
Type: "close-sender",
|
||||||
|
}.String()).Err()
|
||||||
case "datachannel-answer":
|
case "datachannel-answer":
|
||||||
c.log.Debug("got answer:", m.Message)
|
c.log.Debug("got answer:", m.Message)
|
||||||
// Apply the answer as the remote description
|
// 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)
|
pathToFile := path.Join(c.FilesToTransfer[c.FilesToTransferCurrentNum].FolderSource, c.FilesToTransfer[c.FilesToTransferCurrentNum].Name)
|
||||||
c.sendSess.TransferFile(pathToFile)
|
c.sendSess.TransferFile(pathToFile)
|
||||||
case "close-sender":
|
case "close-sender":
|
||||||
c.peerConnection[m.Num].Close()
|
c.Step4FileTransfer = false
|
||||||
c.peerConnection[m.Num] = nil
|
c.Step3RecipientRequestFile = false
|
||||||
c.dataChannel[m.Num].Close()
|
c.sendSess.StopSending()
|
||||||
c.dataChannel[m.Num] = nil
|
|
||||||
// c.Step4FileTransfer = false
|
|
||||||
// c.Step3RecipientRequestFile = false
|
|
||||||
err = c.redisdb.Publish(c.nameOutChannel, Message{
|
err = c.redisdb.Publish(c.nameOutChannel, Message{
|
||||||
Type: "close-recipient",
|
Type: "close-recipient",
|
||||||
Num: m.Num,
|
Num: m.Num,
|
||||||
}.String()).Err()
|
}.String()).Err()
|
||||||
case "close-recipient":
|
case "close-recipient":
|
||||||
c.peerConnection[m.Num].Close()
|
c.Step4FileTransfer = false
|
||||||
c.peerConnection[m.Num] = nil
|
c.Step3RecipientRequestFile = false
|
||||||
c.dataChannel[m.Num] = nil
|
|
||||||
// c.Step4FileTransfer = false
|
|
||||||
// c.Step3RecipientRequestFile = false
|
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue