-
Notifications
You must be signed in to change notification settings - Fork 1
/
connection_test.go
79 lines (63 loc) · 1.89 KB
/
connection_test.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package waterlink
import (
"fmt"
"github.com/lukasl-dev/waterlink/v2/event"
"log"
"time"
)
func ExampleOpen() {
creds := Credentials{
Authorization: "youshallnotpass", // passphrase defined in the server's application.yml
UserID: 820112919224124416, // the user ID of the bot user
}
conn, err := Open("ws://localhost:2333", creds)
if err != nil {
log.Fatalln(err)
}
fmt.Printf("The server is running on version %q.", conn.APIVersion())
// Output:
// The server is running on version "3".
}
func ExampleOpen_listenToEvents() {
creds := Credentials{
Authorization: "youshallnotpass", // passphrase defined in the server's application.yml
UserID: 820112919224124416, // the user ID of the bot user
}
events := EventHandlerFunc(func(evt interface{}) {
switch evt := evt.(type) {
case event.Stats:
fmt.Println("Stats received:", evt)
case event.TrackEnd:
fmt.Println("Track ended:", evt)
}
})
opts := ConnectionOptions{EventHandler: events}
conn, err := Open("ws://localhost:2333", creds, opts)
if err != nil {
log.Fatalln(err)
}
fmt.Printf("The server is running on version %q.", conn.APIVersion())
// Output:
// The server is running on version "3".
}
func ExampleOpen_resumeSession() {
creds := Credentials{
Authorization: "youshallnotpass", // passphrase defined in the server's application.yml
UserID: 820112919224124416, // the user ID of the bot user
ResumeKey: "myResumeKey", // the former configured resume key
}
conn, err := Open("ws://localhost:2333", creds)
if err != nil {
log.Fatalln(err)
}
fmt.Printf("The server is running on version %q.", conn.APIVersion())
// Output:
// The server is running on version "3".
}
func ExampleConnection_ConfigureResuming() {
var conn Connection // TODO: open connection
err := conn.ConfigureResuming("myResumeKey", 1*time.Minute)
if err != nil {
log.Fatalln(err)
}
}