This repository has been archived by the owner on May 1, 2020. It is now read-only.
/
clientImpl.go
64 lines (54 loc) · 1.6 KB
/
clientImpl.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
59
60
61
62
63
64
package test
import (
wwr "github.com/qbeon/webwire-go"
wwrclt "github.com/qbeon/webwire-go/client"
)
type callbackPoweredClientHooks struct {
OnSessionCreated func(*wwr.Session)
OnSessionClosed func()
OnDisconnected func()
OnSignal func(wwr.Payload)
}
// callbackPoweredClient implements the wwrclt.Implementation interface
type callbackPoweredClient struct {
connection *wwrclt.Client
hooks callbackPoweredClientHooks
}
// newCallbackPoweredClient constructs and returns a new echo client instance
func newCallbackPoweredClient(
serverAddr string,
opts wwrclt.Options,
hooks callbackPoweredClientHooks,
) *callbackPoweredClient {
newClt := &callbackPoweredClient{
nil,
hooks,
}
// Initialize connection
newClt.connection = wwrclt.NewClient(serverAddr, newClt, opts)
return newClt
}
// OnSessionCreated implements the wwrclt.Implementation interface
func (clt *callbackPoweredClient) OnSessionCreated(newSession *wwr.Session) {
if clt.hooks.OnSessionCreated != nil {
clt.hooks.OnSessionCreated(newSession)
}
}
// OnSessionClosed implements the wwrclt.Implementation interface
func (clt *callbackPoweredClient) OnSessionClosed() {
if clt.hooks.OnSessionClosed != nil {
clt.hooks.OnSessionClosed()
}
}
// OnDisconnected implements the wwrclt.Implementation interface
func (clt *callbackPoweredClient) OnDisconnected() {
if clt.hooks.OnDisconnected != nil {
clt.hooks.OnDisconnected()
}
}
// OnSignal implements the wwrclt.Implementation interface
func (clt *callbackPoweredClient) OnSignal(message wwr.Payload) {
if clt.hooks.OnSignal != nil {
clt.hooks.OnSignal(message)
}
}