goog.provide('spv.ds.DsClientSettings');
goog.provide('spv.ds.DsClientValidatedSettings');
/**
* @export
* @constructor
*/
spv.ds.DsClientSettings = function()
{
/**
* @type {?boolean}
* @nocollapse
*/
this.use_jsonp = null;
/**
* @type {?boolean}
* @nocollapse
*/
this.use_nova_protocol = null;
/**
* @type {?boolean}
* @nocollapse
*/
this.debug_print = null;
/**
* A callback to notify whenever the protocol issues an Unauthorized Session
* error. The error will pass to the call-specific error callback if this
* field is null.
* @type {?function( Error )}
* @nocollapse
*/
this.on_unauthorized_session = null;
/**
* A function that is called if the backend service cannot be reached.
* @type {?function( Error )}
* @nocollapse
*/
this.on_service_unavailable = null;
/**
* A function that is called if the backend service generates unexpected errors.
* @type {?function( Error )}
* @nocollapse
*/
this.on_service_failure = null;
/**
* Session Time To Live in seconds.
* Introduced to cleanup test session resources.
*
* 0 --> use server default.
*
* @type {number}
* @nocollapse
*/
this.session_ttl = 0;
/**
* Origin is used to track the outer client URL, the URL to the
* embedding page. The name is admittedly vague but it is the name used
* by the server side code.
*
* @type {?string}
* @nocollapse
*/
this.origin = null;
/**
* The initial value of a session's category.
*
* @type {?string}
* @nocollapse
*/
this.initial_category = null;
};
/**
* Creates new settings by overloading these settings with another set of
* settings. Null properties are left untouched, but defined properties are
* taken from the argument settings.
*
* @export
* @param {!spv.ds.DsClientSettings} other
* @return {!spv.ds.DsClientSettings}
*/
spv.ds.DsClientSettings.prototype.overloadWith = function( other )
{
var new_settings = new spv.ds.DsClientSettings();
new_settings.use_jsonp =
(other.use_jsonp !== null) ?
other.use_jsonp : this.use_jsonp;
new_settings.use_nova_protocol =
(other.use_nova_protocol !== null) ?
other.use_nova_protocol : this.use_nova_protocol;
new_settings.debug_print =
(other.debug_print !== null) ?
other.debug_print : this.debug_print;
new_settings.on_unauthorized_session =
(other.on_unauthorized_session !== null) ?
other.on_unauthorized_session : this.on_unauthorized_session;
new_settings.on_service_unavailable =
(other.on_service_unavailable !== null) ?
other.on_service_unavailable : this.on_service_unavailable;
new_settings.on_service_failure =
(other.on_service_failure !== null) ?
other.on_service_failure : this.on_service_failure;
new_settings.session_ttl = other.session_ttl;
new_settings.origin =
(other.origin !== null) ?
other.origin : this.origin;
new_settings.origin = other.origin;
new_settings.initial_category =
(other.initial_category !== null) ?
other.initial_category : this.initial_category;
return new_settings;
};
/**
* @export
*/
spv.ds.DsClientSettings.prototype.assert_valid = function()
{
var error_msg = "Invalid DsClientSettings: ";
if( typeof(this.use_jsonp) != "boolean" )
throw new Error( error_msg + "use_jsonp not set." );
if( typeof(this.debug_print) != "boolean" )
throw new Error( error_msg + "debug_print not set." );
if( typeof(this.session_ttl) != "number" )
throw new Error( error_msg + "session_ttl not set." );
};
/**
* @export
* @return {!string}
*/
spv.ds.DsClientSettings.prototype.toString = function()
{
return "DsClientSettings{ use_jsonp : " + this.use_jsonp +
"; use_nova_protocol : " + this.use_nova_protocol +
"; debug_print : " + this.debug_print +
"}";
}
/**
* Internal type for validation of settings.
* @constructor
* @param {spv.ds.DsClientSettings} settings
*/
spv.ds.DsClientValidatedSettings = function( settings )
{
settings.assert_valid();
/**
* @type {boolean}
*/
this.use_jsonp = settings.use_jsonp === true;
/**
* @type {boolean}
*/
this.use_nova_protocol = settings.use_nova_protocol === true;
/**
* @type {boolean}
*/
this.debug_print = settings.debug_print === true;
/**
* @type {?function(Error)}
*/
this.on_unauthorized_session = settings.on_unauthorized_session;
/**
* @type {?function(Error)}
*/
this.on_service_unavailable = settings.on_service_unavailable;
/**
* @type {?function(Error)}
*/
this.on_service_failure = settings.on_service_failure;
/**
* @type {number}
*/
this.session_ttl = settings.session_ttl;
/**
* @type {string}
*/
this.origin = !!settings.origin ? settings.origin : "";
/**
* @type {string}
*/
this.initial_category = !!settings.initial_category ? settings.initial_category : "";
};