mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 21:30:16 +02:00
better ui
This commit is contained in:
parent
1622fd5092
commit
f6b69bbe46
2 changed files with 19 additions and 1 deletions
|
@ -16,6 +16,7 @@ import (
|
||||||
internalSess "github.com/schollz/croc/v5/src/webrtc/internal/session"
|
internalSess "github.com/schollz/croc/v5/src/webrtc/internal/session"
|
||||||
"github.com/schollz/croc/v5/src/webrtc/pkg/session/common"
|
"github.com/schollz/croc/v5/src/webrtc/pkg/session/common"
|
||||||
"github.com/schollz/progressbar/v2"
|
"github.com/schollz/progressbar/v2"
|
||||||
|
"github.com/schollz/spinner"
|
||||||
logrus "github.com/sirupsen/logrus"
|
logrus "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -40,13 +41,18 @@ type Session struct {
|
||||||
sess internalSess.Session
|
sess internalSess.Session
|
||||||
msgChannel chan webrtc.DataChannelMessage
|
msgChannel chan webrtc.DataChannelMessage
|
||||||
initialized bool
|
initialized bool
|
||||||
|
spinner *spinner.Spinner
|
||||||
}
|
}
|
||||||
|
|
||||||
func new(s internalSess.Session) *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{
|
return &Session{
|
||||||
sess: s,
|
sess: s,
|
||||||
msgChannel: make(chan webrtc.DataChannelMessage, 4096*2),
|
msgChannel: make(chan webrtc.DataChannelMessage, 4096*2),
|
||||||
initialized: false,
|
initialized: false,
|
||||||
|
spinner: spin,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,6 +74,9 @@ func NewWith(c Config) *Session {
|
||||||
|
|
||||||
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) {
|
||||||
|
if !s.spinner.Active() {
|
||||||
|
s.spinner.Start()
|
||||||
|
}
|
||||||
log.Debugf("ICE Connection State has changed: %s\n", connectionState.String())
|
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
|
return err
|
||||||
} else {
|
} else {
|
||||||
if firstByte {
|
if firstByte {
|
||||||
|
s.spinner.Stop()
|
||||||
bar = progressbar.NewOptions64(
|
bar = progressbar.NewOptions64(
|
||||||
fileSize,
|
fileSize,
|
||||||
progressbar.OptionSetWidth(8),
|
progressbar.OptionSetWidth(8),
|
||||||
|
@ -203,7 +213,7 @@ func (s *Session) receiveData(pathToFile string, fileSize int64) error {
|
||||||
progressbar.OptionSetRenderBlankState(true),
|
progressbar.OptionSetRenderBlankState(true),
|
||||||
progressbar.OptionSetBytes64(fileSize),
|
progressbar.OptionSetBytes64(fileSize),
|
||||||
progressbar.OptionSetWriter(os.Stderr),
|
progressbar.OptionSetWriter(os.Stderr),
|
||||||
progressbar.OptionThrottle(1/60*time.Second),
|
progressbar.OptionThrottle(100*time.Millisecond),
|
||||||
)
|
)
|
||||||
firstByte = false
|
firstByte = false
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import (
|
||||||
"github.com/schollz/croc/v5/src/webrtc/pkg/session/common"
|
"github.com/schollz/croc/v5/src/webrtc/pkg/session/common"
|
||||||
"github.com/schollz/croc/v5/src/webrtc/pkg/stats"
|
"github.com/schollz/croc/v5/src/webrtc/pkg/stats"
|
||||||
"github.com/schollz/progressbar/v2"
|
"github.com/schollz/progressbar/v2"
|
||||||
|
"github.com/schollz/spinner"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -68,10 +69,14 @@ type Session struct {
|
||||||
fileSize int64
|
fileSize int64
|
||||||
fname string
|
fname string
|
||||||
firstByte bool
|
firstByte bool
|
||||||
|
spinner *spinner.Spinner
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new sender session
|
// New creates a new sender session
|
||||||
func new(s internalSess.Session) *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{
|
return &Session{
|
||||||
sess: s,
|
sess: s,
|
||||||
initialized: false,
|
initialized: false,
|
||||||
|
@ -80,6 +85,7 @@ func new(s internalSess.Session) *Session {
|
||||||
output: make(chan outputMsg, senderBuffSize*10),
|
output: make(chan outputMsg, senderBuffSize*10),
|
||||||
doneCheck: false,
|
doneCheck: false,
|
||||||
readingStats: stats.New(),
|
readingStats: stats.New(),
|
||||||
|
spinner: spin,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,6 +165,7 @@ func (s *Session) SDPProvider() io.Reader {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
func (s *Session) CreateDataChannel() error {
|
func (s *Session) CreateDataChannel() error {
|
||||||
|
s.spinner.Start()
|
||||||
ordered := true
|
ordered := true
|
||||||
maxPacketLifeTime := uint16(10000)
|
maxPacketLifeTime := uint16(10000)
|
||||||
dataChannel, err := s.sess.CreateDataChannel(&webrtc.DataChannelInit{
|
dataChannel, err := s.sess.CreateDataChannel(&webrtc.DataChannelInit{
|
||||||
|
@ -254,6 +261,7 @@ func (s *Session) onBufferedAmountLow() func() {
|
||||||
s.sess.NetworkStats.AddBytes(uint64(cur.n))
|
s.sess.NetworkStats.AddBytes(uint64(cur.n))
|
||||||
if s.firstByte {
|
if s.firstByte {
|
||||||
s.firstByte = false
|
s.firstByte = false
|
||||||
|
s.spinner.Stop()
|
||||||
fmt.Fprint(os.Stderr, "\n")
|
fmt.Fprint(os.Stderr, "\n")
|
||||||
s.bar = progressbar.NewOptions64(
|
s.bar = progressbar.NewOptions64(
|
||||||
s.fileSize,
|
s.fileSize,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue