
//------------------------------- Get property-----------------------------------------------------------
hcap.property.getProperty({
 "key" : "model_name",
 "onSuccess" : function(s) {
		console.log("onSuccess : property value = " + s.value);

 }, 
 "onFailure" : function(f) {
		console.log("onFailure : errorMessage = " + f.errorMessage);
 }

});

hcap.property.getProperty({
 "key" : "tv_name",
 "onSuccess" : function(s) {
		console.log("onSuccess : property value = " + s.value);

 }, 
 "onFailure" : function(f) {
		console.log("onFailure : errorMessage = " + f.errorMessage);
 }

});

hcap.property.getProperty({
 "key" : "serial_number",
 "onSuccess" : function(s) {
		console.log("onSuccess : property value = " + s.value);

 }, 
 "onFailure" : function(f) {
		console.log("onFailure : errorMessage = " + f.errorMessage);
 }

});


//------------------------------- Set property-----------------------------------------------------------
hcap.property.setProperty({
 "key" : "tv_name",
 "value" : "Lemco_1",
 "onSuccess" : function(s) {
		console.log("onSuccess");

 }, 
 "onFailure" : function(f) {
		console.log("onFailure : errorMessage = " + f.errorMessage);
 }

});


hcap.property.setProperty({
 "key" : "tv_volume_ui",
 "value" : "1",
 "onSuccess" : function(s) {
		console.log("onSuccess");
		

 }, 
 "onFailure" : function(f) {
		console.log("onFailure : errorMessage = " + f.errorMessage);
 }

});


//------------------------------- Set Start channel-----------------------------------------------------------
param = {
	"channelType": 99,
	"url" : "https://cph-p2p-msl.akamaized.net/hls/live/2000341/test/master.m3u8",
	"onSuccess" : function() {
		//console.log("onSuccess");
	}, 
	"onFailure" : function(f) {
		//console.log("onFailure : errorMessage = " + f.errorMessage);
	}
};

hcap.channel.setStartChannel(param);


//------------------------------- Get current channel-----------------------------------------------------------

hcap.channel.getCurrentChannel({
	 "onSuccess" : function(s) {
		 console.log(s);
	 }, 
	 "onFailure" : function(f) {
		 console.log("onFailure : errorMessage = " + f.errorMessage);
	 }
});


//------------------------------- Get network-----------------------------------------------------------
hcap.network.getNumberOfNetworkDevices({
	 "onSuccess" : function(s) {
		 console.log("onSuccess : the number of network devices = " + s.count);
		 
		 logElem = document.querySelector("#demo_div");
		 logElem.innerHTML += "<br/>network devices = " + s.count + "<br/>";
		 
		 logElem.innerHTML += "<br/>network devices = " + hcap.network.NetworkMode.WIRE + "<br/>";
		 logElem.innerHTML += "<br/>network devices = " + hcap.network.NetworkMode.WIRELESS + "<br/>";

	 }, 
	 "onFailure" : function(f) {
		 console.log("onFailure : errorMessage = " + f.errorMessage);
	 }
});

hcap.network.getNetworkDevice({
	 "index" : 0,
	 "onSuccess" : function(r) {
		 console.log("onSuccess : networkMode = " + r.networkMode + 
			 "\n name = " + r.name +
			 "\n mac = " + r.mac +
			 "\n dhcp = " + r.dhcp +
			 "\n ip = " + r.ip +
			 "\n gateway = " + r.gateway +
			 "\n netmask = " + r.netmask +
			 "\n primary dns = " + r.primaryDns +
			 "\n secondary dns = " + r.secondaryDns);

	 }, 
	 "onFailure" : function(r) {
		 console.log("onFailure : errorMessage = " + r.errorMessage);
	 }
 });
 
 hcap.network.getNetworkDevice({
	 "index" : 1,
	 "onSuccess" : function(r) {
		 console.log("onSuccess : networkMode = " + r.networkMode + 
			 "\n name = " + r.name +
			 "\n mac = " + r.mac +
			 "\n dhcp = " + r.dhcp +
			 "\n ip = " + r.ip +
			 "\n gateway = " + r.gateway +
			 "\n netmask = " + r.netmask +
			 "\n primary dns = " + r.primaryDns +
			 "\n secondary dns = " + r.secondaryDns);

	 }, 
	 "onFailure" : function(r) {
		 console.log("onFailure : errorMessage = " + r.errorMessage);
	 }
 });
 
 
 
hcap.network.getNetworkInformation({
	 "onSuccess" : function(s) {
		 console.log("onSuccess : network_mode = " + s.network_mode + 
			 "\n ssid = " + s.ssid +
			 "\n eth_speed = " + s.eth_speed +
			 "\n eth_duplex = " + s.eth_duplex +
			 "\n local_network_available = " + s.local_network_available +
			 "\n internet_available = " + s.internet_available +
			 "\n wifi_mode = " + s.wifi_mode +
			 "\n wireless_security_type = " + s.wireless_security_type +
			 "\n wifi_pass_key = " + s.wifi_pass_key +
			 "\n using_dhcp = " + s.using_dhcp +
			 "\n ip_address = " + s.ip_address +
			 "\n subnet_mask = " + s.subnet_mask +
			 "\n gateway = " + s.gateway +
			 "\n dns1_address = " + s.dns1_address +
			 "\n dns2_address = " + s.dns2_address +
			 "\n dns_dhcp = " + s.dns_dhcp +
			 "\n ethernet_plugged = " + s.ethernet_plugged +
			 "\n wifi_plugged = " + s.wifi_plugged +
			 "\n dhcp_state = " + s.dhcp_state);
	 }, 
	 "onFailure" : function(f) {
		 console.log("onFailure : errorMessage = " + f.errorMessage);
	 }
});


//------------------------------- Get Power Mode-----------------------------------------------------------
hcap.power.getPowerMode({
	 "onSuccess" : function(s) {
		 console.log("onSuccess power mode " + s.mode);
	 }, 
	 "onFailure" : function(f) {
		 console.log("onFailure : errorMessage = " + f.errorMessage);
	 }
});


//------------------------------- Reboot-----------------------------------------------------------
hcap.power.reboot({
	 "onSuccess" : function() {
		 console.log("onSuccess");
	 }, 
	 "onFailure" : function(f) {
		 console.log("onFailure : errorMessage = " + f.errorMessage);
	 }
});


//------------------------------- Power off-----------------------------------------------------------
hcap.power.powerOff({
	 "onSuccess" : function() {
		 console.log("onSuccess");
	 }, 
	 "onFailure" : function(f) {
		 console.log("onFailure : errorMessage = " + f.errorMessage);
	 }
});




//------------------------------- Set mouse pointer-----------------------------------------------------------
hcap.mouse.setPointerOn({
	"isOn" : true,
	 "onSuccess" : function() {
		 console.log("onSuccess");
	 }, 
	 "onFailure" : function(f) {
		 console.log("onFailure : errorMessage = " + f.errorMessage);
	 }
});


//------------------------------- Set localtime-----------------------------------------------------------
hcap.time.setLocalTime({
	 "year" : 2010, 
	 "month" : 8,
	 "day" : 31,
	 "hour" : 1,
	 "minute" : 0,
	 "second" : 0,
	 "timezone" : "Europe/Athens",
	 "set_ntp" : true,
	 "onSuccess" : function() {
		 console.log("onSuccess");
	 }, 
	 "onFailure" : function(f) {
		 console.log("onFailure : errorMessage = " + f.errorMessage);
	 }
});


//------------------------------- Enable debug mode (restart needed)-----------------------------------------------------------
//--------------------------------Disable debug before release to customer-----------------------------------------------------
hcap.system.setBrowserDebugMode({
	 "debugMode" : true,
	 "onSuccess" : function() {
		 console.log("onSuccess");
	 },
	 "onFailure" : function(f) {
		 console.log("onFailure : errorMessage = " + f.errorMessage);
	 }
});

//------------------------------------Read date (javascript code)-------------------------------------------------
var objToday = new Date(),
weekday = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'),
dayOfWeek = weekday[objToday.getDay()],
domEnder = function() { var a = objToday; if (/1/.test(parseInt((a + "").charAt(0)))) return "th"; a = parseInt((a + "").charAt(1)); return 1 == a ? "st" : 2 == a ? "nd" : 3 == a ? "rd" : "th" }(),
dayOfMonth = today + ( objToday.getDate() < 10) ? '0' + objToday.getDate() + domEnder : objToday.getDate() + domEnder,
months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'),
curMonth = months[objToday.getMonth()],
curYear = objToday.getFullYear(),
curHour = objToday.getHours() > 12 ? objToday.getHours() - 12 : (objToday.getHours() < 10 ? "0" + objToday.getHours() : objToday.getHours()),
curMinute = objToday.getMinutes() < 10 ? "0" + objToday.getMinutes() : objToday.getMinutes(),
curSeconds = objToday.getSeconds() < 10 ? "0" + objToday.getSeconds() : objToday.getSeconds(),
curMeridiem = objToday.getHours() > 12 ? "PM" : "AM";

var today = curHour + ":" + curMinute + "." + curSeconds + curMeridiem + " " + dayOfWeek + " " + dayOfMonth + " of " + curMonth + ", " + curYear;

var offset = new Date().getTimezoneOffset();


//------------------------------------Change channel-------------------------------------------------
param = {
	"channelType" : hcap.channel.ChannelType.IP, 
	 "ip" : "230.0.0.1",
	 "port" : 1260,
	 "ipBroadcastType" : hcap.channel.IpBroadcastType.UDP,
	"onSuccess" : function() {
		//console.log("onSuccess");
	}, 
	"onFailure" : function(f) {
		//console.log("onFailure : errorMessage = " + f.errorMessage);
	}
};

param = {
	"channelType" : 99, 
	"url" : "http://192.168.1.105/earth.mp4",
	"onSuccess" : function() {
		//console.log("onSuccess");
	}, 
	"onFailure" : function(f) {
		//console.log("onFailure : errorMessage = " + f.errorMessage);
	}
};


hcap.channel.requestChangeCurrentChannel(param);



//------------------------------------Event listeners-------------------------------------------------
document.addEventListener("keydown", keyHandler, false);

function keyHandler(e) {
	e.preventDefault();
	var keyCode = e.keyCode;

	console.log(keyCode);
	
}


document.addEventListener("mousemove", (e) => {
	logElem.innerHTML += "<br/>" + "mouse move" + e.offsetX + "<br/>";
});



document.addEventListener(
	 "channel_changed", 
	 function (param) {
		 // {Boolean} param.result - true if the current channel is changed successfully, else false.
		 // {String} param.errorMessage - in case of failure, this message provides the details.
		 console.log(
			 "Event 'channel_changed' is received.\n" +
			 "Result = " + param.result + "\n" +
			 "Error message = " + param.errorMessage
		 );
		 
	 },
	 false
);

document.addEventListener(
	 "media_event_received", 
	 function (param) {
		 console.log("Event 'media_event_received' is received.\n");
		 
		 logElem.innerHTML += "<br/>" + "media_event_received" + param.eventType + "<br/>";
	 },
	 false
);