We deliver content for different devices - web, smart tv, tablet and mobile - and I'm trying to provide a common JavaScript interface providing functions like play stream, alert, log etc without thinking of how the device actually do this.
My question is: Is there a way to provide this like an interface, that the Device could implement and ensure that all implementations follows this interface signature?
Example of implementation of typical functions against web browser on pc:
$.extend({
Device : function() {
this.play = function(url){
console.log("Play: " + url);
}
this.alert = function(title, message, buttonText) {
alert(title + "\n" + message);
}
this.log = function(message){
console.log(message);
}
this.error = function(message){
console.error(message);
}
}
});
The same functions against against samsung tv
$.extend({
Device : function() {
var that = this;
var TV = new $.TV();
TV.init();
this.play = function(url){
TV.play(url);
that.log("Play: " + url);
}
this.alert = function(title, message, buttonText) {
alert(title + "\n" + message);
}
this.log = function(message){
//no console on tv, so have to include on in the html
$("#console").append('<div class="console-log">' + message + '</div>');
if($("#console").children().size()>=5){
$("#console").children().first().remove();
}
}
this.error = function(message){
$("#console").append('<div class="console-error">' + message + '</div>');
if($("#console").children().size()>=5){
$("#console").children().first().remove();
}
}
}
});