arlolra/otr — pull request #17 by Hainish (2012-08-20 08:58:31+00:00)
Title: Changes for msg fragments

Some of these are higher level api changes. This is my solution to the problems I encountered when I reworked the msg fragment tests. Please feel free to take any parts you like.

I noticed that the tests were finishing before any messages were sent for message fragments. This is because we're now using callbacks and mocha tests aren't async unless you specify you want them to be. Our sendQueryMsg as well as sendMsg was returning before these callbacks were run. So userB was sending messages immediately, before the AKE was finished. This wasn't a problem before, since our call to sendQueryMsg wasn't returned until the AKE was completely finished.
To solve this problem I made OTR inherit EventEmitter, and have userB only send messages when the ake is finished with emit('encrypted')

The sendMsg also needed to have either callbacks or emitted events, since they can no longer be blocking using fragments. I went with callbacks, but this may be stylistically undesirable.

sendMsg and sendQueryMsg still work as blocking calls for otr not fragments and therefore do not require these callbacks and emits.