WASM: tick immediately when idle, batch when ack pending
This commit is contained in:
+12
-3
@@ -85,14 +85,19 @@ func newSession(url, key string) (*session, error) {
|
||||
func (s *session) jsObject() js.Value {
|
||||
obj := js.Global().Get("Object").New()
|
||||
|
||||
// Keystrokes are queued via Send(). The JS interval flushes them.
|
||||
// Do NOT tick from send — the WebTransport ack round-trip is ~50ms,
|
||||
// and ticking per-keystroke creates duplicate sequence numbers.
|
||||
// Tick immediately when idle (no unacked states). When busy (ack
|
||||
// pending), queue keystrokes and let the interval flush them.
|
||||
// This gives instant feel for the first key while preventing
|
||||
// cumulative state duplication during rapid typing.
|
||||
obj.Set("send", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
||||
if len(args) < 1 {
|
||||
return nil
|
||||
}
|
||||
s.client.Send([]byte(args[0].String()))
|
||||
t := s.client.Transport()
|
||||
if t.AckedByRemote() >= t.SentNum() {
|
||||
s.client.Tick()
|
||||
}
|
||||
return nil
|
||||
}))
|
||||
|
||||
@@ -101,6 +106,10 @@ func (s *session) jsObject() js.Value {
|
||||
return nil
|
||||
}
|
||||
s.client.Resize(uint16(args[0].Int()), uint16(args[1].Int()))
|
||||
t := s.client.Transport()
|
||||
if t.AckedByRemote() >= t.SentNum() {
|
||||
s.client.Tick()
|
||||
}
|
||||
return nil
|
||||
}))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user