The isLoading variable was only an attempt to solve the problem, by testing for it in the handler to see if it should ignore the event, (so setting it to false there is besides the point)
I will try digging through the Blockly code to find an answer. Perhaps a hook can be added by overriding a method somewhere, or something.
Another hack I've thought of is to ignore the first n change events after loading. But this could easily change between blockly versions, and without thorough testing, could not be relied upon to even be constant within a given version.
Your suggestion would have the same effect as the other two ways, ie:
- removing the handler while loading the XML (I only provide one to the workspace) or
- using the isLoading flag which makes the handler return when it is called
All three ways rely on the code knowing when the change events firing as a result of domToWorkspace have completed. (I seem to consistently see 4 fired each time, but not sure I should always rely on exactly 4).
The way my web app works: multiple users can be working on the same workspace simultaneously, real-time. When one user drags a block and releases it, the change event fires on his workspace, the client sends the update to the server and it's broadcast to all clients viewing that workspace. Each of those clients update what their user is seeing by calling clear(), xmlToDom() and domToWorkspace(). But without more code, this enters in an infinite loop between clients and server, since when XML is loaded to a workspace, it triggers the workspace change handler several times.
I've got it working by wrapping the code that re-enables the workspace event handler in a setTimeout of 500ms but it obviously won't work if someone has a slow device/browser
slaveWorkspace.addChangeListener(function(){
console.log("Doh!");
});
Hi Jody,Excited to see people playing around with collaboration. We've been discussing it on and off ourselves for at least a year but haven't had the time to implement it ourselves. There's also a lot of subtle complexity to the problem which we tried to design for in the implementation of events, but I'm sure there are some pieces missing.Neil's doc from last year provided a good summary of the design we had in mind. There's two main areas that still need investigation and significant work based on that design.
- We currently don't distinguish events generated by the user and generated by an incoming event stream. There's differences in the events themselves, such as events from another instance won't have a workspace id or old values. But we probably need a slightly different code path for events that aren't user generated, and it'd take some work to find all the ways they should differ. The fact that sometimes new events get fired that weren't part of the incoming stream is one example where we get this wrong.
- A lot of work needs to be done around rewinding and replaying your local events in the order specified by the server. Our intention was to ignore events from the server during a user interaction to keep the UI from jumping around while dragging a block (for instance), but this means after the user interaction finishes we need to push our changes to the server and receive an update from the server with the events we just generated, then rewind them and apply in the order the server recorded.
We've also discussed having an end group event, but don't think it's necessary. Groups are almost always created by a single user action, and the simple way to batch them is to wait for the user interaction to finish before sending events to the server (which should succeed or fail as a group). This should also solve your problem of when to send a group of events.Regarding your approach of serializing the entire workspace, how do you resolve conflicts? It seems like if two people were working at the same time they would be clobbering each other's work fairly frequently.
--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Blockly.Events.disable()
Blockly.Xml.domToWorkspace(xml, workspace);
Blockly.Events.enable();
Erik - I have not found a solution as such. In fact, I haven't even tried any of it with anyone else yet so I don't know how well it would really work.
I am probably being naive, but...
I probably am building this initially just for my son-in-law and myself to collaborate while on the phone, so clobbering would have to be accepted unless both him and I can communicate about taking turns; something both of us need practice at anyway.
Saying that, I may be wrong but don't think it would be much of a problem with both of us moving blocks - I hope clobbering would be easy to spot and quick to fix. But when working on text, with fast, continuous typing I can see it getting extremely frustrating. To keep it simple I may either resort to enforced turn taking, or showing multiple workspaces on screen; one per active user, with all but one being read-only.
Jody
--
You received this message because you are subscribed to a topic in the Google Groups "Blockly" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/blockly/4ixCVy15sXc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to blockly+unsubscribe@googlegroups.com.
Blockly.Events.enable();
This is working for me as well. Thank you!
--
You received this message because you are subscribed to a topic in the Google Groups "Blockly" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/blockly/4ixCVy15sXc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to blockly+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.