2019-02-06 23:38:12 +00:00
|
|
|
let Messages = {};
|
|
|
|
|
|
|
|
Messages.Providers = {};
|
|
|
|
|
|
|
|
Messages.registerProvider = function (providerName, obj) {
|
|
|
|
this.Providers[providerName] = obj;
|
|
|
|
};
|
|
|
|
|
|
|
|
Messages.setProvider = function (providerName, options) {
|
|
|
|
let provider = this.Providers[providerName];
|
|
|
|
|
|
|
|
if (!provider) {
|
|
|
|
throw new Error('Unknown messages provider');
|
|
|
|
}
|
|
|
|
|
|
|
|
this.currentProviderName = providerName;
|
|
|
|
this.currentMessages = provider;
|
|
|
|
|
|
|
|
return provider.setProvider(options);
|
|
|
|
};
|
|
|
|
|
|
|
|
Messages.isAvailable = function () {
|
|
|
|
if (!this.currentMessages) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return this.currentMessages.isAvailable();
|
|
|
|
};
|
|
|
|
|
|
|
|
Messages.sendMessage = function (options) {
|
|
|
|
if (!this.currentMessages) {
|
|
|
|
throw new Error('Messages provider not set; e.g EmbarkJS.Messages.setProvider("whisper")');
|
|
|
|
}
|
|
|
|
return this.currentMessages.sendMessage(options);
|
|
|
|
};
|
|
|
|
|
2019-02-11 06:08:01 +00:00
|
|
|
Messages.listenTo = function (options) {
|
2019-02-06 23:38:12 +00:00
|
|
|
if (!this.currentMessages) {
|
|
|
|
throw new Error('Messages provider not set; e.g EmbarkJS.Messages.setProvider("whisper")');
|
|
|
|
}
|
2019-02-11 06:08:01 +00:00
|
|
|
return this.currentMessages.listenTo(options);
|
2019-02-06 23:38:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Messages;
|