Skip to content

Commit

Permalink
websocket support
Browse files Browse the repository at this point in the history
  • Loading branch information
jcodybaker committed Dec 22, 2024
1 parent 4462eb2 commit d74fc2c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/discovery/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package discovery
import (
"context"
"fmt"
"strings"
"time"

mqtt "github.com/eclipse/paho.mqtt.golang"
Expand Down Expand Up @@ -47,6 +48,16 @@ func (d *Device) Open(ctx context.Context) (mgrpc.MgRPC, error) {
}
return mgrpc.Serve(ctx, c), nil
}
if strings.HasPrefix(d.uri, "ws://") || strings.HasPrefix(d.uri, "wss://") {
c, err := mgrpc.New(ctx, d.uri,
mgrpc.UseWebSocket(),
)
if err != nil {
return nil, fmt.Errorf("establishing rpc channel: %w", err)
}
ll.Info().Str("channel_protocol", "http").Msg("connected to device")
return c, nil
}
c, err := mgrpc.New(ctx, d.uri,
mgrpc.UseHTTPPost(),
mgrpc.CodecOptions(
Expand Down
1 change: 1 addition & 0 deletions pkg/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func (d *Discoverer) AddDeviceByAddress(ctx context.Context, addr string, opts .
}
switch u.Scheme {
case "http", "https":
case "ws", "wss":
default:
return nil, fmt.Errorf("unsupported URI scheme %q", u.Scheme)
}
Expand Down

0 comments on commit d74fc2c

Please sign in to comment.