diff --git a/js/observe.js b/js/observe.js index 80693a8..ef5c160 100644 --- a/js/observe.js +++ b/js/observe.js @@ -1,37 +1,35 @@ MixIO.log = console.log stop_project = console.log('stop_project') -var lastPublishTime = [new Date(0),new Date(0),new Date(0),new Date(0),new Date(0),new Date(0),new Date(0),new Date(0),new Date(0),new Date(0),new Date(0),new Date(0),new Date(0),new Date(0),new Date(0),new Date(0),new Date(0),new Date(0),new Date(0),new Date(0)] +var lastPublishTime = [new Date(0), new Date(0), new Date(0), new Date(0), new Date(0), new Date(0), new Date(0), new Date(0), new Date(0), new Date(0), new Date(0), new Date(0), new Date(0), new Date(0), new Date(0), new Date(0), new Date(0), new Date(0), new Date(0), new Date(0)] var minPublishInterval = 500 + function isJSON(str) { if (typeof str == 'string') { try { - var obj=JSON.parse(str); - if(typeof obj == 'object' && obj ){ + var obj = JSON.parse(str); + if (typeof obj == 'object' && obj) { return true; - }else{ + } else { return false; } - } catch(e) { + } catch (e) { return false; } } } -function publish(topic,message,omit){ - if(isRunning||omit) - { + +function publish(topic, message, omit) { + if (isRunning || omit) { var newPublishTime = new Date() - if(newPublishTime-lastPublishTime[0]>=minPublishInterval) - { - if(!isMixly) - client.publish(globalUserName+'/'+globalProjectName+'/'+topic,message) + if (newPublishTime - lastPublishTime[0] >= minPublishInterval) { + if (!isMixly) + client.publish(globalUserName + '/' + globalProjectName + '/' + topic, message) else - client.publish('MixIO'+'/'+globalUserName.slice(1)+'/'+globalProjectName+'/'+topic,message) + client.publish('MixIO' + '/' + globalUserName.slice(1) + '/' + globalProjectName + '/' + topic, message) lastPublishTime.shift() lastPublishTime.push(new Date()) - } - else - { + } else { showtext(JSLang[lang].speedLimit) MixIO.log(JSLang[lang].speedLimit) } @@ -39,42 +37,43 @@ function publish(topic,message,omit){ } isRunning = true; isMixly = false; -$(function(){ +$(function() { init_layout(); get_width(); - function view_project(resJSON,userName,projectPass,projectName,timeStamp){ + + function view_project(resJSON, userName, projectPass, projectName, timeStamp) { $("#prjName").html(projectName) - $("#shareMessage").html(userName+JSLang[lang].shareAt+timeStamp) + $("#shareMessage").html(userName + JSLang[lang].shareAt + timeStamp) randomClientID = 'OBGuest_' + Math.random().toString(16).substr(2, 8) globalUserName = userName globalProjectName = projectName - client = mqtt.connect((location.protocol == 'https:' ? 'wss://' : 'ws://')+window.location.host+(location.protocol == 'https:' ? ':8084' : ':8083')+'/mqtt',{ - 'clientId':randomClientID, - 'username':userName, - 'password':projectPass + client = mqtt.connect((location.protocol == 'https:' ? 'wss://' : 'ws://') + window.location.host + (location.protocol == 'https:' ? ':8084' : ':8083') + '/mqtt', { + 'clientId': randomClientID, + 'username': userName, + 'password': projectPass }) - client.subscribe(userName+'/'+projectName+'/#') + client.subscribe(userName + '/' + projectName + '/#') var prev_layout = stringendecoder.decodeHtml(resJSON.layout_info) var units_array = $(prev_layout) - for(var ct = 0;ct<=units_array.length-1;ct = ct+1){ + for (var ct = 0; ct <= units_array.length - 1; ct = ct + 1) { var un = $(units_array[ct]) var toolkits = { - 'input_button':add_button, - 'input_slider':add_slider, - 'input_keyboard':add_keyboard, - 'input_controller':add_controller, - 'input_rgb':add_rgb, - 'output_bulb':add_bulb, - 'output_text':add_text, - 'output_chart':add_chart, - 'output_bar':add_bar, - 'output_dashboard':add_dashboard, - 'output_map':add_map, - 'input_weather':add_weather, - 'table':add_table, - 'decorate_text':add_decorate_text, - 'decorate_pic':function(){}, - 'magic':add_magic, + 'input_button': add_button, + 'input_slider': add_slider, + 'input_keyboard': add_keyboard, + 'input_controller': add_controller, + 'input_rgb': add_rgb, + 'output_bulb': add_bulb, + 'output_text': add_text, + 'output_chart': add_chart, + 'output_bar': add_bar, + 'output_dashboard': add_dashboard, + 'output_map': add_map, + 'input_weather': add_weather, + 'table': add_table, + 'decorate_text': add_decorate_text, + 'decorate_pic': add_decorate_pic, + 'magic': add_magic, 'ble': add_ble, 'pixel': add_pixel, 'input_mic': add_mic, @@ -84,77 +83,72 @@ $(function(){ 'camera': add_camera, 'face': add_face, 'ocr': add_ocr, - 'qr':add_qr + 'qr': add_qr } console.log(un.attr('user-type')) - toolkits[un.attr('user-type')](un.attr('user-title'),un.attr('user-topic'),un.attr('user-content'),un.attr('style'),un.attr('title_style'),true); + toolkits[un.attr('user-type')](un.attr('user-title'), un.attr('user-topic'), un.attr('user-content'), un.attr('style'), un.attr('title_style'), true); } } - var modald = showmodaltext("
"+JSLang[lang].loading+"
" + JSLang[lang].loading + "