Skip to content

Commit

Permalink
Improving the control messsages interface
Browse files Browse the repository at this point in the history
  • Loading branch information
daonb committed Jul 28, 2024
1 parent 08a4faa commit 100ae89
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ his file's format is define in
[Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and the release workflow reads it to set github's release notes.

## [1.5.1] 2024-7-28

### Fixed

- `webexec status` now shows the correct ICE candidate pairs

## [1.5.0] 2024-6-3

Expand Down
8 changes: 6 additions & 2 deletions peers/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type Conf struct {
GetWelcome func() string
KeepAliveInterval time.Duration
Logger *zap.SugaredLogger
OnCTRLMsg func(*Peer, CTRLMessage, json.RawMessage)
OnCTRLMsg func(*Peer, *CTRLMessage, json.RawMessage)
OnStateChange func(*Peer, webrtc.PeerConnectionState)
PortMax uint16
PortMin uint16
Expand Down Expand Up @@ -230,6 +230,10 @@ func (peer *Peer) OnChannelReq(d *webrtc.DataChannel) {
if label != "%" {
peer.logger.Infof("Ignoring a strange channel label %q", label)
}
// cdc is open, let the caller know
if peer.Conf.OnCTRLMsg != nil {
peer.Conf.OnCTRLMsg(peer, nil, nil)
}
})
}

Expand Down Expand Up @@ -259,7 +263,7 @@ func (peer *Peer) handleCTRLMsg(msg webrtc.DataChannelMessage) {
case "nack":
peer.handleNack(m, raw)
default:
peer.Conf.OnCTRLMsg(peer, m, raw)
peer.Conf.OnCTRLMsg(peer, &m, raw)
}
}

Expand Down
2 changes: 1 addition & 1 deletion peers/peer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestActivePeer(t *testing.T) {
GetICEServers: func() ([]webrtc.ICEServer, error) {
return []webrtc.ICEServer{}, nil
},
OnCTRLMsg: func(*Peer, CTRLMessage, json.RawMessage) {
OnCTRLMsg: func(*Peer, *CTRLMessage, json.RawMessage) {
return
},
}
Expand Down
22 changes: 13 additions & 9 deletions webexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,26 +754,30 @@ func pasteCMD(c *cli.Context) error {
}

// handleCTRLMsg handles incoming control messages
func handleCTRLMsg(peer *peers.Peer, m peers.CTRLMessage, raw json.RawMessage) {
func handleCTRLMsg(peer *peers.Peer, m *peers.CTRLMessage, raw json.RawMessage) {
// do nothing on connection open and nil messages
if m == nil {
return
}
switch m.Type {
case "resize":
handleResize(peer, m, raw)
handleResize(peer, *m, raw)
case "restore":
handleRestore(peer, m, raw)
handleRestore(peer, *m, raw)
case "get_payload":
handleGetPayload(peer, m)
handleGetPayload(peer, *m)
case "set_payload":
handleSetPayload(peer, m, raw)
handleSetPayload(peer, *m, raw)
case "mark":
handleMark(peer, m)
handleMark(peer, *m)
case "reconnect_pane":
handleReconnectPane(peer, m, raw)
handleReconnectPane(peer, *m, raw)
case "add_pane":
handleAddPane(peer, m, raw)
handleAddPane(peer, *m, raw)
default:
Logger.Errorf("Got a control message with unknown type: %q", m.Type)
// send nack
err := peer.SendNack(m, "unknown control message type")
err := peer.SendNack(*m, "unknown control message type")
if err != nil {
Logger.Errorf("#%d: Failed to send nack: %v", peer.FP, err)
}
Expand Down

0 comments on commit 100ae89

Please sign in to comment.