websocket: update claimed spec for message to display
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is failing Details

websocket
ALI Hamza 2019-11-04 14:01:08 +07:00
parent dd08fa1a10
commit 1fa7cfd996
No known key found for this signature in database
GPG Key ID: BCA8A46C87798C4C
4 changed files with 16 additions and 11 deletions

@ -305,10 +305,10 @@ This command will tell the display that a ticket was claimed by a staff memeber
##### example:
```
claimed StaffMember 0 {"id":0,"email":"example@example.com","name":"Example Name","staff":"StaffMember","start":"2019-10-01T04:12:19Z","end":"1970-01-01T00:00:00Z"}
claimed 0 1
```
This will tell the display that the staff member 'StaffMember' has claimed the ticket on table 0
This will tell the display that table 1 has claimed the ticket with id 1
#### complete
@ -345,4 +345,4 @@ This tells the display that a client has left serving on a table
unpick 0
```
This tells the display that the table 0 is no longer going to be accepting/serving tickets.
This tells the display that the table 0 is no longer going to be accepting/serving tickets.

@ -25,7 +25,7 @@ func NewServerMux(debug bool) http.Handler {
router.PathPrefix("/assets").Handler(http.FileServer(http.Dir("./static/")))
router.PathPrefix("/css").Handler(http.FileServer(http.Dir("./static/")))
//NotFound : A helper function that responds with a 404 status code and an error
router.PathPrefix("/js").Handler(http.FileServer(http.Dir("./static/")))
router.PathPrefix("/").HandlerFunc(indexHandler)
@ -34,4 +34,4 @@ func NewServerMux(debug bool) http.Handler {
func indexHandler(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./static/index.html")
}
}

@ -4,8 +4,9 @@ import (
"JISQueueing/common"
"JISQueueing/db"
"encoding/json"
"github.com/gorilla/websocket"
"strconv"
"github.com/gorilla/websocket"
)
var tickets = make(map[common.Ticket]bool)
@ -28,7 +29,7 @@ func claimedTicket(ticket common.Ticket, staff common.Staff, table int, who *web
tickets[ticket] = true
jsonTicket, _ := json.Marshal(ticket)
sendDisplayMessage("claimed " + staff.Username + " " + strconv.Itoa(table) + " " + string(jsonTicket))
sendDisplayMessage("claimed " + strconv.Itoa(table) + " " + strconv.Itoa(ticket.ID))
who.WriteMessage(websocket.TextMessage, []byte("success claimed "+string(jsonTicket)))
for conn, s := range connToStaff {
if s.Username != staff.Username {

@ -3,21 +3,25 @@ package socket
import (
"fmt"
"net/http"
"strings"
"github.com/gorilla/websocket"
)
type WebsocketInterface struct {
Writer http.ResponseWriter
Request *http.Request
OnConnect func(who *websocket.Conn)
OnMessage func(who *websocket.Conn, msg string)
Writer http.ResponseWriter
Request *http.Request
OnConnect func(who *websocket.Conn)
OnMessage func(who *websocket.Conn, msg string)
OnDisconnect func(who *websocket.Conn)
}
var upgrader = websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
CheckOrigin: func(r *http.Request) bool {
return strings.Contains(r.Host, "localhost")
},
}
//DisplaySocket handles all socket calls from the display machine