Wrap message receiver for minimum api exposure

Initializing a message receiver opens the socket and starts listening
right away rather than requiring a separate call to connect. The only
other publicly accessible method is to query the socket status.

// FREEBIE
This commit is contained in:
lilia 2015-06-17 11:30:29 -07:00
parent 18433419c9
commit b0603bc91a
3 changed files with 24 additions and 7 deletions

View file

@ -43,15 +43,14 @@
function init() {
if (!textsecure.registration.isDone()) { return; }
// initialize the socket and start listening for messages
messageReceiver = new textsecure.MessageReceiver(window);
window.addEventListener('contact', onContactReceived);
window.addEventListener('receipt', onDeliveryReceipt);
window.addEventListener('message', onMessageReceived);
window.addEventListener('receipt', onDeliveryReceipt);
window.addEventListener('contact', onContactReceived);
window.addEventListener('group', onGroupReceived);
window.addEventListener('sent', onSentMessage);
window.addEventListener('error', onError);
messageReceiver.connect();
// initialize the socket and start listening for messages
messageReceiver = new textsecure.MessageReceiver(window);
}
function onContactReceived(contactInfo) {

View file

@ -39469,6 +39469,7 @@ function generateKeys(count, progressCallback) {
} else {
throw new TypeError('MessageReceiver expected an EventTarget');
}
this.connect();
}
MessageReceiver.prototype = {
@ -39624,8 +39625,16 @@ function generateKeys(count, progressCallback) {
}
};
textsecure.MessageReceiver = MessageReceiver;
textsecure.MessageReceiver = function (eventTarget) {
var messageReceiver = new MessageReceiver(eventTarget);
this.getStatus = function() {
return messageReceiver.getStatus();
}
}
textsecure.MessageReceiver.prototype = {
constructor: textsecure.MessageReceiver
};
}());

View file

@ -24,6 +24,7 @@
} else {
throw new TypeError('MessageReceiver expected an EventTarget');
}
this.connect();
}
MessageReceiver.prototype = {
@ -179,7 +180,15 @@
}
};
textsecure.MessageReceiver = MessageReceiver;
textsecure.MessageReceiver = function (eventTarget) {
var messageReceiver = new MessageReceiver(eventTarget);
this.getStatus = function() {
return messageReceiver.getStatus();
}
}
textsecure.MessageReceiver.prototype = {
constructor: textsecure.MessageReceiver
};
}());