2 * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 var capabilities = [capabilityModeSwitch, capabilityMotionSensor, capabilityServoMotor];
19 var className = "iot2018";
21 window.onload = function () {
22 console.log("version : 0.0.1");
23 registerTouchEvents();
28 console.log("-----------init-----------");
29 scplugin.manager.getOCFDevices(getOCFDeviceCB);
32 function getOCFDeviceCB(devices) {
33 console.log("getOCFDeviceCB : " + devices.length);
35 for (var i in devices) {
36 console.log("deviceHandle: " + devices[i].deviceHandle);
37 console.log("deviceName: " + devices[i].deviceName);
38 console.log("deviceType: " + devices[i].deviceType);
39 console.log("metadata: " + devices[i].metadata);
42 setMainDevice(devices[0]);
43 ocfDevice.subscribe(onRepresentCallback);
45 for (var i = 0; i < capabilities.length; i++) {
46 capabilities[i].update();
50 function onRepresentCallback(result, deviceHandle, uri, rcsJsonString) {
51 for (var i = 0; i < capabilities.length; i++) {
52 var hrefObj = capabilities[i].href;
54 for (var item in hrefObj) {
55 if (hrefObj[item] == uri)
56 capabilities[i].onRepresentCallback(result, deviceHandle, uri, rcsJsonString);
61 function registerTouchEvents() {
62 var elements = document.getElementsByClassName("icon-move");
66 elements[0].addEventListener("touchstart", function() {
67 if (!capabilityModeSwitch.isControllable()){
70 document.getElementById("camera_controller").className = "shadow-up";
74 elements[1].addEventListener("touchstart", function() {
75 if (!capabilityModeSwitch.isControllable()){
78 document.getElementById("camera_controller").className = "shadow-left";
82 elements[2].addEventListener("touchstart", function() {
83 if (!capabilityModeSwitch.isControllable()){
86 document.getElementById("camera_controller").className = "shadow-right";
90 elements[3].addEventListener("touchstart", function() {
91 if (!capabilityModeSwitch.isControllable()){
94 document.getElementById("camera_controller").className = "shadow-down";
97 for (var i = 0; i < elements.length; i++){
98 elements[i].addEventListener("touchend", function() {
99 document.getElementById("camera_controller").className = "";
104 function setMainDevice(device) {
105 scplugin.log.debug(className, arguments.callee.name, "set ocf device : " + device.deviceName);
109 function backAction() {
110 scplugin.manager.close();
113 function onModeBtnClicked() {
114 capabilityModeSwitch.modeToggle();
117 function onMoveUpBtnClicked() {
118 if (!capabilityModeSwitch.isControllable()){
121 capabilityServoMotor.moveUp();
124 function onMoveDownBtnClicked() {
125 if (!capabilityModeSwitch.isControllable()){
128 capabilityServoMotor.moveDown();
131 function onMoveLeftBtnClicked() {
132 if (!capabilityModeSwitch.isControllable()){
135 capabilityServoMotor.moveLeft();
138 function onMoveRightBtnClicked() {
139 if (!capabilityModeSwitch.isControllable()){
142 capabilityServoMotor.moveRight();