mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-14 08:34:32 +00:00
Merge pull request #1639 from sharelatex/bg-add-message-ids
include a unique id in every message published to redis GitOrigin-RevId: f2843e5bb570247f03b260fa0f82f562c9c6014d
This commit is contained in:
parent
494f749e72
commit
0305ba0c6b
2 changed files with 13 additions and 0 deletions
|
@ -1,13 +1,22 @@
|
|||
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...
|
||||
|
|
|
@ -12,6 +12,8 @@ describe "EditorRealTimeController", ->
|
|||
client: () => @rclient
|
||||
"../../infrastructure/Server" : io: @io = {}
|
||||
"settings-sharelatex":{redis:{}}
|
||||
"crypto": @crypto = { randomBytes: sinon.stub().withArgs(4).returns(Buffer.from([0x1, 0x2, 0x3, 0x4])) }
|
||||
"os": @os = {hostname: sinon.stub().returns("somehost")}
|
||||
|
||||
@room_id = "room-id"
|
||||
@message = "message-to-editor"
|
||||
|
@ -19,6 +21,7 @@ describe "EditorRealTimeController", ->
|
|||
|
||||
describe "emitToRoom", ->
|
||||
beforeEach ->
|
||||
@message_id = "web:somehost:01020304-0"
|
||||
@EditorRealTimeController.emitToRoom(@room_id, @message, @payload...)
|
||||
|
||||
it "should publish the message to redis", ->
|
||||
|
@ -27,6 +30,7 @@ describe "EditorRealTimeController", ->
|
|||
room_id: @room_id,
|
||||
message: @message
|
||||
payload: @payload
|
||||
_id: @message_id
|
||||
))
|
||||
.should.equal true
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue