Skip to content

Commit

Permalink
Merge pull request #2 from muzzammilshahid/split-webrtc-wamp
Browse files Browse the repository at this point in the history
Refactor into separate functions for WebRTC connection and WAMP session
  • Loading branch information
om26er authored Dec 6, 2024
2 parents 26835dc + a79fe77 commit 80a9e0a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
16 changes: 14 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type ClientConfig struct {
Serializer xconn.WSSerializerSpec
}

func ConnectWebRTC(config *ClientConfig) (*xconn.Session, error) {
func ConnectWebRTC(config *ClientConfig) (*WebRTCSession, error) {
session, err := xconn.Connect(context.Background(), config.URL, config.Realm)
if err != nil {
return nil, err
Expand Down Expand Up @@ -60,7 +60,19 @@ func ConnectWebRTC(config *ClientConfig) (*xconn.Session, error) {

channel := <-offerer.WaitReady()

peer := NewWebRTCPeer(channel)
return &WebRTCSession{
Channel: channel,
Connection: offerer.connection,
}, nil
}

func ConnectWAMP(config *ClientConfig) (*xconn.Session, error) {
webRTCConnection, err := ConnectWebRTC(config)
if err != nil {
return nil, err
}

peer := NewWebRTCPeer(webRTCConnection.Channel)
base, err := xconn.Join(peer, config.Realm, config.Serializer.Serializer(), nil)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion cmd/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func main() {
TopicAnswererOnCandidate: topicAnswererOnCandidate,
Serializer: xconn.CBORSerializerSpec,
}
session, err := wamp_webrtc_go.ConnectWebRTC(config)
session, err := wamp_webrtc_go.ConnectWAMP(config)
if err != nil {
log.Fatal(err)
}
Expand Down
5 changes: 5 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ type ProviderConfig struct {
TopicPublishLocalCandidate string
Serializer serializers.Serializer
}

type WebRTCSession struct {
Connection *webrtc.PeerConnection
Channel *webrtc.DataChannel
}

0 comments on commit 80a9e0a

Please sign in to comment.