2020-10-16 19:12:53 +02:00
|
|
|
package ws
|
2020-10-09 11:51:06 +02:00
|
|
|
|
|
|
|
import (
|
2020-10-21 21:36:43 +02:00
|
|
|
"encoding/json"
|
2021-03-29 21:54:37 +02:00
|
|
|
"errors"
|
2020-10-09 11:51:06 +02:00
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"sync"
|
2020-11-06 20:11:01 +02:00
|
|
|
"time"
|
2020-10-09 11:51:06 +02:00
|
|
|
|
2020-10-16 11:41:56 +02:00
|
|
|
"github.com/gorilla/mux"
|
2020-10-09 11:51:06 +02:00
|
|
|
"github.com/gorilla/websocket"
|
2021-02-02 22:06:28 +02:00
|
|
|
"github.com/mattermost/focalboard/server/auth"
|
2021-01-27 00:13:46 +02:00
|
|
|
"github.com/mattermost/focalboard/server/model"
|
2021-03-26 20:01:54 +02:00
|
|
|
"github.com/mattermost/focalboard/server/services/store"
|
2020-10-09 11:51:06 +02:00
|
|
|
)
|
|
|
|
|
2021-02-02 22:06:28 +02:00
|
|
|
// IsValidSessionToken authenticates session tokens
|
|
|
|
type IsValidSessionToken func(token string) bool
|
2020-10-09 11:51:06 +02:00
|
|
|
|
2021-05-24 19:06:11 +02:00
|
|
|
type Hub interface {
|
|
|
|
SendWSMessage(data []byte)
|
|
|
|
SetReceiveWSMessage(func(data []byte))
|
|
|
|
}
|
|
|
|
|
2021-02-02 22:06:28 +02:00
|
|
|
// Server is a WebSocket server.
|
|
|
|
type Server struct {
|
2021-05-24 19:06:11 +02:00
|
|
|
upgrader websocket.Upgrader
|
|
|
|
listeners map[string][]*websocket.Conn
|
|
|
|
mu sync.RWMutex
|
|
|
|
auth *auth.Auth
|
|
|
|
hub Hub
|
|
|
|
singleUserToken string
|
|
|
|
isMattermostAuth bool
|
2020-10-09 11:51:06 +02:00
|
|
|
}
|
|
|
|
|
2021-02-02 22:06:28 +02:00
|
|
|
// UpdateMsg is sent on block updates
|
|
|
|
type UpdateMsg struct {
|
|
|
|
Action string `json:"action"`
|
|
|
|
Block model.Block `json:"block"`
|
2020-10-21 21:36:43 +02:00
|
|
|
}
|
|
|
|
|
2021-05-24 19:06:11 +02:00
|
|
|
// clusterUpdateMsg is sent on block updates
|
|
|
|
type clusterUpdateMsg struct {
|
|
|
|
UpdateMsg
|
|
|
|
BlockID string `json:"block_id"`
|
|
|
|
WorkspaceID string `json:"workspace_id"`
|
|
|
|
}
|
|
|
|
|
2021-02-02 23:17:34 +02:00
|
|
|
// ErrorMsg is sent on errors
|
|
|
|
type ErrorMsg struct {
|
|
|
|
Error string `json:"error"`
|
|
|
|
}
|
|
|
|
|
2021-02-02 22:06:28 +02:00
|
|
|
// WebsocketCommand is an incoming command from the client.
|
|
|
|
type WebsocketCommand struct {
|
2021-03-27 03:04:23 +02:00
|
|
|
Action string `json:"action"`
|
|
|
|
WorkspaceID string `json:"workspaceId"`
|
|
|
|
Token string `json:"token"`
|
|
|
|
ReadToken string `json:"readToken"`
|
|
|
|
BlockIDs []string `json:"blockIds"`
|
2020-10-09 11:51:06 +02:00
|
|
|
}
|
|
|
|
|
2021-02-02 22:06:28 +02:00
|
|
|
type websocketSession struct {
|
|
|
|
client *websocket.Conn
|
|
|
|
isAuthenticated bool
|
2021-03-27 03:04:23 +02:00
|
|
|
workspaceID string
|
2020-10-09 11:51:06 +02:00
|
|
|
}
|
|
|
|
|
2020-10-22 15:22:36 +02:00
|
|
|
// NewServer creates a new Server.
|
2021-05-24 19:06:11 +02:00
|
|
|
func NewServer(auth *auth.Auth, singleUserToken string, isMattermostAuth bool) *Server {
|
2020-10-22 13:34:42 +02:00
|
|
|
return &Server{
|
2020-10-09 19:44:12 +02:00
|
|
|
listeners: make(map[string][]*websocket.Conn),
|
2020-10-09 11:51:06 +02:00
|
|
|
upgrader: websocket.Upgrader{
|
|
|
|
CheckOrigin: func(r *http.Request) bool {
|
|
|
|
return true
|
|
|
|
},
|
|
|
|
},
|
2021-05-24 19:06:11 +02:00
|
|
|
auth: auth,
|
|
|
|
singleUserToken: singleUserToken,
|
|
|
|
isMattermostAuth: isMattermostAuth,
|
2020-10-09 11:51:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-02 22:06:28 +02:00
|
|
|
// RegisterRoutes registers routes.
|
|
|
|
func (ws *Server) RegisterRoutes(r *mux.Router) {
|
|
|
|
r.HandleFunc("/ws/onchange", ws.handleWebSocketOnChange)
|
2020-10-21 21:36:43 +02:00
|
|
|
}
|
|
|
|
|
2020-10-22 13:34:42 +02:00
|
|
|
func (ws *Server) handleWebSocketOnChange(w http.ResponseWriter, r *http.Request) {
|
2020-10-09 11:51:06 +02:00
|
|
|
// Upgrade initial GET request to a websocket
|
|
|
|
client, err := ws.upgrader.Upgrade(w, r, nil)
|
|
|
|
if err != nil {
|
2021-03-27 03:04:23 +02:00
|
|
|
log.Printf("ERROR upgrading to websocket: %v", err)
|
|
|
|
return
|
2020-10-09 11:51:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure we close the connection when the function returns
|
|
|
|
defer func() {
|
2020-10-21 21:36:43 +02:00
|
|
|
log.Printf("DISCONNECT WebSocket onChange, client: %s", client.RemoteAddr())
|
2020-10-09 11:51:06 +02:00
|
|
|
|
|
|
|
// Remove client from listeners
|
2021-02-02 22:06:28 +02:00
|
|
|
ws.removeListener(client)
|
2020-10-09 11:51:06 +02:00
|
|
|
|
|
|
|
client.Close()
|
|
|
|
}()
|
|
|
|
|
2021-05-24 19:06:11 +02:00
|
|
|
userID := ""
|
|
|
|
if ws.isMattermostAuth {
|
|
|
|
userID = r.Header.Get("Mattermost-User-Id")
|
|
|
|
}
|
|
|
|
|
2021-02-02 22:06:28 +02:00
|
|
|
wsSession := websocketSession{
|
|
|
|
client: client,
|
2021-05-24 19:06:11 +02:00
|
|
|
isAuthenticated: userID != "",
|
2021-02-02 22:06:28 +02:00
|
|
|
}
|
|
|
|
|
2020-10-09 11:51:06 +02:00
|
|
|
// Simple message handling loop
|
|
|
|
for {
|
2020-10-21 21:36:43 +02:00
|
|
|
_, p, err := client.ReadMessage()
|
2020-10-09 11:51:06 +02:00
|
|
|
if err != nil {
|
2020-10-21 21:36:43 +02:00
|
|
|
log.Printf("ERROR WebSocket onChange, client: %s, err: %v", client.RemoteAddr(), err)
|
2021-02-02 22:06:28 +02:00
|
|
|
ws.removeListener(client)
|
2020-10-22 13:34:42 +02:00
|
|
|
|
2020-10-09 11:51:06 +02:00
|
|
|
break
|
|
|
|
}
|
2020-10-21 21:36:43 +02:00
|
|
|
|
|
|
|
var command WebsocketCommand
|
2020-10-22 15:22:36 +02:00
|
|
|
|
2020-10-21 21:36:43 +02:00
|
|
|
err = json.Unmarshal(p, &command)
|
|
|
|
if err != nil {
|
|
|
|
// handle this error
|
|
|
|
log.Printf(`ERROR webSocket parsing command JSON: %v`, string(p))
|
2020-10-22 13:34:42 +02:00
|
|
|
|
2020-10-21 21:36:43 +02:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2021-05-24 19:06:11 +02:00
|
|
|
if userID != "" {
|
|
|
|
if ws.auth.DoesUserHaveWorkspaceAccess(userID, command.WorkspaceID) {
|
|
|
|
wsSession.workspaceID = command.WorkspaceID
|
|
|
|
} else {
|
|
|
|
log.Printf(`ERROR User doesn't have permissions to read the workspace: %s`, command.WorkspaceID)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-21 21:36:43 +02:00
|
|
|
switch command.Action {
|
2021-02-02 22:06:28 +02:00
|
|
|
case "AUTH":
|
|
|
|
log.Printf(`Command: AUTH, client: %s`, client.RemoteAddr())
|
2021-03-29 21:31:42 +02:00
|
|
|
ws.authenticateListener(&wsSession, command.WorkspaceID, command.Token)
|
2020-10-21 21:36:43 +02:00
|
|
|
case "ADD":
|
2021-03-27 03:04:23 +02:00
|
|
|
log.Printf(`Command: Add workspaceID: %s, blockIDs: %v, client: %s`, wsSession.workspaceID, command.BlockIDs, client.RemoteAddr())
|
2021-02-03 04:15:03 +02:00
|
|
|
ws.addListener(&wsSession, &command)
|
2020-10-21 21:36:43 +02:00
|
|
|
case "REMOVE":
|
2021-03-27 03:04:23 +02:00
|
|
|
log.Printf(`Command: Remove workspaceID: %s, blockID: %v, client: %s`, wsSession.workspaceID, command.BlockIDs, client.RemoteAddr())
|
2021-02-03 04:15:03 +02:00
|
|
|
ws.removeListenerFromBlocks(&wsSession, &command)
|
2020-10-21 21:36:43 +02:00
|
|
|
default:
|
|
|
|
log.Printf(`ERROR webSocket command, invalid action: %v`, command.Action)
|
|
|
|
}
|
2020-10-09 11:51:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-27 03:04:23 +02:00
|
|
|
func (ws *Server) isValidSessionToken(token, workspaceID string) bool {
|
2021-02-09 22:27:34 +02:00
|
|
|
if len(ws.singleUserToken) > 0 {
|
|
|
|
return token == ws.singleUserToken
|
2021-02-02 22:06:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
session, err := ws.auth.GetSession(token)
|
2021-03-27 03:04:23 +02:00
|
|
|
if session == nil || err != nil {
|
|
|
|
return false
|
2021-02-02 22:06:28 +02:00
|
|
|
}
|
|
|
|
|
2021-03-27 03:04:23 +02:00
|
|
|
// Check workspace permission
|
2021-05-24 19:06:11 +02:00
|
|
|
return ws.auth.DoesUserHaveWorkspaceAccess(session.UserID, workspaceID)
|
2021-02-02 22:06:28 +02:00
|
|
|
}
|
|
|
|
|
2021-03-29 21:31:42 +02:00
|
|
|
func (ws *Server) authenticateListener(wsSession *websocketSession, workspaceID, token string) {
|
2021-03-27 03:04:23 +02:00
|
|
|
if wsSession.isAuthenticated {
|
|
|
|
// Do not allow multiple auth calls (for security)
|
|
|
|
log.Printf("authenticateListener: Ignoring already authenticated session")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-02-03 04:15:03 +02:00
|
|
|
// Authenticate session
|
2021-03-27 03:04:23 +02:00
|
|
|
isValidSession := ws.isValidSessionToken(token, workspaceID)
|
2021-02-02 22:06:28 +02:00
|
|
|
if !isValidSession {
|
|
|
|
wsSession.client.Close()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Authenticated
|
2021-03-27 03:04:23 +02:00
|
|
|
|
|
|
|
wsSession.workspaceID = workspaceID
|
2021-02-02 22:06:28 +02:00
|
|
|
wsSession.isAuthenticated = true
|
2021-03-27 03:04:23 +02:00
|
|
|
log.Printf("authenticateListener: Authenticated, workspaceID: %s", workspaceID)
|
2021-02-02 22:06:28 +02:00
|
|
|
}
|
|
|
|
|
2021-03-29 21:54:37 +02:00
|
|
|
func (ws *Server) getAuthenticatedWorkspaceID(wsSession *websocketSession, command *WebsocketCommand) (string, error) {
|
2021-03-29 21:31:42 +02:00
|
|
|
if wsSession.isAuthenticated {
|
2021-03-29 21:54:37 +02:00
|
|
|
return wsSession.workspaceID, nil
|
2021-03-26 20:01:54 +02:00
|
|
|
}
|
|
|
|
|
2021-03-29 21:31:42 +02:00
|
|
|
// If not authenticated, try to authenticate the read token against the supplied workspaceID
|
|
|
|
workspaceID := command.WorkspaceID
|
|
|
|
if len(workspaceID) == 0 {
|
|
|
|
log.Printf("getAuthenticatedWorkspaceID: No workspace")
|
2021-03-29 21:54:37 +02:00
|
|
|
return "", errors.New("No workspace")
|
|
|
|
}
|
|
|
|
|
2021-03-29 21:31:42 +02:00
|
|
|
container := store.Container{
|
|
|
|
WorkspaceID: workspaceID,
|
2021-03-26 20:01:54 +02:00
|
|
|
}
|
|
|
|
|
2021-02-03 04:15:03 +02:00
|
|
|
if len(command.ReadToken) > 0 {
|
|
|
|
// Read token must be valid for all block IDs
|
|
|
|
for _, blockID := range command.BlockIDs {
|
2021-03-26 20:01:54 +02:00
|
|
|
isValid, _ := ws.auth.IsValidReadToken(container, blockID, command.ReadToken)
|
2021-02-03 04:15:03 +02:00
|
|
|
if !isValid {
|
2021-03-29 21:54:37 +02:00
|
|
|
return "", errors.New("Invalid read token for workspace")
|
2021-02-03 04:15:03 +02:00
|
|
|
}
|
|
|
|
}
|
2021-03-29 21:54:37 +02:00
|
|
|
return workspaceID, nil
|
2021-02-03 04:15:03 +02:00
|
|
|
}
|
|
|
|
|
2021-03-29 21:54:37 +02:00
|
|
|
return "", errors.New("No read token")
|
2021-02-03 04:15:03 +02:00
|
|
|
}
|
|
|
|
|
2021-03-27 03:04:23 +02:00
|
|
|
// TODO: Refactor workspace hashing
|
|
|
|
func makeItemID(workspaceID, blockID string) string {
|
|
|
|
return workspaceID + "-" + blockID
|
|
|
|
}
|
|
|
|
|
2021-02-02 23:00:22 +02:00
|
|
|
// addListener adds a listener for a block's change.
|
2021-02-03 04:15:03 +02:00
|
|
|
func (ws *Server) addListener(wsSession *websocketSession, command *WebsocketCommand) {
|
2021-03-29 21:54:37 +02:00
|
|
|
workspaceID, err := ws.getAuthenticatedWorkspaceID(wsSession, command)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("addListener: NOT AUTHENTICATED, ERROR: %v", err)
|
2021-02-02 23:17:34 +02:00
|
|
|
sendError(wsSession.client, "not authenticated")
|
2021-02-02 22:06:28 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ws.mu.Lock()
|
2021-02-03 04:15:03 +02:00
|
|
|
for _, blockID := range command.BlockIDs {
|
2021-03-27 03:04:23 +02:00
|
|
|
itemID := makeItemID(workspaceID, blockID)
|
|
|
|
if ws.listeners[itemID] == nil {
|
|
|
|
ws.listeners[itemID] = []*websocket.Conn{}
|
2021-02-02 22:06:28 +02:00
|
|
|
}
|
|
|
|
|
2021-03-27 03:04:23 +02:00
|
|
|
ws.listeners[itemID] = append(ws.listeners[itemID], wsSession.client)
|
2021-02-02 22:06:28 +02:00
|
|
|
}
|
|
|
|
ws.mu.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
// removeListener removes a webSocket listener from all blocks.
|
|
|
|
func (ws *Server) removeListener(client *websocket.Conn) {
|
|
|
|
ws.mu.Lock()
|
|
|
|
for key, clients := range ws.listeners {
|
|
|
|
listeners := []*websocket.Conn{}
|
|
|
|
|
|
|
|
for _, existingClient := range clients {
|
|
|
|
if client != existingClient {
|
|
|
|
listeners = append(listeners, existingClient)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ws.listeners[key] = listeners
|
|
|
|
}
|
|
|
|
ws.mu.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
// removeListenerFromBlocks removes a webSocket listener from a set of block.
|
2021-02-03 04:15:03 +02:00
|
|
|
func (ws *Server) removeListenerFromBlocks(wsSession *websocketSession, command *WebsocketCommand) {
|
2021-03-29 21:54:37 +02:00
|
|
|
workspaceID, err := ws.getAuthenticatedWorkspaceID(wsSession, command)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("addListener: NOT AUTHENTICATED, ERROR: %v", err)
|
2021-02-02 23:17:34 +02:00
|
|
|
sendError(wsSession.client, "not authenticated")
|
2021-02-02 22:06:28 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-03-27 03:04:23 +02:00
|
|
|
ws.mu.Lock()
|
2021-02-03 04:15:03 +02:00
|
|
|
for _, blockID := range command.BlockIDs {
|
2021-03-27 03:04:23 +02:00
|
|
|
itemID := makeItemID(workspaceID, blockID)
|
|
|
|
listeners := ws.listeners[itemID]
|
2021-02-02 22:06:28 +02:00
|
|
|
if listeners == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the first instance of this client that's listening to this block
|
|
|
|
// Note: A client can listen multiple times to the same block
|
|
|
|
for index, listener := range listeners {
|
|
|
|
if wsSession.client == listener {
|
|
|
|
newListeners := append(listeners[:index], listeners[index+1:]...)
|
2021-03-27 03:04:23 +02:00
|
|
|
ws.listeners[itemID] = newListeners
|
2021-02-02 22:06:28 +02:00
|
|
|
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ws.mu.Unlock()
|
|
|
|
}
|
|
|
|
|
2021-02-02 23:17:34 +02:00
|
|
|
func sendError(conn *websocket.Conn, message string) {
|
|
|
|
errorMsg := ErrorMsg{
|
|
|
|
Error: message,
|
|
|
|
}
|
|
|
|
|
|
|
|
err := conn.WriteJSON(errorMsg)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("sendError error: %v", err)
|
|
|
|
conn.Close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-24 19:06:11 +02:00
|
|
|
func (ws *Server) SetHub(hub Hub) {
|
|
|
|
ws.hub = hub
|
|
|
|
ws.hub.SetReceiveWSMessage(func(data []byte) {
|
|
|
|
var msg clusterUpdateMsg
|
|
|
|
err := json.Unmarshal(data, &msg)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("unable to unmarshal cluster message")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
listeners := ws.getListeners(msg.WorkspaceID, msg.BlockID)
|
|
|
|
log.Printf("%d listener(s) for blockID: %s", len(listeners), msg.BlockID)
|
|
|
|
|
|
|
|
message := UpdateMsg{
|
|
|
|
Action: msg.Action,
|
|
|
|
Block: msg.Block,
|
|
|
|
}
|
|
|
|
|
|
|
|
if listeners != nil {
|
|
|
|
for _, listener := range listeners {
|
|
|
|
log.Printf("Broadcast change, workspaceID: %s, blockID: %s, remoteAddr: %s", msg.WorkspaceID, msg.BlockID, listener.RemoteAddr())
|
|
|
|
|
|
|
|
err := listener.WriteJSON(message)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("broadcast error: %v", err)
|
|
|
|
listener.Close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-02-02 23:00:22 +02:00
|
|
|
// getListeners returns the listeners to a blockID's changes.
|
2021-03-27 03:04:23 +02:00
|
|
|
func (ws *Server) getListeners(workspaceID string, blockID string) []*websocket.Conn {
|
2021-02-02 22:06:28 +02:00
|
|
|
ws.mu.Lock()
|
2021-03-27 03:04:23 +02:00
|
|
|
itemID := makeItemID(workspaceID, blockID)
|
|
|
|
listeners := ws.listeners[itemID]
|
2021-02-02 22:06:28 +02:00
|
|
|
ws.mu.Unlock()
|
|
|
|
|
|
|
|
return listeners
|
|
|
|
}
|
|
|
|
|
2020-11-06 20:11:01 +02:00
|
|
|
// BroadcastBlockDelete broadcasts delete messages to clients
|
2021-03-27 03:04:23 +02:00
|
|
|
func (ws *Server) BroadcastBlockDelete(workspaceID, blockID, parentID string) {
|
2020-11-06 20:11:01 +02:00
|
|
|
now := time.Now().Unix()
|
|
|
|
block := model.Block{}
|
|
|
|
block.ID = blockID
|
|
|
|
block.ParentID = parentID
|
|
|
|
block.UpdateAt = now
|
|
|
|
block.DeleteAt = now
|
|
|
|
|
2021-03-27 03:04:23 +02:00
|
|
|
ws.BroadcastBlockChange(workspaceID, block)
|
2020-11-06 20:11:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// BroadcastBlockChange broadcasts update messages to clients
|
2021-03-27 03:04:23 +02:00
|
|
|
func (ws *Server) BroadcastBlockChange(workspaceID string, block model.Block) {
|
2020-11-06 20:11:01 +02:00
|
|
|
blockIDsToNotify := []string{block.ID, block.ParentID}
|
|
|
|
|
|
|
|
for _, blockID := range blockIDsToNotify {
|
2021-03-27 03:04:23 +02:00
|
|
|
listeners := ws.getListeners(workspaceID, blockID)
|
2020-11-06 20:11:01 +02:00
|
|
|
log.Printf("%d listener(s) for blockID: %s", len(listeners), blockID)
|
|
|
|
|
2021-05-24 19:06:11 +02:00
|
|
|
message := UpdateMsg{
|
|
|
|
Action: "UPDATE_BLOCK",
|
|
|
|
Block: block,
|
|
|
|
}
|
|
|
|
if ws.hub != nil {
|
|
|
|
data, err := json.Marshal(clusterUpdateMsg{UpdateMsg: message, WorkspaceID: workspaceID, BlockID: blockID})
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("unable to serialize websocket message %v with the error: %v", message, err)
|
2020-11-06 20:11:01 +02:00
|
|
|
}
|
2021-05-24 19:06:11 +02:00
|
|
|
ws.hub.SendWSMessage(data)
|
|
|
|
}
|
2020-11-06 20:11:01 +02:00
|
|
|
|
2021-05-24 19:06:11 +02:00
|
|
|
if listeners != nil {
|
2020-11-06 20:11:01 +02:00
|
|
|
for _, listener := range listeners {
|
2021-03-27 03:04:23 +02:00
|
|
|
log.Printf("Broadcast change, workspaceID: %s, blockID: %s, remoteAddr: %s", workspaceID, blockID, listener.RemoteAddr())
|
2020-11-06 20:11:01 +02:00
|
|
|
|
|
|
|
err := listener.WriteJSON(message)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("broadcast error: %v", err)
|
|
|
|
listener.Close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|