-
Notifications
You must be signed in to change notification settings - Fork 851
Extending TowTruck
This page documents some of the ways you can customize the TowTruck experience on your site. Especially how you can extend TowTruck to synchronize parts of your application that require special treatment.
Yeah, we're still working on it. We're using the extending label to categorize tickets related to this.
You can run this to try to reinitialize anything TowTruck initializes on page load. In particular you can use it if there are new textareas or code editors that should be sync'd, but were added dynamically to the page. E.g.:
$("#form").append("<textarea>");
TowTruck.reinitialize();
(We hope with #70 that this will no longer be necessary.)
You can still get at TowTruck, even if you can't rely on the internals not to change underneath you. (You would be well recommended to deploy your own copy of the client if you do this stuff.)
Most of the TowTruck features are implemented as individual modules, so it should be possible to introduce your own module to do many of the same things. The most important thing is the session
module, and sending and receiving messages.
To get the session module (or any module) you can run this after TowTruck starts:
var session = TowTruck.require("session");
This assumes that the module has already been loaded... but that assumption would be correct once TowTruck has started.
Then there are two interesting methods:
session.send({type: "my-custom-type", attr: value});
session.hub.on("my-custom-type", function (msg) {
alert(msg.value);
});
I.e., session.send()
and session.hub.on()
. As you can see the messages are dispatched based on msg.type
. These messages are broadcasted to all other participants. Note that the messages are always sent, even if the other person is at a different URL. To check if an incoming message comes from a person on the same page as you, check msg.sameUrl
(msg.url
shows the actual URL of the other person).
Check in on #393