Created tests for the Broadcast class as well as created a buffer in incoming remote operations.
Additional changes:
Added a siteId property to the Char object so that the Broadcast class has easy access to it as opposed to looking at the last Identifier in the position array and checking there.
Moved the initialization of PeerJS to outside of the Controller class so that we can now easily test the Controller class using mocks and spies.
Instead of having the peerId and host variables globally available to us, we can pass them into the initialization of Controller and that way they won't conflict with our other variables.
How the Buffer works:
When a remote operation is detected, Broadcast sends it to Controller to be handled.
Controller first checks to see if that operation has already been integrated. If it has, it returns early. If it's a new operation, it broadcasts it out to all of it's peers and it adds it to the end of the buffer. (Lines 40-44)
The Controller then reviews the buffer to integrate all the operations that are ready to be integrated. (Lines 50-65)
Reviewing the buffer involves iterating over all the operations in the buffer (99% of the time it will just be one operation). The first step is a secondary check to see if the operation has already been integrated into the CRDT. This is in case two duplicate operations somehow manage to sneak into the buffer before the VersionVector is updated. If it's a duplicate, it's spliced out. (Lines 56-58)
If the operation is a new operation, it checks to see if that operation is ready to be integrated (inserts are always ready, but deletes have to make sure the char they are deleting already exist). (Lines 86-96).
If the operation is ready to be integrated, it is inserted into the CRDT, the VersionVector is updated, and the editor is updated (the operation is spliced out of buffer after being integrated). (Lines 100-112).
The buffer keeps iterating over all operations until no new operations have been integrated (this is in the case that operations are being received out of order and therefore aren't integrated on the first pass through).
Created tests for the Broadcast class as well as created a buffer in incoming remote operations.
Additional changes:
siteId
property to the Char object so that the Broadcast class has easy access to it as opposed to looking at the last Identifier in the position array and checking there.peerId
andhost
variables globally available to us, we can pass them into the initialization of Controller and that way they won't conflict with our other variables.How the Buffer works: