parent
1cd490b04a
commit
18465c61f5
27
chatroom.go
27
chatroom.go
|
@ -39,7 +39,7 @@ type ChatRoom struct {
|
||||||
//initializing the chatroom
|
//initializing the chatroom
|
||||||
func newChatRoom() (*ChatRoom, error) {
|
func newChatRoom() (*ChatRoom, error) {
|
||||||
cr := &ChatRoom{
|
cr := &ChatRoom{
|
||||||
queue: make(chan string, 5),
|
queue: make(chan string, 100),
|
||||||
clients: make(map[string]*Client),
|
clients: make(map[string]*Client),
|
||||||
tempConn: make(map[string]*websocket.Conn),
|
tempConn: make(map[string]*websocket.Conn),
|
||||||
}
|
}
|
||||||
|
@ -349,22 +349,27 @@ func (cr *ChatRoom) UserCount() int {
|
||||||
|
|
||||||
//broadcasting all the messages in the queue in one block
|
//broadcasting all the messages in the queue in one block
|
||||||
func (cr *ChatRoom) BroadCast() {
|
func (cr *ChatRoom) BroadCast() {
|
||||||
msgBlock := ""
|
var msgs []string
|
||||||
infLoop:
|
|
||||||
for {
|
for {
|
||||||
|
leave := false
|
||||||
select {
|
select {
|
||||||
case m := <-cr.queue:
|
case m := <-cr.queue:
|
||||||
msgBlock += m
|
msgs = append(msgs, m)
|
||||||
default:
|
default:
|
||||||
break infLoop
|
leave = true
|
||||||
|
}
|
||||||
|
if leave {
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(msgBlock) > 0 {
|
for _, msg := range msgs {
|
||||||
for _, client := range cr.clients {
|
if len(msg) > 0 {
|
||||||
client.Send(msgBlock)
|
for _, client := range cr.clients {
|
||||||
}
|
client.Send(msg)
|
||||||
for _, conn := range cr.tempConn {
|
}
|
||||||
connSend(msgBlock, conn)
|
for _, conn := range cr.tempConn {
|
||||||
|
connSend(msg, conn)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue