1
1
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-11 05:11:06 +02:00

better ui

This commit is contained in:
Zack Scholl 2019-04-11 14:24:21 -07:00
parent 1622fd5092
commit f6b69bbe46
2 changed files with 19 additions and 1 deletions

View file

@ -16,6 +16,7 @@ import (
internalSess "github.com/schollz/croc/v5/src/webrtc/internal/session"
"github.com/schollz/croc/v5/src/webrtc/pkg/session/common"
"github.com/schollz/progressbar/v2"
"github.com/schollz/spinner"
logrus "github.com/sirupsen/logrus"
)
@ -40,13 +41,18 @@ type Session struct {
sess internalSess.Session
msgChannel chan webrtc.DataChannelMessage
initialized bool
spinner *spinner.Spinner
}
func new(s internalSess.Session) *Session {
spin := spinner.New(spinner.CharSets[9], 100*time.Millisecond)
spin.Writer = os.Stderr
spin.Suffix = " creating channel..."
return &Session{
sess: s,
msgChannel: make(chan webrtc.DataChannelMessage, 4096*2),
initialized: false,
spinner: spin,
}
}
@ -68,6 +74,9 @@ func NewWith(c Config) *Session {
func (s *Session) onConnectionStateChange() func(connectionState webrtc.ICEConnectionState) {
return func(connectionState webrtc.ICEConnectionState) {
if !s.spinner.Active() {
s.spinner.Start()
}
log.Debugf("ICE Connection State has changed: %s\n", connectionState.String())
}
}
@ -196,6 +205,7 @@ func (s *Session) receiveData(pathToFile string, fileSize int64) error {
return err
} else {
if firstByte {
s.spinner.Stop()
bar = progressbar.NewOptions64(
fileSize,
progressbar.OptionSetWidth(8),
@ -203,7 +213,7 @@ func (s *Session) receiveData(pathToFile string, fileSize int64) error {
progressbar.OptionSetRenderBlankState(true),
progressbar.OptionSetBytes64(fileSize),
progressbar.OptionSetWriter(os.Stderr),
progressbar.OptionThrottle(1/60*time.Second),
progressbar.OptionThrottle(100*time.Millisecond),
)
firstByte = false
}

View file

@ -16,6 +16,7 @@ import (
"github.com/schollz/croc/v5/src/webrtc/pkg/session/common"
"github.com/schollz/croc/v5/src/webrtc/pkg/stats"
"github.com/schollz/progressbar/v2"
"github.com/schollz/spinner"
"github.com/sirupsen/logrus"
)
@ -68,10 +69,14 @@ type Session struct {
fileSize int64
fname string
firstByte bool
spinner *spinner.Spinner
}
// New creates a new sender session
func new(s internalSess.Session) *Session {
spin := spinner.New(spinner.CharSets[9], 100*time.Millisecond)
spin.Writer = os.Stderr
spin.Suffix = " creating channel..."
return &Session{
sess: s,
initialized: false,
@ -80,6 +85,7 @@ func new(s internalSess.Session) *Session {
output: make(chan outputMsg, senderBuffSize*10),
doneCheck: false,
readingStats: stats.New(),
spinner: spin,
}
}
@ -159,6 +165,7 @@ func (s *Session) SDPProvider() io.Reader {
// }
func (s *Session) CreateDataChannel() error {
s.spinner.Start()
ordered := true
maxPacketLifeTime := uint16(10000)
dataChannel, err := s.sess.CreateDataChannel(&webrtc.DataChannelInit{
@ -254,6 +261,7 @@ func (s *Session) onBufferedAmountLow() func() {
s.sess.NetworkStats.AddBytes(uint64(cur.n))
if s.firstByte {
s.firstByte = false
s.spinner.Stop()
fmt.Fprint(os.Stderr, "\n")
s.bar = progressbar.NewOptions64(
s.fileSize,