Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
kataras committed Mar 21, 2020
1 parent 4f4fce4 commit a6bf2ab
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.vscode
_authortools
/_examples/issue-*/
/_examples/**/node_modules
.directory
*.exe
*.exe
29 changes: 20 additions & 9 deletions _examples/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bufio"
"context"
"encoding/json"
"fmt"
"log"
Expand Down Expand Up @@ -169,26 +170,34 @@ func startServer() {
}

func startClient() {
scanner := bufio.NewScanner(os.Stdin)

fmt.Print("Please specify a username: ")
if !scanner.Scan() {
return
var username string
fmt.Print("Please specify a unique name: ")
fmt.Scanln(&username)

// init a gobwas(could use a gorilla one instead) Dialer.
options := gobwas.Options{
Header: gobwas.Header{
"X-Username": []string{username},
},
}
username := scanner.Text()
dialer := gobwas.Dialer(options)

// init the websocket connection by dialing the server.
client, err := neffos.Dial(
// Optional context cancelation and deadline for dialing.
nil,
context.TODO(),
// The underline dialer, can be also a gobwas.Dialer/DefautlDialer or a gorilla.Dialer/DefaultDialer.
// Here we wrap a custom gobwas dialer in order to send the username among, on the handshake state,
// see `startServer().server.IDGenerator`.
gobwas.Dialer(gobwas.Options{Header: gobwas.Header{"X-Username": []string{username}}}),
dialer,
// The endpoint, i.e ws://localhost:8080/path.
addr+endpoint,
// The namespaces and events, can be optionally shared with the server's.
serverAndClientEvents)
serverAndClientEvents,
)
if err != nil {
log.Fatal(err)
}

if err != nil {
log.Fatal(err)
Expand All @@ -209,6 +218,8 @@ func startClient() {

var room *neffos.Room

scanner := bufio.NewScanner(os.Stdin)

askRoom:
if !serverJoinRoom {
fmt.Print("Please specify a room to join, i.e room1: ")
Expand Down
File renamed without changes.

0 comments on commit a6bf2ab

Please sign in to comment.