mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-14 20:40:17 -05:00
0305ba0c6b
include a unique id in every message published to redis GitOrigin-RevId: f2843e5bb570247f03b260fa0f82f562c9c6014d
23 lines
699 B
CoffeeScript
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...
|
|
|