Documentation ¶
Index ¶
- Constants
- func NewMeshServer(name string, meshconf *MeshServerConfig, rd RoomData) *meshServer
- func NewRoom(roomslug string, clientslug string, rd RoomData, srv *meshServer) *room
- func ServeWs(meshserv *meshServer, w http.ResponseWriter, r *http.Request)
- type MeshServer
- type MeshServerConfig
- type Message
- type Room
- type RoomData
Constants ¶
View Source
const (
MeshGlobalRoom = "mesh-global" //MeshGlobalRoom is a room where a client gets joined when he connects to a websocket . MeshGlobalRoom facilitates creation of rooms
)
Variables ¶
This section is empty.
Functions ¶
func NewMeshServer ¶
func NewMeshServer(name string, meshconf *MeshServerConfig, rd RoomData) *meshServer
NewMeshServer initialize new websocket server
Types ¶
type MeshServer ¶
type MeshServer interface { GetClients() map[string]*client GetClientAuthMetadata(clientslug string) []string GetRooms() []string GetGameName() string GetClientsInRoom() map[string]map[string]*client DeleteRoom(name string) JoinClientRoom(roomname string, clientname string, rd RoomData) RemoveClientRoom(roomname string, clientname string) //PushMessage is to push message from the code not from the UI thats broadcast //returns a send only channel PushMessage() chan<- *Message //ReceiveMessage is to receive message from readpumps of the clients this can be used to manipulate //returns a receive only channel RecieveMessage() <-chan *Message //EventTriggers Track //Get the updates on the clients in room changes and act accordingly //Returns receive only channel []string length of 3 [0]-->event type [1]-->roomname [1]-->clientslug //event types :- client-joined-room , client-left-room EventTriggers() <-chan []string }
type MeshServerConfig ¶
type MeshServerConfig struct {
DirectBroadCast bool
}
type Message ¶
type Message struct { Action string `json:"action"` //action MessageBody map[string]interface{} `json:"message_body"` //message IsTargetClient bool //not imported if its true then the Target string is a client which is one Target string `json:"target"` //target the room Sender string `json:"sender"` //whose readpump is used }
Message struct is the structure of the message which is send in mesh server
type Room ¶
type Room interface { GetRoomSlugInfo() string GetRoomMakerInfo() string GetAuthMetadata() []string // This is to indicate that there are no clients in the room to send the message // If there are no clients in the room the room gets deleted from the map and this channel is closed. // The HandleRoomData go routine will be closed if implemented. RoomStopped() <-chan struct{} //ConsumeRoomMessage receives the messages it gets directly from the clients. ConsumeRoomMessage() <-chan *Message //This are the events such as client-joined-room,client-left-room . //Consist of list of 3 values :- [event,roomname,clientid] EventTriggers() <-chan []string //BroadcastMessage pushes the message to all the clients in the room . //Use IsTargetClient to true if you have to send the message to a particular client of the room . BroadcastMessage(message *Message) }
type RoomData ¶
type RoomData interface { //HandleRoomData use your struct which has all the data related to room and do the changes accordingly HandleRoomData(room Room, server MeshServer) }
Click to show internal directories.
Click to hide internal directories.