-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
67 lines (53 loc) · 1.71 KB
/
main.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
package main
import (
"fmt"
"net/http"
socketServer "github.com/kaschula/soc-draw/app"
)
func main() {
appClientPath := "public/simple-chat"
appServer := NewSimpleChatApplication()
go appServer.Run()
// Data
userOne := &socketServer.User{"user:1"}
userTwo := &socketServer.User{"user:2"}
userThree := &socketServer.User{"user:3"}
userFour := &socketServer.User{"user:4"}
users := map[string]*socketServer.User{
userOne.ID: userOne,
userTwo.ID: userTwo,
userThree.ID: userThree,
userFour.ID: userFour,
}
globalRooms := []socketServer.RoomI{
socketServer.NewDefaultRoom("R:1", "First Room", appServer),
socketServer.NewDefaultRoom("R:2", "Second Room", appServer),
}
roomService := map[*socketServer.User][]socketServer.RoomI{
userOne: globalRooms,
userTwo: globalRooms,
userThree: globalRooms,
userFour: globalRooms,
}
app := newApp(users, roomService)
fs := http.FileServer(http.Dir(appClientPath))
http.Handle("/", fs)
http.HandleFunc("/ws", app.CreateSocketHandler)
fmt.Println("http server started on :8089")
err := http.ListenAndServe(":8089", nil)
if err != nil {
fmt.Println("ListenAndServe: ", err)
}
}
func newApp(
users map[string]*socketServer.User,
roomRepo map[*socketServer.User][]socketServer.RoomI,
) *socketServer.App {
roomService := socketServer.NewDefaultRoomService(roomRepo)
userService := socketServer.NewInMemoryUserService(users)
userClientService := socketServer.NewInMemoryUserClientService(nil)
lobby := socketServer.NewRoomLobby(userService, roomService, userClientService)
factory := &socketServer.GorillaWebsocketUpgradeFactory{}
clientService := socketServer.NewDefaultClientService(factory)
return socketServer.NewApp(clientService, lobby)
}