overleaf/services/web/app/coffee/Features/Editor/EditorRealTimeController.coffee
Brian Gough 0305ba0c6b Merge pull request #1639 from sharelatex/bg-add-message-ids
include a unique id in every message published to redis

GitOrigin-RevId: f2843e5bb570247f03b260fa0f82f562c9c6014d
2019-03-21 16:17:37 +00:00

23 lines
699 B
CoffeeScript

Settings = require 'settings-sharelatex'
RedisWrapper = require("../../infrastructure/RedisWrapper")
rclient = RedisWrapper.client("realtime")
os = require "os"
crypto = require "crypto"
HOST = os.hostname()
RND = crypto.randomBytes(4).toString('hex') # generate a random key for this process
COUNT = 0
module.exports = EditorRealTimeController =
emitToRoom: (room_id, message, payload...) ->
# create a unique message id using a counter
message_id = "web:#{HOST}:#{RND}-#{COUNT++}"
rclient.publish "editor-events", JSON.stringify
room_id: room_id
message: message
payload: payload
_id: message_id
emitToAll: (message, payload...) ->
@emitToRoom "all", message, payload...