-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient.go
58 lines (47 loc) · 1.41 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package xconn
import (
"context"
"net"
"time"
"github.com/xconnio/wampproto-go/auth"
)
type Client struct {
Authenticator auth.ClientAuthenticator
SerializerSpec WSSerializerSpec
NetDial func(ctx context.Context, network, addr string) (net.Conn, error)
DialTimeout time.Duration
KeepAliveInterval time.Duration
KeepAliveTimeout time.Duration
}
func (c *Client) Connect(ctx context.Context, url string, realm string) (*Session, error) {
if c.SerializerSpec == nil {
c.SerializerSpec = JSONSerializerSpec
}
joiner := &WebSocketJoiner{
Authenticator: c.Authenticator,
SerializerSpec: c.SerializerSpec,
}
dialerConfig := &WSDialerConfig{
SubProtocol: c.SerializerSpec.SubProtocol(),
DialTimeout: c.DialTimeout,
NetDial: c.NetDial,
KeepAliveInterval: c.KeepAliveInterval,
KeepAliveTimeout: c.KeepAliveTimeout,
}
base, err := joiner.Join(ctx, url, realm, dialerConfig)
if err != nil {
return nil, err
}
return NewSession(base, c.SerializerSpec.Serializer()), nil // nolint: contextcheck
}
func Connect(ctx context.Context, url string, realm string) (*Session, error) {
joiner := &WebSocketJoiner{}
dialerConfig := &WSDialerConfig{
SubProtocol: JsonWebsocketProtocol,
}
base, err := joiner.Join(ctx, url, realm, dialerConfig)
if err != nil {
return nil, err
}
return NewSession(base, JSONSerializerSpec.Serializer()), nil // nolint: contextcheck
}