/**
 * @class
 * unotify
 */
class unotify{
	static async getCid(successCallback, errorCallback){
		var a = null;
		try{
			a = await this.getCidPeriotic(3);
			if(typeof successCallback == 'function'){
				successCallback(a);
			}
		}
		catch (err){
			console.log(err);
			if(typeof errorCallback == 'function'){
				errorCallback(a);
			}
		}
	}
	static getCidPeriotic(times){
		var self = this;
		return new Promise(function(resolve, reject){
			var i = 0;
			var cid = null;
			var handle = null;
			i++;
			cid = self.getCidOnce(i);
			if(cid != null || i >= times){
				window.clearInterval(handle);
				resolve(cid);
			}else{
				handle = setInterval(function(){
					i++;
					cid = self.getCidOnce(i);
					if(cid != null || i >= times){
						window.clearInterval(handle);
						resolve(cid);
					}
				},1000);
			}
		});
	}
	static getCidOnce(i){
		var clientInfo = plus.push.getClientInfo();
		if(clientInfo && clientInfo.hasOwnProperty('clientid') && clientInfo.clientid){
			return(clientInfo.clientid);
		}else{
			return(null);
		}
	}
}
export default unotify;