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() { function init() {
if (!textsecure.registration.isDone()) { return; } 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('message', onMessageReceived);
window.addEventListener('receipt', onDeliveryReceipt);
window.addEventListener('contact', onContactReceived);
window.addEventListener('group', onGroupReceived); window.addEventListener('group', onGroupReceived);
window.addEventListener('sent', onSentMessage); window.addEventListener('sent', onSentMessage);
window.addEventListener('error', onError); window.addEventListener('error', onError);
messageReceiver.connect(); // initialize the socket and start listening for messages
messageReceiver = new textsecure.MessageReceiver(window);
} }
function onContactReceived(contactInfo) { function onContactReceived(contactInfo) {

View file

@ -39469,6 +39469,7 @@ function generateKeys(count, progressCallback) {
} else { } else {
throw new TypeError('MessageReceiver expected an EventTarget'); throw new TypeError('MessageReceiver expected an EventTarget');
} }
this.connect();
} }
MessageReceiver.prototype = { 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 { } else {
throw new TypeError('MessageReceiver expected an EventTarget'); throw new TypeError('MessageReceiver expected an EventTarget');
} }
this.connect();
} }
MessageReceiver.prototype = { 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
};
}()); }());