@ -180,7 +180,7 @@ func (s *Server) Unicast(c *Connection, to string, m interface{}) {
@@ -180,7 +180,7 @@ func (s *Server) Unicast(c *Connection, to string, m interface{}) {
b := c . h . buffers . New ( )
encoder := json . NewEncoder ( b )
err := encoder . Encode ( & DataOutgoing { From : c . Id , To : to , Data : m } )
err := encoder . Encode ( & DataOutgoing { From : c . Id , To : to , Data : m , A : c . Session . Attestation ( ) } )
if err != nil {
b . Decref ( )
log . Println ( "Unicast error while encoding JSON" , err )
@ -192,6 +192,31 @@ func (s *Server) Unicast(c *Connection, to string, m interface{}) {
@@ -192,6 +192,31 @@ func (s *Server) Unicast(c *Connection, to string, m interface{}) {
b . Decref ( )
}
func ( s * Server ) Broadcast ( c * Connection , m interface { } ) {
b := c . h . buffers . New ( )
encoder := json . NewEncoder ( b )
err := encoder . Encode ( & DataOutgoing { From : c . Id , Data : m , A : c . Session . Attestation ( ) } )
if err != nil {
b . Decref ( )
log . Println ( "Broadcast error while encoding JSON" , err )
return
}
if c . h . isGlobalRoomid ( c . Roomid ) {
c . h . RunForAllRooms ( func ( room * RoomWorker ) {
var msg = & MessageRequest { From : c . Id , Message : b , Id : room . Id }
room . broadcastHandler ( msg )
} )
} else {
var msg = & MessageRequest { From : c . Id , Message : b , Id : c . Roomid }
room := c . h . GetRoom ( c . Roomid )
room . broadcastHandler ( msg )
}
b . Decref ( )
}
func ( s * Server ) Alive ( c * Connection , alive * DataAlive , iid string ) {
c . h . aliveHandler ( c , alive , iid )
@ -217,31 +242,6 @@ func (s *Server) ContactRequest(c *Connection, to string, cr *DataContactRequest
@@ -217,31 +242,6 @@ func (s *Server) ContactRequest(c *Connection, to string, cr *DataContactRequest
}
func ( s * Server ) Broadcast ( c * Connection , m interface { } ) {
b := c . h . buffers . New ( )
encoder := json . NewEncoder ( b )
err := encoder . Encode ( & DataOutgoing { From : c . Id , Data : m } )
if err != nil {
b . Decref ( )
log . Println ( "Broadcast error while encoding JSON" , err )
return
}
if c . h . isGlobalRoomid ( c . Roomid ) {
c . h . RunForAllRooms ( func ( room * RoomWorker ) {
var msg = & MessageRequest { From : c . Id , Message : b , Id : room . Id }
room . broadcastHandler ( msg )
} )
} else {
var msg = & MessageRequest { From : c . Id , Message : b , Id : c . Roomid }
room := c . h . GetRoom ( c . Roomid )
room . broadcastHandler ( msg )
}
b . Decref ( )
}
func ( s * Server ) Users ( c * Connection ) {
room := c . h . GetRoom ( c . Roomid )