.mCSB_container{margin-right:30px}.mCSB_container.mCS_no_scrollbar_y.mCS_y_hidden{margin-right:0}.mCS-dir-rtl>.mCSB_inside>.mCSB_container{margin-right:0;margin-left:30px}.mCS-dir-rtl>.mCSB_inside>.mCSB_container.mCS_no_scrollbar_y.mCS_y_hidden{margin-left:0}.mCSB_scrollTools{position:absolute;width:16px;height:auto;left:auto;top:0;right:0;bottom:0;opacity:.75;filter:"alpha(opacity=75)";-ms-filter:"alpha(opacity=75)"}.mCSB_outside+.mCSB_scrollTools{right:-26px}.mCS-dir-rtl>.mCSB_inside>.mCSB_scrollTools,.mCS-dir-rtl>.mCSB_outside+.mCSB_scrollTools{right:auto;left:0}.mCS-dir-rtl>.mCSB_outside+.mCSB_scrollTools{left:-26px}.mCSB_scrollTools .mCSB_draggerContainer{position:absolute;top:0;left:0;bottom:0;right:0;height:auto}.mCSB_scrollTools a+.mCSB_draggerContainer{margin:20px 0}.mCSB_scrollTools .mCSB_draggerRail{width:2px;height:100%;margin:0 auto;-webkit-border-radius:16px;-moz-border-radius:16px;border-radius:16px}.mCSB_scrollTools .mCSB_dragger{cursor:pointer;width:100%;height:30px;z-index:1}.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{position:relative;width:4px;height:100%;margin:0 auto;-webkit-border-radius:16px;-moz-border-radius:16px;border-radius:16px;text-align:center}.mCSB_scrollTools_vertical.mCSB_scrollTools_onDrag_expand .mCSB_dragger.mCSB_dragger_onDrag_expanded .mCSB_dragger_bar,.mCSB_scrollTools_vertical.mCSB_scrollTools_onDrag_expand .mCSB_draggerContainer:hover .mCSB_dragger .mCSB_dragger_bar{width:12px}.mCSB_scrollTools_vertical.mCSB_scrollTools_onDrag_expand .mCSB_dragger.mCSB_dragger_onDrag_expanded+.mCSB_draggerRail,.mCSB_scrollTools_vertical.mCSB_scrollTools_onDrag_expand .mCSB_draggerContainer:hover .mCSB_draggerRail{width:8px}.mCSB_scrollTools .mCSB_buttonDown,.mCSB_scrollTools .mCSB_buttonUp{display:block;position:absolute;height:20px;width:100%;overflow:hidden;margin:0 auto;cursor:pointer}.mCSB_scrollTools .mCSB_buttonDown{bottom:0}.mCSB_horizontal.mCSB_inside>.mCSB_container{margin-right:0;margin-bottom:30px}.mCSB_horizontal.mCSB_outside>.mCSB_container{min-height:100%}.mCSB_horizontal>.mCSB_container.mCS_no_scrollbar_x.mCS_x_hidden{margin-bottom:0}.mCSB_scrollTools.mCSB_scrollTools_horizontal{width:auto;height:16px;top:auto;right:0;bottom:0;left:0}.mCustomScrollBox+.mCSB_scrollTools+.mCSB_scrollTools.mCSB_scrollTools_horizontal,.mCustomScrollBox+.mCSB_scrollTools.mCSB_scrollTools_horizontal{bottom:-26px}.mCSB_scrollTools.mCSB_scrollTools_horizontal a+.mCSB_draggerContainer{margin:0 20px}.mCSB_scrollTools.mCSB_scrollTools_horizontal .mCSB_draggerRail{width:100%;height:2px;margin:7px 0}.mCSB_scrollTools.mCSB_scrollTools_horizontal .mCSB_dragger{width:30px;height:100%;left:0}.mCSB_scrollTools.mCSB_scrollTools_horizontal .mCSB_dragger .mCSB_dragger_bar{width:100%;height:4px;margin:6px auto}.mCSB_scrollTools_horizontal.mCSB_scrollTools_onDrag_expand .mCSB_dragger.mCSB_dragger_onDrag_expanded .mCSB_dragger_bar,.mCSB_scrollTools_horizontal.mCSB_scrollTools_onDrag_expand .mCSB_draggerContainer:hover .mCSB_dragger .mCSB_dragger_bar{height:12px;margin:2px auto}.mCSB_scrollTools_horizontal.mCSB_scrollTools_onDrag_expand .mCSB_dragger.mCSB_dragger_onDrag_expanded+.mCSB_draggerRail,.mCSB_scrollTools_horizontal.mCSB_scrollTools_onDrag_expand .mCSB_draggerContainer:hover .mCSB_draggerRail{height:8px;margin:4px 0}.mCSB_scrollTools.mCSB_scrollTools_horizontal .mCSB_buttonLeft,.mCSB_scrollTools.mCSB_scrollTools_horizontal .mCSB_buttonRight{display:block;position:absolute;width:20px;height:100%;overflow:hidden;margin:0 auto;cursor:pointer}.mCSB_scrollTools.mCSB_scrollTools_horizontal .mCSB_buttonLeft{left:0}.mCSB_scrollTools.mCSB_scrollTools_horizontal .mCSB_buttonRight{right:0}.mCSB_container_wrapper{position:absolute;height:auto;width:auto;overflow:hidden;top:0;left:0;right:0;bottom:0;margin-right:30px;margin-bottom:30px}.mCSB_container_wrapper>.mCSB_container{padding-right:30px;padding-bottom:30px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.mCSB_vertical_horizontal>.mCSB_scrollTools.mCSB_scrollTools_vertical{bottom:20px}.mCSB_vertical_horizontal>.mCSB_scrollTools.mCSB_scrollTools_horizontal{right:20px}.mCSB_container_wrapper.mCS_no_scrollbar_x.mCS_x_hidden+.mCSB_scrollTools.mCSB_scrollTools_vertical{bottom:0}.mCS-dir-rtl>.mCustomScrollBox.mCSB_vertical_horizontal.mCSB_inside>.mCSB_scrollTools.mCSB_scrollTools_horizontal,.mCSB_container_wrapper.mCS_no_scrollbar_y.mCS_y_hidden+.mCSB_scrollTools~.mCSB_scrollTools.mCSB_scrollTools_horizontal{right:0}.mCS-dir-rtl>.mCustomScrollBox.mCSB_vertical_horizontal.mCSB_inside>.mCSB_scrollTools.mCSB_scrollTools_horizontal{left:20px}.mCS-dir-rtl>.mCustomScrollBox.mCSB_vertical_horizontal.mCSB_inside>.mCSB_container_wrapper.mCS_no_scrollbar_y.mCS_y_hidden+.mCSB_scrollTools~.mCSB_scrollTools.mCSB_scrollTools_horizontal{left:0}.mCS-dir-rtl>.mCSB_inside>.mCSB_container_wrapper{margin-right:0;margin-left:30px}.mCSB_container_wrapper.mCS_no_scrollbar_y.mCS_y_hidden>.mCSB_container{padding-right:0}.mCSB_container_wrapper.mCS_no_scrollbar_x.mCS_x_hidden>.mCSB_container{padding-bottom:0}.mCustomScrollBox.mCSB_vertical_horizontal.mCSB_inside>.mCSB_container_wrapper.mCS_no_scrollbar_y.mCS_y_hidden{margin-right:0;margin-left:0}.mCustomScrollBox.mCSB_vertical_horizontal.mCSB_inside>.mCSB_container_wrapper.mCS_no_scrollbar_x.mCS_x_hidden{margin-bottom:0}.mCSB_scrollTools,.mCSB_scrollTools .mCSB_buttonDown,.mCSB_scrollTools .mCSB_buttonLeft,.mCSB_scrollTools .mCSB_buttonRight,.mCSB_scrollTools .mCSB_buttonUp,.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{-webkit-transition:opacity .2s ease-in-out,background-color .2s ease-in-out;-moz-transition:opacity .2s ease-in-out,background-color .2s ease-in-out;-o-transition:opacity .2s ease-in-out,background-color .2s ease-in-out;transition:opacity .2s ease-in-out,background-color .2s ease-in-out}.mCSB_scrollTools_horizontal.mCSB_scrollTools_onDrag_expand .mCSB_draggerRail,.mCSB_scrollTools_horizontal.mCSB_scrollTools_onDrag_expand .mCSB_dragger_bar,.mCSB_scrollTools_vertical.mCSB_scrollTools_onDrag_expand .mCSB_draggerRail,.mCSB_scrollTools_vertical.mCSB_scrollTools_onDrag_expand .mCSB_dragger_bar{-webkit-transition:width .2s ease-out .2s,height .2s ease-out .2s,margin-left .2s ease-out .2s,margin-right .2s ease-out .2s,margin-top .2s ease-out .2s,margin-bottom .2s ease-out .2s,opacity .2s ease-in-out,background-color .2s ease-in-out;-moz-transition:width .2s ease-out .2s,height .2s ease-out .2s,margin-left .2s ease-out .2s,margin-right .2s ease-out .2s,margin-top .2s ease-out .2s,margin-bottom .2s ease-out .2s,opacity .2s ease-in-out,background-color .2s ease-in-out;-o-transition:width .2s ease-out .2s,height .2s ease-out .2s,margin-left .2s ease-out .2s,margin-right .2s ease-out .2s,margin-top .2s ease-out .2s,margin-bottom .2s ease-out .2s,opacity .2s ease-in-out,background-color .2s ease-in-out;transition:width .2s ease-out .2s,height .2s ease-out .2s,margin-left .2s ease-out .2s,margin-right .2s ease-out .2s,margin-top .2s ease-out .2s,margin-bottom .2s ease-out .2s,opacity .2s ease-in-out,background-color .2s ease-in-out}.mCS-autoHide>.mCustomScrollBox>.mCSB_scrollTools,.mCS-autoHide>.mCustomScrollBox~.mCSB_scrollTools{opacity:0;filter:"alpha(opacity=0)";-ms-filter:"alpha(opacity=0)"}.mCS-autoHide:hover>.mCustomScrollBox>.mCSB_scrollTools,.mCS-autoHide:hover>.mCustomScrollBox~.mCSB_scrollTools,.mCustomScrollBox:hover>.mCSB_scrollTools,.mCustomScrollBox:hover~.mCSB_scrollTools,.mCustomScrollbar>.mCustomScrollBox>.mCSB_scrollTools.mCSB_scrollTools_onDrag,.mCustomScrollbar>.mCustomScrollBox~.mCSB_scrollTools.mCSB_scrollTools_onDrag{opacity:1;filter:"alpha(opacity=100)";-ms-filter:"alpha(opacity=100)"}.mCSB_scrollTools .mCSB_draggerRail{background-color:#000;background-color:rgba(0,0,0,.4);filter:"alpha(opacity=40)";-ms-filter:"alpha(opacity=40)"}.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{background-color:#fff;background-color:rgba(255,255,255,.75);filter:"alpha(opacity=75)";-ms-filter:"alpha(opacity=75)"}.mCSB_scrollTools .mCSB_dragger:hover .mCSB_dragger_bar{background-color:#fff;background-color:rgba(255,255,255,.85);filter:"alpha(opacity=85)";-ms-filter:"alpha(opacity=85)"}.mCSB_scrollTools .mCSB_dragger.mCSB_dragger_onDrag .mCSB_dragger_bar,.mCSB_scrollTools .mCSB_dragger:active .mCSB_dragger_bar{background-color:#fff;background-color:rgba(255,255,255,.9);filter:"alpha(opacity=90)";-ms-filter:"alpha(opacity=90)"}.mCSB_scrollTools .mCSB_buttonDown,.mCSB_scrollTools .mCSB_buttonLeft,.mCSB_scrollTools .mCSB_buttonRight,.mCSB_scrollTools .mCSB_buttonUp{background-image:url(mCSB_buttons.png);background-repeat:no-repeat;opacity:.4;filter:"alpha(opacity=40)";-ms-filter:"alpha(opacity=40)"}.mCSB_scrollTools .mCSB_buttonUp{background-position:0 0}.mCSB_scrollTools .mCSB_buttonDown{background-position:0 -20px}.mCSB_scrollTools .mCSB_buttonLeft{background-position:0 -40px}.mCSB_scrollTools .mCSB_buttonRight{background-position:0 -56px}.mCSB_scrollTools .mCSB_buttonDown:hover,.mCSB_scrollTools .mCSB_buttonLeft:hover,.mCSB_scrollTools .mCSB_buttonRight:hover,.mCSB_scrollTools .mCSB_buttonUp:hover{opacity:.75;filter:"alpha(opacity=75)";-ms-filter:"alpha(opacity=75)"}.mCSB_scrollTools .mCSB_buttonDown:active,.mCSB_scrollTools .mCSB_buttonLeft:active,.mCSB_scrollTools .mCSB_buttonRight:active,.mCSB_scrollTools .mCSB_buttonUp:active{opacity:.9;filter:"alpha(opacity=90)";-ms-filter:"alpha(opacity=90)"}.mCS-dark.mCSB_scrollTools .mCSB_draggerRail{background-color:#000;background-color:rgba(0,0,0,.15)}.mCS-dark.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{background-color:#000;background-color:rgba(0,0,0,.75)}.mCS-dark.mCSB_scrollTools .mCSB_dragger:hover .mCSB_dragger_bar{background-color:rgba(0,0,0,.85)}.mCS-dark.mCSB_scrollTools .mCSB_dragger.mCSB_dragger_onDrag .mCSB_dragger_bar,.mCS-dark.mCSB_scrollTools .mCSB_dragger:active .mCSB_dragger_bar{background-color:rgba(0,0,0,.9)}.mCS-dark.mCSB_scrollTools .mCSB_buttonUp{background-position:-80px 0}.mCS-dark.mCSB_scrollTools .mCSB_buttonDown{background-position:-80px -20px}.mCS-dark.mCSB_scrollTools .mCSB_buttonLeft{background-position:-80px -40px}.mCS-dark.mCSB_scrollTools .mCSB_buttonRight{background-position:-80px -56px}.mCS-dark-2.mCSB_scrollTools .mCSB_draggerRail,.mCS-light-2.mCSB_scrollTools .mCSB_draggerRail{width:4px;background-color:#fff;background-color:rgba(255,255,255,.1);-webkit-border-radius:1px;-moz-border-radius:1px;border-radius:1px}.mCS-dark-2.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar,.mCS-light-2.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{width:4px;background-color:#fff;background-color:rgba(255,255,255,.75);-webkit-border-radius:1px;-moz-border-radius:1px;border-radius:1px}.mCS-dark-2.mCSB_scrollTools_horizontal .mCSB_dragger .mCSB_dragger_bar,.mCS-dark-2.mCSB_scrollTools_horizontal .mCSB_draggerRail,.mCS-light-2.mCSB_scrollTools_horizontal .mCSB_dragger .mCSB_dragger_bar,.mCS-light-2.mCSB_scrollTools_horizontal .mCSB_draggerRail{width:100%;height:4px;margin:6px auto}.mCS-light-2.mCSB_scrollTools .mCSB_dragger:hover .mCSB_dragger_bar{background-color:#fff;background-color:rgba(255,255,255,.85)}.mCS-light-2.mCSB_scrollTools .mCSB_dragger.mCSB_dragger_onDrag .mCSB_dragger_bar,.mCS-light-2.mCSB_scrollTools .mCSB_dragger:active .mCSB_dragger_bar{background-color:#fff;background-color:rgba(255,255,255,.9)}.mCS-light-2.mCSB_scrollTools .mCSB_buttonUp{background-position:-32px 0}.mCS-light-2.mCSB_scrollTools .mCSB_buttonDown{background-position:-32px -20px}.mCS-light-2.mCSB_scrollTools .mCSB_buttonLeft{background-position:-40px -40px}.mCS-light-2.mCSB_scrollTools .mCSB_buttonRight{background-position:-40px -56px}.mCS-dark-2.mCSB_scrollTools .mCSB_draggerRail{background-color:#000;background-color:rgba(0,0,0,.1);-webkit-border-radius:1px;-moz-border-radius:1px;border-radius:1px}.mCS-dark-2.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{background-color:#000;background-color:rgba(0,0,0,.75);-webkit-border-radius:1px;-moz-border-radius:1px;border-radius:1px}.mCS-dark-2.mCSB_scrollTools .mCSB_dragger:hover .mCSB_dragger_bar{background-color:#000;background-color:rgba(0,0,0,.85)}.mCS-dark-2.mCSB_scrollTools .mCSB_dragger.mCSB_dragger_onDrag .mCSB_dragger_bar,.mCS-dark-2.mCSB_scrollTools .mCSB_dragger:active .mCSB_dragger_bar{background-color:#000;background-color:rgba(0,0,0,.9)}.mCS-dark-2.mCSB_scrollTools .mCSB_buttonUp{background-position:-112px 0}.mCS-dark-2.mCSB_scrollTools .mCSB_buttonDown{background-position:-112px -20px}.mCS-dark-2.mCSB_scrollTools .mCSB_buttonLeft{background-position:-120px -40px}.mCS-dark-2.mCSB_scrollTools .mCSB_buttonRight{background-position:-120px -56px}.mCS-dark-thick.mCSB_scrollTools .mCSB_draggerRail,.mCS-light-thick.mCSB_scrollTools .mCSB_draggerRail{width:4px;background-color:#fff;background-color:rgba(255,255,255,.1);-webkit-border-radius:2px;-moz-border-radius:2px;border-radius:2px}.mCS-dark-thick.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar,.mCS-light-thick.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{width:6px;background-color:#fff;background-color:rgba(255,255,255,.75);-webkit-border-radius:2px;-moz-border-radius:2px;border-radius:2px}.mCS-dark-thick.mCSB_scrollTools_horizontal .mCSB_draggerRail,.mCS-light-thick.mCSB_scrollTools_horizontal .mCSB_draggerRail{width:100%;height:4px;margin:6px 0}.mCS-dark-thick.mCSB_scrollTools_horizontal .mCSB_dragger .mCSB_dragger_bar,.mCS-light-thick.mCSB_scrollTools_horizontal .mCSB_dragger .mCSB_dragger_bar{width:100%;height:6px;margin:5px auto}.mCS-light-thick.mCSB_scrollTools .mCSB_dragger:hover .mCSB_dragger_bar{background-color:#fff;background-color:rgba(255,255,255,.85)}.mCS-light-thick.mCSB_scrollTools .mCSB_dragger.mCSB_dragger_onDrag .mCSB_dragger_bar,.mCS-light-thick.mCSB_scrollTools .mCSB_dragger:active .mCSB_dragger_bar{background-color:#fff;background-color:rgba(255,255,255,.9)}.mCS-light-thick.mCSB_scrollTools .mCSB_buttonUp{background-position:-16px 0}.mCS-light-thick.mCSB_scrollTools .mCSB_buttonDown{background-position:-16px -20px}.mCS-light-thick.mCSB_scrollTools .mCSB_buttonLeft{background-position:-20px -40px}.mCS-light-thick.mCSB_scrollTools .mCSB_buttonRight{background-position:-20px -56px}.mCS-dark-thick.mCSB_scrollTools .mCSB_draggerRail{background-color:#000;background-color:rgba(0,0,0,.1);-webkit-border-radius:2px;-moz-border-radius:2px;border-radius:2px}.mCS-dark-thick.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{background-color:#000;background-color:rgba(0,0,0,.75);-webkit-border-radius:2px;-moz-border-radius:2px;border-radius:2px}.mCS-dark-thick.mCSB_scrollTools .mCSB_dragger:hover .mCSB_dragger_bar{background-color:#000;background-color:rgba(0,0,0,.85)}.mCS-dark-thick.mCSB_scrollTools .mCSB_dragger.mCSB_dragger_onDrag .mCSB_dragger_bar,.mCS-dark-thick.mCSB_scrollTools .mCSB_dragger:active .mCSB_dragger_bar{background-color:#000;background-color:rgba(0,0,0,.9)}.mCS-dark-thick.mCSB_scrollTools .mCSB_buttonUp{background-position:-96px 0}.mCS-dark-thick.mCSB_scrollTools .mCSB_buttonDown{background-position:-96px -20px}.mCS-dark-thick.mCSB_scrollTools .mCSB_buttonLeft{background-position:-100px -40px}.mCS-dark-thick.mCSB_scrollTools .mCSB_buttonRight{background-position:-100px -56px}.mCS-light-thin.mCSB_scrollTools .mCSB_draggerRail{background-color:#fff;background-color:rgba(255,255,255,.1)}.mCS-dark-thin.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar,.mCS-light-thin.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{width:2px}.mCS-dark-thin.mCSB_scrollTools_horizontal .mCSB_draggerRail,.mCS-light-thin.mCSB_scrollTools_horizontal .mCSB_draggerRail{width:100%}.mCS-dark-thin.mCSB_scrollTools_horizontal .mCSB_dragger .mCSB_dragger_bar,.mCS-light-thin.mCSB_scrollTools_horizontal .mCSB_dragger .mCSB_dragger_bar{width:100%;height:2px;margin:7px auto}.mCS-dark-thin.mCSB_scrollTools .mCSB_draggerRail{background-color:#000;background-color:rgba(0,0,0,.15)}.mCS-dark-thin.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{background-color:#000;background-color:rgba(0,0,0,.75)}.mCS-dark-thin.mCSB_scrollTools .mCSB_dragger:hover .mCSB_dragger_bar{background-color:#000;background-color:rgba(0,0,0,.85)}.mCS-dark-thin.mCSB_scrollTools .mCSB_dragger.mCSB_dragger_onDrag .mCSB_dragger_bar,.mCS-dark-thin.mCSB_scrollTools .mCSB_dragger:active .mCSB_dragger_bar{background-color:#000;background-color:rgba(0,0,0,.9)}.mCS-dark-thin.mCSB_scrollTools .mCSB_buttonUp{background-position:-80px 0}.mCS-dark-thin.mCSB_scrollTools .mCSB_buttonDown{background-position:-80px -20px}.mCS-dark-thin.mCSB_scrollTools .mCSB_buttonLeft{background-position:-80px -40px}.mCS-dark-thin.mCSB_scrollTools .mCSB_buttonRight{background-position:-80px -56px}.mCS-rounded.mCSB_scrollTools .mCSB_draggerRail{background-color:#fff;background-color:rgba(255,255,255,.15)}.mCS-rounded-dark.mCSB_scrollTools .mCSB_dragger,.mCS-rounded-dots-dark.mCSB_scrollTools .mCSB_dragger,.mCS-rounded-dots.mCSB_scrollTools .mCSB_dragger,.mCS-rounded.mCSB_scrollTools .mCSB_dragger{height:14px}.mCS-rounded-dark.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar,.mCS-rounded-dots-dark.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar,.mCS-rounded-dots.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar,.mCS-rounded.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{width:14px;margin:0 1px}.mCS-rounded-dark.mCSB_scrollTools_horizontal .mCSB_dragger,.mCS-rounded-dots-dark.mCSB_scrollTools_horizontal .mCSB_dragger,.mCS-rounded-dots.mCSB_scrollTools_horizontal .mCSB_dragger,.mCS-rounded.mCSB_scrollTools_horizontal .mCSB_dragger{width:14px}.mCS-rounded-dark.mCSB_scrollTools_horizontal .mCSB_dragger .mCSB_dragger_bar,.mCS-rounded-dots-dark.mCSB_scrollTools_horizontal .mCSB_dragger .mCSB_dragger_bar,.mCS-rounded-dots.mCSB_scrollTools_horizontal .mCSB_dragger .mCSB_dragger_bar,.mCS-rounded.mCSB_scrollTools_horizontal .mCSB_dragger .mCSB_dragger_bar{height:14px;margin:1px 0}.mCS-rounded-dark.mCSB_scrollTools_vertical.mCSB_scrollTools_onDrag_expand .mCSB_dragger.mCSB_dragger_onDrag_expanded .mCSB_dragger_bar,.mCS-rounded-dark.mCSB_scrollTools_vertical.mCSB_scrollTools_onDrag_expand .mCSB_draggerContainer:hover .mCSB_dragger .mCSB_dragger_bar,.mCS-rounded.mCSB_scrollTools_vertical.mCSB_scrollTools_onDrag_expand .mCSB_dragger.mCSB_dragger_onDrag_expanded .mCSB_dragger_bar,.mCS-rounded.mCSB_scrollTools_vertical.mCSB_scrollTools_onDrag_expand .mCSB_draggerContainer:hover .mCSB_dragger .mCSB_dragger_bar{width:16px;height:16px;margin:-1px 0}.mCS-rounded-dark.mCSB_scrollTools_vertical.mCSB_scrollTools_onDrag_expand .mCSB_dragger.mCSB_dragger_onDrag_expanded+.mCSB_draggerRail,.mCS-rounded-dark.mCSB_scrollTools_vertical.mCSB_scrollTools_onDrag_expand .mCSB_draggerContainer:hover .mCSB_draggerRail,.mCS-rounded.mCSB_scrollTools_vertical.mCSB_scrollTools_onDrag_expand .mCSB_dragger.mCSB_dragger_onDrag_expanded+.mCSB_draggerRail,.mCS-rounded.mCSB_scrollTools_vertical.mCSB_scrollTools_onDrag_expand .mCSB_draggerContainer:hover .mCSB_draggerRail{width:4px}.mCS-rounded-dark.mCSB_scrollTools_horizontal.mCSB_scrollTools_onDrag_expand .mCSB_dragger.mCSB_dragger_onDrag_expanded .mCSB_dragger_bar,.mCS-rounded-dark.mCSB_scrollTools_horizontal.mCSB_scrollTools_onDrag_expand .mCSB_draggerContainer:hover .mCSB_dragger .mCSB_dragger_bar,.mCS-rounded.mCSB_scrollTools_horizontal.mCSB_scrollTools_onDrag_expand .mCSB_dragger.mCSB_dragger_onDrag_expanded .mCSB_dragger_bar,.mCS-rounded.mCSB_scrollTools_horizontal.mCSB_scrollTools_onDrag_expand .mCSB_draggerContainer:hover .mCSB_dragger .mCSB_dragger_bar{height:16px;width:16px;margin:0 -1px}.mCS-rounded-dark.mCSB_scrollTools_horizontal.mCSB_scrollTools_onDrag_expand .mCSB_dragger.mCSB_dragger_onDrag_expanded+.mCSB_draggerRail,.mCS-rounded-dark.mCSB_scrollTools_horizontal.mCSB_scrollTools_onDrag_expand .mCSB_draggerContainer:hover .mCSB_draggerRail,.mCS-rounded.mCSB_scrollTools_horizontal.mCSB_scrollTools_onDrag_expand .mCSB_dragger.mCSB_dragger_onDrag_expanded+.mCSB_draggerRail,.mCS-rounded.mCSB_scrollTools_horizontal.mCSB_scrollTools_onDrag_expand .mCSB_draggerContainer:hover .mCSB_draggerRail{height:4px;margin:6px 0}.mCS-rounded.mCSB_scrollTools .mCSB_buttonUp{background-position:0 -72px}.mCS-rounded.mCSB_scrollTools .mCSB_buttonDown{background-position:0 -92px}.mCS-rounded.mCSB_scrollTools .mCSB_buttonLeft{background-position:0 -112px}.mCS-rounded.mCSB_scrollTools .mCSB_buttonRight{background-position:0 -128px}.mCS-rounded-dark.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar,.mCS-rounded-dots-dark.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{background-color:#000;background-color:rgba(0,0,0,.75)}.mCS-rounded-dark.mCSB_scrollTools .mCSB_draggerRail{background-color:#000;background-color:rgba(0,0,0,.15)}.mCS-rounded-dark.mCSB_scrollTools .mCSB_dragger:hover .mCSB_dragger_bar,.mCS-rounded-dots-dark.mCSB_scrollTools .mCSB_dragger:hover .mCSB_dragger_bar{background-color:#000;background-color:rgba(0,0,0,.85)}.mCS-rounded-dark.mCSB_scrollTools .mCSB_dragger.mCSB_dragger_onDrag .mCSB_dragger_bar,.mCS-rounded-dark.mCSB_scrollTools .mCSB_dragger:active .mCSB_dragger_bar,.mCS-rounded-dots-dark.mCSB_scrollTools .mCSB_dragger.mCSB_dragger_onDrag .mCSB_dragger_bar,.mCS-rounded-dots-dark.mCSB_scrollTools .mCSB_dragger:active .mCSB_dragger_bar{background-color:#000;background-color:rgba(0,0,0,.9)}.mCS-rounded-dark.mCSB_scrollTools .mCSB_buttonUp{background-position:-80px -72px}.mCS-rounded-dark.mCSB_scrollTools .mCSB_buttonDown{background-position:-80px -92px}.mCS-rounded-dark.mCSB_scrollTools .mCSB_buttonLeft{background-position:-80px -112px}.mCS-rounded-dark.mCSB_scrollTools .mCSB_buttonRight{background-position:-80px -128px}.mCS-rounded-dots-dark.mCSB_scrollTools_vertical .mCSB_draggerRail,.mCS-rounded-dots.mCSB_scrollTools_vertical .mCSB_draggerRail{width:4px}.mCS-rounded-dots-dark.mCSB_scrollTools .mCSB_draggerRail,.mCS-rounded-dots-dark.mCSB_scrollTools_horizontal .mCSB_draggerRail,.mCS-rounded-dots.mCSB_scrollTools .mCSB_draggerRail,.mCS-rounded-dots.mCSB_scrollTools_horizontal .mCSB_draggerRail{background-color:transparent;background-position:center}.mCS-rounded-dots-dark.mCSB_scrollTools .mCSB_draggerRail,.mCS-rounded-dots.mCSB_scrollTools .mCSB_draggerRail{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAANElEQVQYV2NkIAAYiVbw//9/Y6DiM1ANJoyMjGdBbLgJQAX/kU0DKgDLkaQAvxW4HEvQFwCRcxIJK1XznAAAAABJRU5ErkJggg==);background-repeat:repeat-y;opacity:.3;filter:"alpha(opacity=30)";-ms-filter:"alpha(opacity=30)"}.mCS-rounded-dots-dark.mCSB_scrollTools_horizontal .mCSB_draggerRail,.mCS-rounded-dots.mCSB_scrollTools_horizontal .mCSB_draggerRail{height:4px;margin:6px 0;background-repeat:repeat-x}.mCS-rounded-dots.mCSB_scrollTools .mCSB_buttonUp{background-position:-16px -72px}.mCS-rounded-dots.mCSB_scrollTools .mCSB_buttonDown{background-position:-16px -92px}.mCS-rounded-dots.mCSB_scrollTools .mCSB_buttonLeft{background-position:-20px -112px}.mCS-rounded-dots.mCSB_scrollTools .mCSB_buttonRight{background-position:-20px -128px}.mCS-rounded-dots-dark.mCSB_scrollTools .mCSB_draggerRail{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAALElEQVQYV2NkIAAYSVFgDFR8BqrBBEifBbGRTfiPZhpYjiQFBK3A6l6CvgAAE9kGCd1mvgEAAAAASUVORK5CYII=)}.mCS-rounded-dots-dark.mCSB_scrollTools .mCSB_buttonUp{background-position:-96px -72px}.mCS-rounded-dots-dark.mCSB_scrollTools .mCSB_buttonDown{background-position:-96px -92px}.mCS-rounded-dots-dark.mCSB_scrollTools .mCSB_buttonLeft{background-position:-100px -112px}.mCS-rounded-dots-dark.mCSB_scrollTools .mCSB_buttonRight{background-position:-100px -128px}.mCS-3d-dark.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar,.mCS-3d-thick-dark.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar,.mCS-3d-thick.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar,.mCS-3d.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{background-repeat:repeat-y;background-image:-moz-linear-gradient(left,rgba(255,255,255,.5) 0,rgba(255,255,255,0) 100%);background-image:-webkit-gradient(linear,left top,right top,color-stop(0,rgba(255,255,255,.5)),color-stop(100%,rgba(255,255,255,0)));background-image:-webkit-linear-gradient(left,rgba(255,255,255,.5) 0,rgba(255,255,255,0) 100%);background-image:-o-linear-gradient(left,rgba(255,255,255,.5) 0,rgba(255,255,255,0) 100%);background-image:-ms-linear-gradient(left,rgba(255,255,255,.5) 0,rgba(255,255,255,0) 100%);background-image:linear-gradient(to right,rgba(255,255,255,.5) 0,rgba(255,255,255,0) 100%)}.mCS-3d-dark.mCSB_scrollTools_horizontal .mCSB_dragger .mCSB_dragger_bar,.mCS-3d-thick-dark.mCSB_scrollTools_horizontal .mCSB_dragger .mCSB_dragger_bar,.mCS-3d-thick.mCSB_scrollTools_horizontal .mCSB_dragger .mCSB_dragger_bar,.mCS-3d.mCSB_scrollTools_horizontal .mCSB_dragger .mCSB_dragger_bar{background-repeat:repeat-x;background-image:-moz-linear-gradient(top,rgba(255,255,255,.5) 0,rgba(255,255,255,0) 100%);background-image:-webkit-gradient(linear,left top,left bottom,color-stop(0,rgba(255,255,255,.5)),color-stop(100%,rgba(255,255,255,0)));background-image:-webkit-linear-gradient(top,rgba(255,255,255,.5) 0,rgba(255,255,255,0) 100%);background-image:-o-linear-gradient(top,rgba(255,255,255,.5) 0,rgba(255,255,255,0) 100%);background-image:-ms-linear-gradient(top,rgba(255,255,255,.5) 0,rgba(255,255,255,0) 100%);background-image:linear-gradient(to bottom,rgba(255,255,255,.5) 0,rgba(255,255,255,0) 100%)}.mCS-3d-dark.mCSB_scrollTools_vertical .mCSB_dragger,.mCS-3d.mCSB_scrollTools_vertical .mCSB_dragger{height:70px}.mCS-3d-dark.mCSB_scrollTools_horizontal .mCSB_dragger,.mCS-3d.mCSB_scrollTools_horizontal .mCSB_dragger{width:70px}.mCS-3d-dark.mCSB_scrollTools,.mCS-3d.mCSB_scrollTools{opacity:1;filter:"alpha(opacity=30)";-ms-filter:"alpha(opacity=30)"}.mCS-3d-dark.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar,.mCS-3d-dark.mCSB_scrollTools .mCSB_draggerRail,.mCS-3d.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar,.mCS-3d.mCSB_scrollTools .mCSB_draggerRail{-webkit-border-radius:16px;-moz-border-radius:16px;border-radius:16px}.mCS-3d-dark.mCSB_scrollTools .mCSB_draggerRail,.mCS-3d.mCSB_scrollTools .mCSB_draggerRail{width:8px;background-color:#000;background-color:rgba(0,0,0,.2);box-shadow:inset 1px 0 1px rgba(0,0,0,.5),inset -1px 0 1px rgba(255,255,255,.2)}.mCS-3d-dark.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar,.mCS-3d-dark.mCSB_scrollTools .mCSB_dragger.mCSB_dragger_onDrag .mCSB_dragger_bar,.mCS-3d-dark.mCSB_scrollTools .mCSB_dragger:active .mCSB_dragger_bar,.mCS-3d-dark.mCSB_scrollTools .mCSB_dragger:hover .mCSB_dragger_bar,.mCS-3d.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar,.mCS-3d.mCSB_scrollTools .mCSB_dragger.mCSB_dragger_onDrag .mCSB_dragger_bar,.mCS-3d.mCSB_scrollTools .mCSB_dragger:active .mCSB_dragger_bar,.mCS-3d.mCSB_scrollTools .mCSB_dragger:hover .mCSB_dragger_bar{background-color:#555}.mCS-3d-dark.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar,.mCS-3d.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{width:8px}.mCS-3d-dark.mCSB_scrollTools_horizontal .mCSB_draggerRail,.mCS-3d.mCSB_scrollTools_horizontal .mCSB_draggerRail{width:100%;height:8px;margin:4px 0;box-shadow:inset 0 1px 1px rgba(0,0,0,.5),inset 0 -1px 1px rgba(255,255,255,.2)}.mCS-3d-dark.mCSB_scrollTools_horizontal .mCSB_dragger .mCSB_dragger_bar,.mCS-3d.mCSB_scrollTools_horizontal .mCSB_dragger .mCSB_dragger_bar{width:100%;height:8px;margin:4px auto}.mCS-3d.mCSB_scrollTools .mCSB_buttonUp{background-position:-32px -72px}.mCS-3d.mCSB_scrollTools .mCSB_buttonDown{background-position:-32px -92px}.mCS-3d.mCSB_scrollTools .mCSB_buttonLeft{background-position:-40px -112px}.mCS-3d.mCSB_scrollTools .mCSB_buttonRight{background-position:-40px -128px}.mCS-3d-dark.mCSB_scrollTools .mCSB_draggerRail{background-color:#000;background-color:rgba(0,0,0,.1);box-shadow:inset 1px 0 1px rgba(0,0,0,.1)}.mCS-3d-dark.mCSB_scrollTools_horizontal .mCSB_draggerRail{box-shadow:inset 0 1px 1px rgba(0,0,0,.1)}.mCS-3d-dark.mCSB_scrollTools .mCSB_buttonUp{background-position:-112px -72px}.mCS-3d-dark.mCSB_scrollTools .mCSB_buttonDown{background-position:-112px -92px}.mCS-3d-dark.mCSB_scrollTools .mCSB_buttonLeft{background-position:-120px -112px}.mCS-3d-dark.mCSB_scrollTools .mCSB_buttonRight{background-position:-120px -128px}.mCS-3d-thick-dark.mCSB_scrollTools,.mCS-3d-thick.mCSB_scrollTools{opacity:1;filter:"alpha(opacity=30)";-ms-filter:"alpha(opacity=30)"}.mCS-3d-thick-dark.mCSB_scrollTools,.mCS-3d-thick-dark.mCSB_scrollTools .mCSB_draggerContainer,.mCS-3d-thick.mCSB_scrollTools,.mCS-3d-thick.mCSB_scrollTools .mCSB_draggerContainer{-webkit-border-radius:7px;-moz-border-radius:7px;border-radius:7px}.mCSB_inside+.mCS-3d-thick-dark.mCSB_scrollTools_vertical,.mCSB_inside+.mCS-3d-thick.mCSB_scrollTools_vertical{right:1px}.mCS-3d-thick-dark.mCSB_scrollTools_vertical,.mCS-3d-thick.mCSB_scrollTools_vertical{box-shadow:inset 1px 0 1px rgba(0,0,0,.1),inset 0 0 14px rgba(0,0,0,.5)}.mCS-3d-thick-dark.mCSB_scrollTools_horizontal,.mCS-3d-thick.mCSB_scrollTools_horizontal{bottom:1px;box-shadow:inset 0 1px 1px rgba(0,0,0,.1),inset 0 0 14px rgba(0,0,0,.5)}.mCS-3d-thick-dark.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar,.mCS-3d-thick.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px;box-shadow:inset 1px 0 0 rgba(255,255,255,.4);width:12px;margin:2px;position:absolute;height:auto;top:0;bottom:0;left:0;right:0}.mCS-3d-thick-dark.mCSB_scrollTools_horizontal .mCSB_dragger .mCSB_dragger_bar,.mCS-3d-thick.mCSB_scrollTools_horizontal .mCSB_dragger .mCSB_dragger_bar{box-shadow:inset 0 1px 0 rgba(255,255,255,.4);height:12px;width:auto}.mCS-3d-thick.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar,.mCS-3d-thick.mCSB_scrollTools .mCSB_dragger.mCSB_dragger_onDrag .mCSB_dragger_bar,.mCS-3d-thick.mCSB_scrollTools .mCSB_dragger:active .mCSB_dragger_bar,.mCS-3d-thick.mCSB_scrollTools .mCSB_dragger:hover .mCSB_dragger_bar{background-color:#555}.mCS-3d-thick.mCSB_scrollTools .mCSB_draggerContainer{background-color:#000;background-color:rgba(0,0,0,.05);box-shadow:inset 1px 1px 16px rgba(0,0,0,.1)}.mCS-3d-thick.mCSB_scrollTools .mCSB_draggerRail{background-color:transparent}.mCS-3d-thick.mCSB_scrollTools .mCSB_buttonUp{background-position:-32px -72px}.mCS-3d-thick.mCSB_scrollTools .mCSB_buttonDown{background-position:-32px -92px}.mCS-3d-thick.mCSB_scrollTools .mCSB_buttonLeft{background-position:-40px -112px}.mCS-3d-thick.mCSB_scrollTools .mCSB_buttonRight{background-position:-40px -128px}.mCS-3d-thick-dark.mCSB_scrollTools{box-shadow:inset 0 0 14px rgba(0,0,0,.2)}.mCS-3d-thick-dark.mCSB_scrollTools_horizontal{box-shadow:inset 0 1px 1px rgba(0,0,0,.1),inset 0 0 14px rgba(0,0,0,.2)}.mCS-3d-thick-dark.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{box-shadow:inset 1px 0 0 rgba(255,255,255,.4),inset -1px 0 0 rgba(0,0,0,.2)}.mCS-3d-thick-dark.mCSB_scrollTools_horizontal .mCSB_dragger .mCSB_dragger_bar{box-shadow:inset 0 1px 0 rgba(255,255,255,.4),inset 0 -1px 0 rgba(0,0,0,.2)}.mCS-3d-thick-dark.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar,.mCS-3d-thick-dark.mCSB_scrollTools .mCSB_dragger.mCSB_dragger_onDrag .mCSB_dragger_bar,.mCS-3d-thick-dark.mCSB_scrollTools .mCSB_dragger:active .mCSB_dragger_bar,.mCS-3d-thick-dark.mCSB_scrollTools .mCSB_dragger:hover .mCSB_dragger_bar{background-color:#777}.mCS-3d-thick-dark.mCSB_scrollTools .mCSB_draggerContainer{background-color:#fff;background-color:rgba(0,0,0,.05);box-shadow:inset 1px 1px 16px rgba(0,0,0,.1)}.mCS-3d-thick-dark.mCSB_scrollTools .mCSB_draggerRail,.mCS-minimal-dark.mCSB_scrollTools .mCSB_draggerRail,.mCS-minimal.mCSB_scrollTools .mCSB_draggerRail{background-color:transparent}.mCS-3d-thick-dark.mCSB_scrollTools .mCSB_buttonUp{background-position:-112px -72px}.mCS-3d-thick-dark.mCSB_scrollTools .mCSB_buttonDown{background-position:-112px -92px}.mCS-3d-thick-dark.mCSB_scrollTools .mCSB_buttonLeft{background-position:-120px -112px}.mCS-3d-thick-dark.mCSB_scrollTools .mCSB_buttonRight{background-position:-120px -128px}.mCSB_outside+.mCS-minimal-dark.mCSB_scrollTools_vertical,.mCSB_outside+.mCS-minimal.mCSB_scrollTools_vertical{right:0;margin:12px 0}.mCustomScrollBox.mCS-minimal+.mCSB_scrollTools+.mCSB_scrollTools.mCSB_scrollTools_horizontal,.mCustomScrollBox.mCS-minimal+.mCSB_scrollTools.mCSB_scrollTools_horizontal,.mCustomScrollBox.mCS-minimal-dark+.mCSB_scrollTools+.mCSB_scrollTools.mCSB_scrollTools_horizontal,.mCustomScrollBox.mCS-minimal-dark+.mCSB_scrollTools.mCSB_scrollTools_horizontal{bottom:0;margin:0 12px}.mCS-dir-rtl>.mCSB_outside+.mCS-minimal-dark.mCSB_scrollTools_vertical,.mCS-dir-rtl>.mCSB_outside+.mCS-minimal.mCSB_scrollTools_vertical{left:0;right:auto}.mCS-minimal-dark.mCSB_scrollTools_vertical .mCSB_dragger,.mCS-minimal.mCSB_scrollTools_vertical .mCSB_dragger{height:50px}.mCS-minimal-dark.mCSB_scrollTools_horizontal .mCSB_dragger,.mCS-minimal.mCSB_scrollTools_horizontal .mCSB_dragger{width:50px}.mCS-minimal.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{background-color:#fff;background-color:rgba(255,255,255,.2);filter:"alpha(opacity=20)";-ms-filter:"alpha(opacity=20)"}.mCS-minimal.mCSB_scrollTools .mCSB_dragger.mCSB_dragger_onDrag .mCSB_dragger_bar,.mCS-minimal.mCSB_scrollTools .mCSB_dragger:active .mCSB_dragger_bar{background-color:#fff;background-color:rgba(255,255,255,.5);filter:"alpha(opacity=50)";-ms-filter:"alpha(opacity=50)"}.mCS-minimal-dark.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{background-color:#000;background-color:rgba(0,0,0,.2);filter:"alpha(opacity=20)";-ms-filter:"alpha(opacity=20)"}.mCS-minimal-dark.mCSB_scrollTools .mCSB_dragger.mCSB_dragger_onDrag .mCSB_dragger_bar,.mCS-minimal-dark.mCSB_scrollTools .mCSB_dragger:active .mCSB_dragger_bar{background-color:#000;background-color:rgba(0,0,0,.5);filter:"alpha(opacity=50)";-ms-filter:"alpha(opacity=50)"}.mCS-dark-3.mCSB_scrollTools .mCSB_draggerRail,.mCS-light-3.mCSB_scrollTools .mCSB_draggerRail{width:6px;background-color:#000;background-color:rgba(0,0,0,.2)}.mCS-dark-3.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar,.mCS-light-3.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{width:6px}.mCS-dark-3.mCSB_scrollTools_horizontal .mCSB_dragger .mCSB_dragger_bar,.mCS-dark-3.mCSB_scrollTools_horizontal .mCSB_draggerRail,.mCS-light-3.mCSB_scrollTools_horizontal .mCSB_dragger .mCSB_dragger_bar,.mCS-light-3.mCSB_scrollTools_horizontal .mCSB_draggerRail{width:100%;height:6px;margin:5px 0}.mCS-dark-3.mCSB_scrollTools_vertical.mCSB_scrollTools_onDrag_expand .mCSB_dragger.mCSB_dragger_onDrag_expanded+.mCSB_draggerRail,.mCS-dark-3.mCSB_scrollTools_vertical.mCSB_scrollTools_onDrag_expand .mCSB_draggerContainer:hover .mCSB_draggerRail,.mCS-light-3.mCSB_scrollTools_vertical.mCSB_scrollTools_onDrag_expand .mCSB_dragger.mCSB_dragger_onDrag_expanded+.mCSB_draggerRail,.mCS-light-3.mCSB_scrollTools_vertical.mCSB_scrollTools_onDrag_expand .mCSB_draggerContainer:hover .mCSB_draggerRail{width:12px}.mCS-dark-3.mCSB_scrollTools_horizontal.mCSB_scrollTools_onDrag_expand .mCSB_dragger.mCSB_dragger_onDrag_expanded+.mCSB_draggerRail,.mCS-dark-3.mCSB_scrollTools_horizontal.mCSB_scrollTools_onDrag_expand .mCSB_draggerContainer:hover .mCSB_draggerRail,.mCS-light-3.mCSB_scrollTools_horizontal.mCSB_scrollTools_onDrag_expand .mCSB_dragger.mCSB_dragger_onDrag_expanded+.mCSB_draggerRail,.mCS-light-3.mCSB_scrollTools_horizontal.mCSB_scrollTools_onDrag_expand .mCSB_draggerContainer:hover .mCSB_draggerRail{height:12px;margin:2px 0}.mCS-light-3.mCSB_scrollTools .mCSB_buttonUp{background-position:-32px -72px}.mCS-light-3.mCSB_scrollTools .mCSB_buttonDown{background-position:-32px -92px}.mCS-light-3.mCSB_scrollTools .mCSB_buttonLeft{background-position:-40px -112px}.mCS-light-3.mCSB_scrollTools .mCSB_buttonRight{background-position:-40px -128px}.mCS-dark-3.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{background-color:#000;background-color:rgba(0,0,0,.75)}.mCS-dark-3.mCSB_scrollTools .mCSB_dragger:hover .mCSB_dragger_bar{background-color:#000;background-color:rgba(0,0,0,.85)}.mCS-dark-3.mCSB_scrollTools .mCSB_dragger.mCSB_dragger_onDrag .mCSB_dragger_bar,.mCS-dark-3.mCSB_scrollTools .mCSB_dragger:active .mCSB_dragger_bar{background-color:#000;background-color:rgba(0,0,0,.9)}.mCS-dark-3.mCSB_scrollTools .mCSB_draggerRail{background-color:#000;background-color:rgba(0,0,0,.1)}.mCS-dark-3.mCSB_scrollTools .mCSB_buttonUp{background-position:-112px -72px}.mCS-dark-3.mCSB_scrollTools .mCSB_buttonDown{background-position:-112px -92px}.mCS-dark-3.mCSB_scrollTools .mCSB_buttonLeft{background-position:-120px -112px}.mCS-dark-3.mCSB_scrollTools .mCSB_buttonRight{background-position:-120px -128px}.mCS-inset-2-dark.mCSB_scrollTools .mCSB_draggerRail,.mCS-inset-2.mCSB_scrollTools .mCSB_draggerRail,.mCS-inset-3-dark.mCSB_scrollTools .mCSB_draggerRail,.mCS-inset-3.mCSB_scrollTools .mCSB_draggerRail,.mCS-inset-dark.mCSB_scrollTools .mCSB_draggerRail,.mCS-inset.mCSB_scrollTools .mCSB_draggerRail{width:12px;background-color:#000;background-color:rgba(0,0,0,.2)}.mCS-inset-2-dark.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar,.mCS-inset-2.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar,.mCS-inset-3-dark.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar,.mCS-inset-3.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar,.mCS-inset-dark.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar,.mCS-inset.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{width:6px;margin:3px 5px;position:absolute;height:auto;top:0;bottom:0;left:0;right:0}.mCS-inset-2-dark.mCSB_scrollTools_horizontal .mCSB_dragger .mCSB_dragger_bar,.mCS-inset-2.mCSB_scrollTools_horizontal .mCSB_dragger .mCSB_dragger_bar,.mCS-inset-3-dark.mCSB_scrollTools_horizontal .mCSB_dragger .mCSB_dragger_bar,.mCS-inset-3.mCSB_scrollTools_horizontal .mCSB_dragger .mCSB_dragger_bar,.mCS-inset-dark.mCSB_scrollTools_horizontal .mCSB_dragger .mCSB_dragger_bar,.mCS-inset.mCSB_scrollTools_horizontal .mCSB_dragger .mCSB_dragger_bar{height:6px;margin:5px 3px;position:absolute;width:auto;top:0;bottom:0;left:0;right:0}.mCS-inset-2-dark.mCSB_scrollTools_horizontal .mCSB_draggerRail,.mCS-inset-2.mCSB_scrollTools_horizontal .mCSB_draggerRail,.mCS-inset-3-dark.mCSB_scrollTools_horizontal .mCSB_draggerRail,.mCS-inset-3.mCSB_scrollTools_horizontal .mCSB_draggerRail,.mCS-inset-dark.mCSB_scrollTools_horizontal .mCSB_draggerRail,.mCS-inset.mCSB_scrollTools_horizontal .mCSB_draggerRail{width:100%;height:12px;margin:2px 0}.mCS-inset-2.mCSB_scrollTools .mCSB_buttonUp,.mCS-inset-3.mCSB_scrollTools .mCSB_buttonUp,.mCS-inset.mCSB_scrollTools .mCSB_buttonUp{background-position:-32px -72px}.mCS-inset-2.mCSB_scrollTools .mCSB_buttonDown,.mCS-inset-3.mCSB_scrollTools .mCSB_buttonDown,.mCS-inset.mCSB_scrollTools .mCSB_buttonDown{background-position:-32px -92px}.mCS-inset-2.mCSB_scrollTools .mCSB_buttonLeft,.mCS-inset-3.mCSB_scrollTools .mCSB_buttonLeft,.mCS-inset.mCSB_scrollTools .mCSB_buttonLeft{background-position:-40px -112px}.mCS-inset-2.mCSB_scrollTools .mCSB_buttonRight,.mCS-inset-3.mCSB_scrollTools .mCSB_buttonRight,.mCS-inset.mCSB_scrollTools .mCSB_buttonRight{background-position:-40px -128px}.mCS-inset-2-dark.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar,.mCS-inset-3-dark.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar,.mCS-inset-dark.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{background-color:#000;background-color:rgba(0,0,0,.75)}.mCS-inset-2-dark.mCSB_scrollTools .mCSB_dragger:hover .mCSB_dragger_bar,.mCS-inset-3-dark.mCSB_scrollTools .mCSB_dragger:hover .mCSB_dragger_bar,.mCS-inset-dark.mCSB_scrollTools .mCSB_dragger:hover .mCSB_dragger_bar{background-color:#000;background-color:rgba(0,0,0,.85)}.mCS-inset-2-dark.mCSB_scrollTools .mCSB_dragger.mCSB_dragger_onDrag .mCSB_dragger_bar,.mCS-inset-2-dark.mCSB_scrollTools .mCSB_dragger:active .mCSB_dragger_bar,.mCS-inset-3-dark.mCSB_scrollTools .mCSB_dragger.mCSB_dragger_onDrag .mCSB_dragger_bar,.mCS-inset-3-dark.mCSB_scrollTools .mCSB_dragger:active .mCSB_dragger_bar,.mCS-inset-dark.mCSB_scrollTools .mCSB_dragger.mCSB_dragger_onDrag .mCSB_dragger_bar,.mCS-inset-dark.mCSB_scrollTools .mCSB_dragger:active .mCSB_dragger_bar{background-color:#000;background-color:rgba(0,0,0,.9)}.mCS-inset-2-dark.mCSB_scrollTools .mCSB_draggerRail,.mCS-inset-3-dark.mCSB_scrollTools .mCSB_draggerRail,.mCS-inset-dark.mCSB_scrollTools .mCSB_draggerRail{background-color:#000;background-color:rgba(0,0,0,.1)}.mCS-inset-2-dark.mCSB_scrollTools .mCSB_buttonUp,.mCS-inset-3-dark.mCSB_scrollTools .mCSB_buttonUp,.mCS-inset-dark.mCSB_scrollTools .mCSB_buttonUp{background-position:-112px -72px}.mCS-inset-2-dark.mCSB_scrollTools .mCSB_buttonDown,.mCS-inset-3-dark.mCSB_scrollTools .mCSB_buttonDown,.mCS-inset-dark.mCSB_scrollTools .mCSB_buttonDown{background-position:-112px -92px}.mCS-inset-2-dark.mCSB_scrollTools .mCSB_buttonLeft,.mCS-inset-3-dark.mCSB_scrollTools .mCSB_buttonLeft,.mCS-inset-dark.mCSB_scrollTools .mCSB_buttonLeft{background-position:-120px -112px}.mCS-inset-2-dark.mCSB_scrollTools .mCSB_buttonRight,.mCS-inset-3-dark.mCSB_scrollTools .mCSB_buttonRight,.mCS-inset-dark.mCSB_scrollTools .mCSB_buttonRight{background-position:-120px -128px}.mCS-inset-2-dark.mCSB_scrollTools .mCSB_draggerRail,.mCS-inset-2.mCSB_scrollTools .mCSB_draggerRail{background-color:transparent;border-width:1px;border-style:solid;border-color:#fff;border-color:rgba(255,255,255,.2);-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.mCS-inset-2-dark.mCSB_scrollTools .mCSB_draggerRail{border-color:#000;border-color:rgba(0,0,0,.2)}.mCS-inset-3.mCSB_scrollTools .mCSB_draggerRail{background-color:#fff;background-color:rgba(255,255,255,.6)}.mCS-inset-3-dark.mCSB_scrollTools .mCSB_draggerRail{background-color:#000;background-color:rgba(0,0,0,.6)}.mCS-inset-3.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{background-color:#000;background-color:rgba(0,0,0,.75)}.mCS-inset-3.mCSB_scrollTools .mCSB_dragger:hover .mCSB_dragger_bar{background-color:#000;background-color:rgba(0,0,0,.85)}.mCS-inset-3.mCSB_scrollTools .mCSB_dragger.mCSB_dragger_onDrag .mCSB_dragger_bar,.mCS-inset-3.mCSB_scrollTools .mCSB_dragger:active .mCSB_dragger_bar{background-color:#000;background-color:rgba(0,0,0,.9)}.mCS-inset-3-dark.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{background-color:#fff;background-color:rgba(255,255,255,.75)}.mCS-inset-3-dark.mCSB_scrollTools .mCSB_dragger:hover .mCSB_dragger_bar{background-color:#fff;background-color:rgba(255,255,255,.85)}.mCS-inset-3-dark.mCSB_scrollTools .mCSB_dragger.mCSB_dragger_onDrag .mCSB_dragger_bar,.mCS-inset-3-dark.mCSB_scrollTools .mCSB_dragger:active .mCSB_dragger_bar{background-color:#fff;background-color:rgba(255,255,255,.9)}
--------------------------------------------------------------------------------
/js/paho-mqtt.js:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2013 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * and Eclipse Distribution License v1.0 which accompany this distribution.
7 | *
8 | * The Eclipse Public License is available at
9 | * http://www.eclipse.org/legal/epl-v10.html
10 | * and the Eclipse Distribution License is available at
11 | * http://www.eclipse.org/org/documents/edl-v10.php.
12 | *
13 | * Contributors:
14 | * Andrew Banks - initial API and implementation and initial documentation
15 | *******************************************************************************/
16 |
17 |
18 | // Only expose a single object name in the global namespace.
19 | // Everything must go through this module. Global Paho module
20 | // only has a single public function, client, which returns
21 | // a Paho client object given connection details.
22 |
23 | /**
24 | * Send and receive messages using web browsers.
25 | *
26 | * This programming interface lets a JavaScript client application use the MQTT V3.1 or
27 | * V3.1.1 protocol to connect to an MQTT-supporting messaging server.
28 | *
29 | * The function supported includes:
30 | *
31 | * - Connecting to and disconnecting from a server. The server is identified by its host name and port number.
32 | *
- Specifying options that relate to the communications link with the server,
33 | * for example the frequency of keep-alive heartbeats, and whether SSL/TLS is required.
34 | *
- Subscribing to and receiving messages from MQTT Topics.
35 | *
- Publishing messages to MQTT Topics.
36 | *
37 | *
38 | * The API consists of two main objects:
39 | *
40 | * - {@link Paho.Client}
41 | * - This contains methods that provide the functionality of the API,
42 | * including provision of callbacks that notify the application when a message
43 | * arrives from or is delivered to the messaging server,
44 | * or when the status of its connection to the messaging server changes.
45 | * - {@link Paho.Message}
46 | * - This encapsulates the payload of the message along with various attributes
47 | * associated with its delivery, in particular the destination to which it has
48 | * been (or is about to be) sent.
49 | *
50 | *
51 | * The programming interface validates parameters passed to it, and will throw
52 | * an Error containing an error message intended for developer use, if it detects
53 | * an error with any parameter.
54 | *
55 | * Example:
56 | *
57 | *
58 | var client = new Paho.MQTT.Client(location.hostname, Number(location.port), "clientId");
59 | client.onConnectionLost = onConnectionLost;
60 | client.onMessageArrived = onMessageArrived;
61 | client.connect({onSuccess:onConnect});
62 |
63 | function onConnect() {
64 | // Once a connection has been made, make a subscription and send a message.
65 | console.log("onConnect");
66 | client.subscribe("/World");
67 | var message = new Paho.MQTT.Message("Hello");
68 | message.destinationName = "/World";
69 | client.send(message);
70 | };
71 | function onConnectionLost(responseObject) {
72 | if (responseObject.errorCode !== 0)
73 | console.log("onConnectionLost:"+responseObject.errorMessage);
74 | };
75 | function onMessageArrived(message) {
76 | console.log("onMessageArrived:"+message.payloadString);
77 | client.disconnect();
78 | };
79 | *
80 | * @namespace Paho
81 | */
82 |
83 | /* jshint shadow:true */
84 | (function ExportLibrary(root, factory) {
85 | if(typeof exports === "object" && typeof module === "object"){
86 | module.exports = factory();
87 | } else if (typeof define === "function" && define.amd){
88 | define(factory);
89 | } else if (typeof exports === "object"){
90 | exports = factory();
91 | } else {
92 | //if (typeof root.Paho === "undefined"){
93 | // root.Paho = {};
94 | //}
95 | root.Paho = factory();
96 | }
97 | })(this, function LibraryFactory(){
98 |
99 |
100 | var PahoMQTT = (function (global) {
101 |
102 | // Private variables below, these are only visible inside the function closure
103 | // which is used to define the module.
104 | var version = "@VERSION@-@BUILDLEVEL@";
105 |
106 | /**
107 | * @private
108 | */
109 | var localStorage = global.localStorage || (function () {
110 | var data = {};
111 |
112 | return {
113 | setItem: function (key, item) { data[key] = item; },
114 | getItem: function (key) { return data[key]; },
115 | removeItem: function (key) { delete data[key]; },
116 | };
117 | })();
118 |
119 | /**
120 | * Unique message type identifiers, with associated
121 | * associated integer values.
122 | * @private
123 | */
124 | var MESSAGE_TYPE = {
125 | CONNECT: 1,
126 | CONNACK: 2,
127 | PUBLISH: 3,
128 | PUBACK: 4,
129 | PUBREC: 5,
130 | PUBREL: 6,
131 | PUBCOMP: 7,
132 | SUBSCRIBE: 8,
133 | SUBACK: 9,
134 | UNSUBSCRIBE: 10,
135 | UNSUBACK: 11,
136 | PINGREQ: 12,
137 | PINGRESP: 13,
138 | DISCONNECT: 14
139 | };
140 |
141 | // Collection of utility methods used to simplify module code
142 | // and promote the DRY pattern.
143 |
144 | /**
145 | * Validate an object's parameter names to ensure they
146 | * match a list of expected variables name for this option
147 | * type. Used to ensure option object passed into the API don't
148 | * contain erroneous parameters.
149 | * @param {Object} obj - User options object
150 | * @param {Object} keys - valid keys and types that may exist in obj.
151 | * @throws {Error} Invalid option parameter found.
152 | * @private
153 | */
154 | var validate = function(obj, keys) {
155 | for (var key in obj) {
156 | if (obj.hasOwnProperty(key)) {
157 | if (keys.hasOwnProperty(key)) {
158 | if (typeof obj[key] !== keys[key])
159 | throw new Error(format(ERROR.INVALID_TYPE, [typeof obj[key], key]));
160 | } else {
161 | var errorStr = "Unknown property, " + key + ". Valid properties are:";
162 | for (var validKey in keys)
163 | if (keys.hasOwnProperty(validKey))
164 | errorStr = errorStr+" "+validKey;
165 | throw new Error(errorStr);
166 | }
167 | }
168 | }
169 | };
170 |
171 | /**
172 | * Return a new function which runs the user function bound
173 | * to a fixed scope.
174 | * @param {function} User function
175 | * @param {object} Function scope
176 | * @return {function} User function bound to another scope
177 | * @private
178 | */
179 | var scope = function (f, scope) {
180 | return function () {
181 | return f.apply(scope, arguments);
182 | };
183 | };
184 |
185 | /**
186 | * Unique message type identifiers, with associated
187 | * associated integer values.
188 | * @private
189 | */
190 | var ERROR = {
191 | OK: {code:0, text:"AMQJSC0000I OK."},
192 | CONNECT_TIMEOUT: {code:1, text:"AMQJSC0001E Connect timed out."},
193 | SUBSCRIBE_TIMEOUT: {code:2, text:"AMQJS0002E Subscribe timed out."},
194 | UNSUBSCRIBE_TIMEOUT: {code:3, text:"AMQJS0003E Unsubscribe timed out."},
195 | PING_TIMEOUT: {code:4, text:"AMQJS0004E Ping timed out."},
196 | INTERNAL_ERROR: {code:5, text:"AMQJS0005E Internal error. Error Message: {0}, Stack trace: {1}"},
197 | CONNACK_RETURNCODE: {code:6, text:"AMQJS0006E Bad Connack return code:{0} {1}."},
198 | SOCKET_ERROR: {code:7, text:"AMQJS0007E Socket error:{0}."},
199 | SOCKET_CLOSE: {code:8, text:"AMQJS0008I Socket closed."},
200 | MALFORMED_UTF: {code:9, text:"AMQJS0009E Malformed UTF data:{0} {1} {2}."},
201 | UNSUPPORTED: {code:10, text:"AMQJS0010E {0} is not supported by this browser."},
202 | INVALID_STATE: {code:11, text:"AMQJS0011E Invalid state {0}."},
203 | INVALID_TYPE: {code:12, text:"AMQJS0012E Invalid type {0} for {1}."},
204 | INVALID_ARGUMENT: {code:13, text:"AMQJS0013E Invalid argument {0} for {1}."},
205 | UNSUPPORTED_OPERATION: {code:14, text:"AMQJS0014E Unsupported operation."},
206 | INVALID_STORED_DATA: {code:15, text:"AMQJS0015E Invalid data in local storage key={0} value={1}."},
207 | INVALID_MQTT_MESSAGE_TYPE: {code:16, text:"AMQJS0016E Invalid MQTT message type {0}."},
208 | MALFORMED_UNICODE: {code:17, text:"AMQJS0017E Malformed Unicode string:{0} {1}."},
209 | BUFFER_FULL: {code:18, text:"AMQJS0018E Message buffer is full, maximum buffer size: {0}."},
210 | };
211 |
212 | /** CONNACK RC Meaning. */
213 | var CONNACK_RC = {
214 | 0:"Connection Accepted",
215 | 1:"Connection Refused: unacceptable protocol version",
216 | 2:"Connection Refused: identifier rejected",
217 | 3:"Connection Refused: server unavailable",
218 | 4:"Connection Refused: bad user name or password",
219 | 5:"Connection Refused: not authorized"
220 | };
221 |
222 | /**
223 | * Format an error message text.
224 | * @private
225 | * @param {error} ERROR value above.
226 | * @param {substitutions} [array] substituted into the text.
227 | * @return the text with the substitutions made.
228 | */
229 | var format = function(error, substitutions) {
230 | var text = error.text;
231 | if (substitutions) {
232 | var field,start;
233 | for (var i=0; i 0) {
237 | var part1 = text.substring(0,start);
238 | var part2 = text.substring(start+field.length);
239 | text = part1+substitutions[i]+part2;
240 | }
241 | }
242 | }
243 | return text;
244 | };
245 |
246 | //MQTT protocol and version 6 M Q I s d p 3
247 | var MqttProtoIdentifierv3 = [0x00,0x06,0x4d,0x51,0x49,0x73,0x64,0x70,0x03];
248 | //MQTT proto/version for 311 4 M Q T T 4
249 | var MqttProtoIdentifierv4 = [0x00,0x04,0x4d,0x51,0x54,0x54,0x04];
250 |
251 | /**
252 | * Construct an MQTT wire protocol message.
253 | * @param type MQTT packet type.
254 | * @param options optional wire message attributes.
255 | *
256 | * Optional properties
257 | *
258 | * messageIdentifier: message ID in the range [0..65535]
259 | * payloadMessage: Application Message - PUBLISH only
260 | * connectStrings: array of 0 or more Strings to be put into the CONNECT payload
261 | * topics: array of strings (SUBSCRIBE, UNSUBSCRIBE)
262 | * requestQoS: array of QoS values [0..2]
263 | *
264 | * "Flag" properties
265 | * cleanSession: true if present / false if absent (CONNECT)
266 | * willMessage: true if present / false if absent (CONNECT)
267 | * isRetained: true if present / false if absent (CONNECT)
268 | * userName: true if present / false if absent (CONNECT)
269 | * password: true if present / false if absent (CONNECT)
270 | * keepAliveInterval: integer [0..65535] (CONNECT)
271 | *
272 | * @private
273 | * @ignore
274 | */
275 | var WireMessage = function (type, options) {
276 | this.type = type;
277 | for (var name in options) {
278 | if (options.hasOwnProperty(name)) {
279 | this[name] = options[name];
280 | }
281 | }
282 | };
283 |
284 | WireMessage.prototype.encode = function() {
285 | // Compute the first byte of the fixed header
286 | var first = ((this.type & 0x0f) << 4);
287 |
288 | /*
289 | * Now calculate the length of the variable header + payload by adding up the lengths
290 | * of all the component parts
291 | */
292 |
293 | var remLength = 0;
294 | var topicStrLength = [];
295 | var destinationNameLength = 0;
296 | var willMessagePayloadBytes;
297 |
298 | // if the message contains a messageIdentifier then we need two bytes for that
299 | if (this.messageIdentifier !== undefined)
300 | remLength += 2;
301 |
302 | switch(this.type) {
303 | // If this a Connect then we need to include 12 bytes for its header
304 | case MESSAGE_TYPE.CONNECT:
305 | switch(this.mqttVersion) {
306 | case 3:
307 | remLength += MqttProtoIdentifierv3.length + 3;
308 | break;
309 | case 4:
310 | remLength += MqttProtoIdentifierv4.length + 3;
311 | break;
312 | }
313 |
314 | remLength += UTF8Length(this.clientId) + 2;
315 | if (this.willMessage !== undefined) {
316 | remLength += UTF8Length(this.willMessage.destinationName) + 2;
317 | // Will message is always a string, sent as UTF-8 characters with a preceding length.
318 | willMessagePayloadBytes = this.willMessage.payloadBytes;
319 | if (!(willMessagePayloadBytes instanceof Uint8Array))
320 | willMessagePayloadBytes = new Uint8Array(payloadBytes);
321 | remLength += willMessagePayloadBytes.byteLength +2;
322 | }
323 | if (this.userName !== undefined)
324 | remLength += UTF8Length(this.userName) + 2;
325 | if (this.password !== undefined)
326 | remLength += UTF8Length(this.password) + 2;
327 | break;
328 |
329 | // Subscribe, Unsubscribe can both contain topic strings
330 | case MESSAGE_TYPE.SUBSCRIBE:
331 | first |= 0x02; // Qos = 1;
332 | for ( var i = 0; i < this.topics.length; i++) {
333 | topicStrLength[i] = UTF8Length(this.topics[i]);
334 | remLength += topicStrLength[i] + 2;
335 | }
336 | remLength += this.requestedQos.length; // 1 byte for each topic's Qos
337 | // QoS on Subscribe only
338 | break;
339 |
340 | case MESSAGE_TYPE.UNSUBSCRIBE:
341 | first |= 0x02; // Qos = 1;
342 | for ( var i = 0; i < this.topics.length; i++) {
343 | topicStrLength[i] = UTF8Length(this.topics[i]);
344 | remLength += topicStrLength[i] + 2;
345 | }
346 | break;
347 |
348 | case MESSAGE_TYPE.PUBREL:
349 | first |= 0x02; // Qos = 1;
350 | break;
351 |
352 | case MESSAGE_TYPE.PUBLISH:
353 | if (this.payloadMessage.duplicate) first |= 0x08;
354 | first = first |= (this.payloadMessage.qos << 1);
355 | if (this.payloadMessage.retained) first |= 0x01;
356 | destinationNameLength = UTF8Length(this.payloadMessage.destinationName);
357 | remLength += destinationNameLength + 2;
358 | var payloadBytes = this.payloadMessage.payloadBytes;
359 | remLength += payloadBytes.byteLength;
360 | if (payloadBytes instanceof ArrayBuffer)
361 | payloadBytes = new Uint8Array(payloadBytes);
362 | else if (!(payloadBytes instanceof Uint8Array))
363 | payloadBytes = new Uint8Array(payloadBytes.buffer);
364 | break;
365 |
366 | case MESSAGE_TYPE.DISCONNECT:
367 | break;
368 |
369 | default:
370 | break;
371 | }
372 |
373 | // Now we can allocate a buffer for the message
374 |
375 | var mbi = encodeMBI(remLength); // Convert the length to MQTT MBI format
376 | var pos = mbi.length + 1; // Offset of start of variable header
377 | var buffer = new ArrayBuffer(remLength + pos);
378 | var byteStream = new Uint8Array(buffer); // view it as a sequence of bytes
379 |
380 | //Write the fixed header into the buffer
381 | byteStream[0] = first;
382 | byteStream.set(mbi,1);
383 |
384 | // If this is a PUBLISH then the variable header starts with a topic
385 | if (this.type == MESSAGE_TYPE.PUBLISH)
386 | pos = writeString(this.payloadMessage.destinationName, destinationNameLength, byteStream, pos);
387 | // If this is a CONNECT then the variable header contains the protocol name/version, flags and keepalive time
388 |
389 | else if (this.type == MESSAGE_TYPE.CONNECT) {
390 | switch (this.mqttVersion) {
391 | case 3:
392 | byteStream.set(MqttProtoIdentifierv3, pos);
393 | pos += MqttProtoIdentifierv3.length;
394 | break;
395 | case 4:
396 | byteStream.set(MqttProtoIdentifierv4, pos);
397 | pos += MqttProtoIdentifierv4.length;
398 | break;
399 | }
400 | var connectFlags = 0;
401 | if (this.cleanSession)
402 | connectFlags = 0x02;
403 | if (this.willMessage !== undefined ) {
404 | connectFlags |= 0x04;
405 | connectFlags |= (this.willMessage.qos<<3);
406 | if (this.willMessage.retained) {
407 | connectFlags |= 0x20;
408 | }
409 | }
410 | if (this.userName !== undefined)
411 | connectFlags |= 0x80;
412 | if (this.password !== undefined)
413 | connectFlags |= 0x40;
414 | byteStream[pos++] = connectFlags;
415 | pos = writeUint16 (this.keepAliveInterval, byteStream, pos);
416 | }
417 |
418 | // Output the messageIdentifier - if there is one
419 | if (this.messageIdentifier !== undefined)
420 | pos = writeUint16 (this.messageIdentifier, byteStream, pos);
421 |
422 | switch(this.type) {
423 | case MESSAGE_TYPE.CONNECT:
424 | pos = writeString(this.clientId, UTF8Length(this.clientId), byteStream, pos);
425 | if (this.willMessage !== undefined) {
426 | pos = writeString(this.willMessage.destinationName, UTF8Length(this.willMessage.destinationName), byteStream, pos);
427 | pos = writeUint16(willMessagePayloadBytes.byteLength, byteStream, pos);
428 | byteStream.set(willMessagePayloadBytes, pos);
429 | pos += willMessagePayloadBytes.byteLength;
430 |
431 | }
432 | if (this.userName !== undefined)
433 | pos = writeString(this.userName, UTF8Length(this.userName), byteStream, pos);
434 | if (this.password !== undefined)
435 | pos = writeString(this.password, UTF8Length(this.password), byteStream, pos);
436 | break;
437 |
438 | case MESSAGE_TYPE.PUBLISH:
439 | // PUBLISH has a text or binary payload, if text do not add a 2 byte length field, just the UTF characters.
440 | byteStream.set(payloadBytes, pos);
441 |
442 | break;
443 |
444 | // case MESSAGE_TYPE.PUBREC:
445 | // case MESSAGE_TYPE.PUBREL:
446 | // case MESSAGE_TYPE.PUBCOMP:
447 | // break;
448 |
449 | case MESSAGE_TYPE.SUBSCRIBE:
450 | // SUBSCRIBE has a list of topic strings and request QoS
451 | for (var i=0; i> 4;
474 | var messageInfo = first &= 0x0f;
475 | pos += 1;
476 |
477 |
478 | // Decode the remaining length (MBI format)
479 |
480 | var digit;
481 | var remLength = 0;
482 | var multiplier = 1;
483 | do {
484 | if (pos == input.length) {
485 | return [null,startingPos];
486 | }
487 | digit = input[pos++];
488 | remLength += ((digit & 0x7F) * multiplier);
489 | multiplier *= 128;
490 | } while ((digit & 0x80) !== 0);
491 |
492 | var endPos = pos+remLength;
493 | if (endPos > input.length) {
494 | return [null,startingPos];
495 | }
496 |
497 | var wireMessage = new WireMessage(type);
498 | switch(type) {
499 | case MESSAGE_TYPE.CONNACK:
500 | var connectAcknowledgeFlags = input[pos++];
501 | if (connectAcknowledgeFlags & 0x01)
502 | wireMessage.sessionPresent = true;
503 | wireMessage.returnCode = input[pos++];
504 | break;
505 |
506 | case MESSAGE_TYPE.PUBLISH:
507 | var qos = (messageInfo >> 1) & 0x03;
508 |
509 | var len = readUint16(input, pos);
510 | pos += 2;
511 | var topicName = parseUTF8(input, pos, len);
512 | pos += len;
513 | // If QoS 1 or 2 there will be a messageIdentifier
514 | if (qos > 0) {
515 | wireMessage.messageIdentifier = readUint16(input, pos);
516 | pos += 2;
517 | }
518 |
519 | var message = new Message(input.subarray(pos, endPos));
520 | if ((messageInfo & 0x01) == 0x01)
521 | message.retained = true;
522 | if ((messageInfo & 0x08) == 0x08)
523 | message.duplicate = true;
524 | message.qos = qos;
525 | message.destinationName = topicName;
526 | wireMessage.payloadMessage = message;
527 | break;
528 |
529 | case MESSAGE_TYPE.PUBACK:
530 | case MESSAGE_TYPE.PUBREC:
531 | case MESSAGE_TYPE.PUBREL:
532 | case MESSAGE_TYPE.PUBCOMP:
533 | case MESSAGE_TYPE.UNSUBACK:
534 | wireMessage.messageIdentifier = readUint16(input, pos);
535 | break;
536 |
537 | case MESSAGE_TYPE.SUBACK:
538 | wireMessage.messageIdentifier = readUint16(input, pos);
539 | pos += 2;
540 | wireMessage.returnCode = input.subarray(pos, endPos);
541 | break;
542 |
543 | default:
544 | break;
545 | }
546 |
547 | return [wireMessage,endPos];
548 | }
549 |
550 | function writeUint16(input, buffer, offset) {
551 | buffer[offset++] = input >> 8; //MSB
552 | buffer[offset++] = input % 256; //LSB
553 | return offset;
554 | }
555 |
556 | function writeString(input, utf8Length, buffer, offset) {
557 | offset = writeUint16(utf8Length, buffer, offset);
558 | stringToUTF8(input, buffer, offset);
559 | return offset + utf8Length;
560 | }
561 |
562 | function readUint16(buffer, offset) {
563 | return 256*buffer[offset] + buffer[offset+1];
564 | }
565 |
566 | /**
567 | * Encodes an MQTT Multi-Byte Integer
568 | * @private
569 | */
570 | function encodeMBI(number) {
571 | var output = new Array(1);
572 | var numBytes = 0;
573 |
574 | do {
575 | var digit = number % 128;
576 | number = number >> 7;
577 | if (number > 0) {
578 | digit |= 0x80;
579 | }
580 | output[numBytes++] = digit;
581 | } while ( (number > 0) && (numBytes<4) );
582 |
583 | return output;
584 | }
585 |
586 | /**
587 | * Takes a String and calculates its length in bytes when encoded in UTF8.
588 | * @private
589 | */
590 | function UTF8Length(input) {
591 | var output = 0;
592 | for (var i = 0; i 0x7FF)
596 | {
597 | // Surrogate pair means its a 4 byte character
598 | if (0xD800 <= charCode && charCode <= 0xDBFF)
599 | {
600 | i++;
601 | output++;
602 | }
603 | output +=3;
604 | }
605 | else if (charCode > 0x7F)
606 | output +=2;
607 | else
608 | output++;
609 | }
610 | return output;
611 | }
612 |
613 | /**
614 | * Takes a String and writes it into an array as UTF8 encoded bytes.
615 | * @private
616 | */
617 | function stringToUTF8(input, output, start) {
618 | var pos = start;
619 | for (var i = 0; i>6 & 0x1F | 0xC0;
636 | output[pos++] = charCode & 0x3F | 0x80;
637 | } else if (charCode <= 0xFFFF) {
638 | output[pos++] = charCode>>12 & 0x0F | 0xE0;
639 | output[pos++] = charCode>>6 & 0x3F | 0x80;
640 | output[pos++] = charCode & 0x3F | 0x80;
641 | } else {
642 | output[pos++] = charCode>>18 & 0x07 | 0xF0;
643 | output[pos++] = charCode>>12 & 0x3F | 0x80;
644 | output[pos++] = charCode>>6 & 0x3F | 0x80;
645 | output[pos++] = charCode & 0x3F | 0x80;
646 | }
647 | }
648 | return output;
649 | }
650 |
651 | function parseUTF8(input, offset, length) {
652 | var output = "";
653 | var utf16;
654 | var pos = offset;
655 |
656 | while (pos < offset+length)
657 | {
658 | var byte1 = input[pos++];
659 | if (byte1 < 128)
660 | utf16 = byte1;
661 | else
662 | {
663 | var byte2 = input[pos++]-128;
664 | if (byte2 < 0)
665 | throw new Error(format(ERROR.MALFORMED_UTF, [byte1.toString(16), byte2.toString(16),""]));
666 | if (byte1 < 0xE0) // 2 byte character
667 | utf16 = 64*(byte1-0xC0) + byte2;
668 | else
669 | {
670 | var byte3 = input[pos++]-128;
671 | if (byte3 < 0)
672 | throw new Error(format(ERROR.MALFORMED_UTF, [byte1.toString(16), byte2.toString(16), byte3.toString(16)]));
673 | if (byte1 < 0xF0) // 3 byte character
674 | utf16 = 4096*(byte1-0xE0) + 64*byte2 + byte3;
675 | else
676 | {
677 | var byte4 = input[pos++]-128;
678 | if (byte4 < 0)
679 | throw new Error(format(ERROR.MALFORMED_UTF, [byte1.toString(16), byte2.toString(16), byte3.toString(16), byte4.toString(16)]));
680 | if (byte1 < 0xF8) // 4 byte character
681 | utf16 = 262144*(byte1-0xF0) + 4096*byte2 + 64*byte3 + byte4;
682 | else // longer encodings are not supported
683 | throw new Error(format(ERROR.MALFORMED_UTF, [byte1.toString(16), byte2.toString(16), byte3.toString(16), byte4.toString(16)]));
684 | }
685 | }
686 | }
687 |
688 | if (utf16 > 0xFFFF) // 4 byte character - express as a surrogate pair
689 | {
690 | utf16 -= 0x10000;
691 | output += String.fromCharCode(0xD800 + (utf16 >> 10)); // lead character
692 | utf16 = 0xDC00 + (utf16 & 0x3FF); // trail character
693 | }
694 | output += String.fromCharCode(utf16);
695 | }
696 | return output;
697 | }
698 |
699 | /**
700 | * Repeat keepalive requests, monitor responses.
701 | * @ignore
702 | */
703 | var Pinger = function(client, keepAliveInterval) {
704 | this._client = client;
705 | this._keepAliveInterval = keepAliveInterval*1000;
706 | this.isReset = false;
707 |
708 | var pingReq = new WireMessage(MESSAGE_TYPE.PINGREQ).encode();
709 |
710 | var doTimeout = function (pinger) {
711 | return function () {
712 | return doPing.apply(pinger);
713 | };
714 | };
715 |
716 | /** @ignore */
717 | var doPing = function() {
718 | if (!this.isReset) {
719 | this._client._trace("Pinger.doPing", "Timed out");
720 | this._client._disconnected( ERROR.PING_TIMEOUT.code , format(ERROR.PING_TIMEOUT));
721 | } else {
722 | this.isReset = false;
723 | this._client._trace("Pinger.doPing", "send PINGREQ");
724 | this._client.socket.send(pingReq);
725 | this.timeout = setTimeout(doTimeout(this), this._keepAliveInterval);
726 | }
727 | };
728 |
729 | this.reset = function() {
730 | this.isReset = true;
731 | clearTimeout(this.timeout);
732 | if (this._keepAliveInterval > 0)
733 | this.timeout = setTimeout(doTimeout(this), this._keepAliveInterval);
734 | };
735 |
736 | this.cancel = function() {
737 | clearTimeout(this.timeout);
738 | };
739 | };
740 |
741 | /**
742 | * Monitor request completion.
743 | * @ignore
744 | */
745 | var Timeout = function(client, timeoutSeconds, action, args) {
746 | if (!timeoutSeconds)
747 | timeoutSeconds = 30;
748 |
749 | var doTimeout = function (action, client, args) {
750 | return function () {
751 | return action.apply(client, args);
752 | };
753 | };
754 | this.timeout = setTimeout(doTimeout(action, client, args), timeoutSeconds * 1000);
755 |
756 | this.cancel = function() {
757 | clearTimeout(this.timeout);
758 | };
759 | };
760 |
761 | /**
762 | * Internal implementation of the Websockets MQTT V3.1 client.
763 | *
764 | * @name Paho.ClientImpl @constructor
765 | * @param {String} host the DNS nameof the webSocket host.
766 | * @param {Number} port the port number for that host.
767 | * @param {String} clientId the MQ client identifier.
768 | */
769 | var ClientImpl = function (uri, host, port, path, clientId) {
770 | // Check dependencies are satisfied in this browser.
771 | if (!("WebSocket" in global && global.WebSocket !== null)) {
772 | throw new Error(format(ERROR.UNSUPPORTED, ["WebSocket"]));
773 | }
774 | if (!("ArrayBuffer" in global && global.ArrayBuffer !== null)) {
775 | throw new Error(format(ERROR.UNSUPPORTED, ["ArrayBuffer"]));
776 | }
777 | this._trace("Paho.Client", uri, host, port, path, clientId);
778 |
779 | this.host = host;
780 | this.port = port;
781 | this.path = path;
782 | this.uri = uri;
783 | this.clientId = clientId;
784 | this._wsuri = null;
785 |
786 | // Local storagekeys are qualified with the following string.
787 | // The conditional inclusion of path in the key is for backward
788 | // compatibility to when the path was not configurable and assumed to
789 | // be /mqtt
790 | this._localKey=host+":"+port+(path!="/mqtt"?":"+path:"")+":"+clientId+":";
791 |
792 | // Create private instance-only message queue
793 | // Internal queue of messages to be sent, in sending order.
794 | this._msg_queue = [];
795 | this._buffered_msg_queue = [];
796 |
797 | // Messages we have sent and are expecting a response for, indexed by their respective message ids.
798 | this._sentMessages = {};
799 |
800 | // Messages we have received and acknowleged and are expecting a confirm message for
801 | // indexed by their respective message ids.
802 | this._receivedMessages = {};
803 |
804 | // Internal list of callbacks to be executed when messages
805 | // have been successfully sent over web socket, e.g. disconnect
806 | // when it doesn't have to wait for ACK, just message is dispatched.
807 | this._notify_msg_sent = {};
808 |
809 | // Unique identifier for SEND messages, incrementing
810 | // counter as messages are sent.
811 | this._message_identifier = 1;
812 |
813 | // Used to determine the transmission sequence of stored sent messages.
814 | this._sequence = 0;
815 |
816 |
817 | // Load the local state, if any, from the saved version, only restore state relevant to this client.
818 | for (var key in localStorage)
819 | if ( key.indexOf("Sent:"+this._localKey) === 0 || key.indexOf("Received:"+this._localKey) === 0)
820 | this.restore(key);
821 | };
822 |
823 | // Messaging Client public instance members.
824 | ClientImpl.prototype.host = null;
825 | ClientImpl.prototype.port = null;
826 | ClientImpl.prototype.path = null;
827 | ClientImpl.prototype.uri = null;
828 | ClientImpl.prototype.clientId = null;
829 |
830 | // Messaging Client private instance members.
831 | ClientImpl.prototype.socket = null;
832 | /* true once we have received an acknowledgement to a CONNECT packet. */
833 | ClientImpl.prototype.connected = false;
834 | /* The largest message identifier allowed, may not be larger than 2**16 but
835 | * if set smaller reduces the maximum number of outbound messages allowed.
836 | */
837 | ClientImpl.prototype.maxMessageIdentifier = 65536;
838 | ClientImpl.prototype.connectOptions = null;
839 | ClientImpl.prototype.hostIndex = null;
840 | ClientImpl.prototype.onConnected = null;
841 | ClientImpl.prototype.onConnectionLost = null;
842 | ClientImpl.prototype.onMessageDelivered = null;
843 | ClientImpl.prototype.onMessageArrived = null;
844 | ClientImpl.prototype.traceFunction = null;
845 | ClientImpl.prototype._msg_queue = null;
846 | ClientImpl.prototype._buffered_msg_queue = null;
847 | ClientImpl.prototype._connectTimeout = null;
848 | /* The sendPinger monitors how long we allow before we send data to prove to the server that we are alive. */
849 | ClientImpl.prototype.sendPinger = null;
850 | /* The receivePinger monitors how long we allow before we require evidence that the server is alive. */
851 | ClientImpl.prototype.receivePinger = null;
852 | ClientImpl.prototype._reconnectInterval = 1; // Reconnect Delay, starts at 1 second
853 | ClientImpl.prototype._reconnecting = false;
854 | ClientImpl.prototype._reconnectTimeout = null;
855 | ClientImpl.prototype.disconnectedPublishing = false;
856 | ClientImpl.prototype.disconnectedBufferSize = 5000;
857 |
858 | ClientImpl.prototype.receiveBuffer = null;
859 |
860 | ClientImpl.prototype._traceBuffer = null;
861 | ClientImpl.prototype._MAX_TRACE_ENTRIES = 100;
862 |
863 | ClientImpl.prototype.connect = function (connectOptions) {
864 | var connectOptionsMasked = this._traceMask(connectOptions, "password");
865 | this._trace("Client.connect", connectOptionsMasked, this.socket, this.connected);
866 |
867 | if (this.connected)
868 | throw new Error(format(ERROR.INVALID_STATE, ["already connected"]));
869 | if (this.socket)
870 | throw new Error(format(ERROR.INVALID_STATE, ["already connected"]));
871 |
872 | if (this._reconnecting) {
873 | // connect() function is called while reconnect is in progress.
874 | // Terminate the auto reconnect process to use new connect options.
875 | this._reconnectTimeout.cancel();
876 | this._reconnectTimeout = null;
877 | this._reconnecting = false;
878 | }
879 |
880 | this.connectOptions = connectOptions;
881 | this._reconnectInterval = 1;
882 | this._reconnecting = false;
883 | if (connectOptions.uris) {
884 | this.hostIndex = 0;
885 | this._doConnect(connectOptions.uris[0]);
886 | } else {
887 | this._doConnect(this.uri);
888 | }
889 |
890 | };
891 |
892 | ClientImpl.prototype.subscribe = function (filter, subscribeOptions) {
893 | this._trace("Client.subscribe", filter, subscribeOptions);
894 |
895 | if (!this.connected)
896 | throw new Error(format(ERROR.INVALID_STATE, ["not connected"]));
897 |
898 | var wireMessage = new WireMessage(MESSAGE_TYPE.SUBSCRIBE);
899 | wireMessage.topics = filter.constructor === Array ? filter : [filter];
900 | if (subscribeOptions.qos === undefined)
901 | subscribeOptions.qos = 0;
902 | wireMessage.requestedQos = [];
903 | for (var i = 0; i < wireMessage.topics.length; i++)
904 | wireMessage.requestedQos[i] = subscribeOptions.qos;
905 |
906 | if (subscribeOptions.onSuccess) {
907 | wireMessage.onSuccess = function(grantedQos) {subscribeOptions.onSuccess({invocationContext:subscribeOptions.invocationContext,grantedQos:grantedQos});};
908 | }
909 |
910 | if (subscribeOptions.onFailure) {
911 | wireMessage.onFailure = function(errorCode) {subscribeOptions.onFailure({invocationContext:subscribeOptions.invocationContext,errorCode:errorCode, errorMessage:format(errorCode)});};
912 | }
913 |
914 | if (subscribeOptions.timeout) {
915 | wireMessage.timeOut = new Timeout(this, subscribeOptions.timeout, subscribeOptions.onFailure,
916 | [{invocationContext:subscribeOptions.invocationContext,
917 | errorCode:ERROR.SUBSCRIBE_TIMEOUT.code,
918 | errorMessage:format(ERROR.SUBSCRIBE_TIMEOUT)}]);
919 | }
920 |
921 | // All subscriptions return a SUBACK.
922 | this._requires_ack(wireMessage);
923 | this._schedule_message(wireMessage);
924 | };
925 |
926 | /** @ignore */
927 | ClientImpl.prototype.unsubscribe = function(filter, unsubscribeOptions) {
928 | this._trace("Client.unsubscribe", filter, unsubscribeOptions);
929 |
930 | if (!this.connected)
931 | throw new Error(format(ERROR.INVALID_STATE, ["not connected"]));
932 |
933 | var wireMessage = new WireMessage(MESSAGE_TYPE.UNSUBSCRIBE);
934 | wireMessage.topics = filter.constructor === Array ? filter : [filter];
935 |
936 | if (unsubscribeOptions.onSuccess) {
937 | wireMessage.callback = function() {unsubscribeOptions.onSuccess({invocationContext:unsubscribeOptions.invocationContext});};
938 | }
939 | if (unsubscribeOptions.timeout) {
940 | wireMessage.timeOut = new Timeout(this, unsubscribeOptions.timeout, unsubscribeOptions.onFailure,
941 | [{invocationContext:unsubscribeOptions.invocationContext,
942 | errorCode:ERROR.UNSUBSCRIBE_TIMEOUT.code,
943 | errorMessage:format(ERROR.UNSUBSCRIBE_TIMEOUT)}]);
944 | }
945 |
946 | // All unsubscribes return a SUBACK.
947 | this._requires_ack(wireMessage);
948 | this._schedule_message(wireMessage);
949 | };
950 |
951 | ClientImpl.prototype.send = function (message) {
952 | this._trace("Client.send", message);
953 |
954 | var wireMessage = new WireMessage(MESSAGE_TYPE.PUBLISH);
955 | wireMessage.payloadMessage = message;
956 |
957 | if (this.connected) {
958 | // Mark qos 1 & 2 message as "ACK required"
959 | // For qos 0 message, invoke onMessageDelivered callback if there is one.
960 | // Then schedule the message.
961 | if (message.qos > 0) {
962 | this._requires_ack(wireMessage);
963 | } else if (this.onMessageDelivered) {
964 | this._notify_msg_sent[wireMessage] = this.onMessageDelivered(wireMessage.payloadMessage);
965 | }
966 | this._schedule_message(wireMessage);
967 | } else {
968 | // Currently disconnected, will not schedule this message
969 | // Check if reconnecting is in progress and disconnected publish is enabled.
970 | if (this._reconnecting && this.disconnectedPublishing) {
971 | // Check the limit which include the "required ACK" messages
972 | var messageCount = Object.keys(this._sentMessages).length + this._buffered_msg_queue.length;
973 | if (messageCount > this.disconnectedBufferSize) {
974 | throw new Error(format(ERROR.BUFFER_FULL, [this.disconnectedBufferSize]));
975 | } else {
976 | if (message.qos > 0) {
977 | // Mark this message as "ACK required"
978 | this._requires_ack(wireMessage);
979 | } else {
980 | wireMessage.sequence = ++this._sequence;
981 | // Add messages in fifo order to array, by adding to start
982 | this._buffered_msg_queue.unshift(wireMessage);
983 | }
984 | }
985 | } else {
986 | throw new Error(format(ERROR.INVALID_STATE, ["not connected"]));
987 | }
988 | }
989 | };
990 |
991 | ClientImpl.prototype.disconnect = function () {
992 | this._trace("Client.disconnect");
993 |
994 | if (this._reconnecting) {
995 | // disconnect() function is called while reconnect is in progress.
996 | // Terminate the auto reconnect process.
997 | this._reconnectTimeout.cancel();
998 | this._reconnectTimeout = null;
999 | this._reconnecting = false;
1000 | }
1001 |
1002 | if (!this.socket)
1003 | throw new Error(format(ERROR.INVALID_STATE, ["not connecting or connected"]));
1004 |
1005 | var wireMessage = new WireMessage(MESSAGE_TYPE.DISCONNECT);
1006 |
1007 | // Run the disconnected call back as soon as the message has been sent,
1008 | // in case of a failure later on in the disconnect processing.
1009 | // as a consequence, the _disconected call back may be run several times.
1010 | this._notify_msg_sent[wireMessage] = scope(this._disconnected, this);
1011 |
1012 | this._schedule_message(wireMessage);
1013 | };
1014 |
1015 | ClientImpl.prototype.getTraceLog = function () {
1016 | if ( this._traceBuffer !== null ) {
1017 | this._trace("Client.getTraceLog", new Date());
1018 | this._trace("Client.getTraceLog in flight messages", this._sentMessages.length);
1019 | for (var key in this._sentMessages)
1020 | this._trace("_sentMessages ",key, this._sentMessages[key]);
1021 | for (var key in this._receivedMessages)
1022 | this._trace("_receivedMessages ",key, this._receivedMessages[key]);
1023 |
1024 | return this._traceBuffer;
1025 | }
1026 | };
1027 |
1028 | ClientImpl.prototype.startTrace = function () {
1029 | if ( this._traceBuffer === null ) {
1030 | this._traceBuffer = [];
1031 | }
1032 | this._trace("Client.startTrace", new Date(), version);
1033 | };
1034 |
1035 | ClientImpl.prototype.stopTrace = function () {
1036 | delete this._traceBuffer;
1037 | };
1038 |
1039 | ClientImpl.prototype._doConnect = function (wsurl) {
1040 | // When the socket is open, this client will send the CONNECT WireMessage using the saved parameters.
1041 | if (this.connectOptions.useSSL) {
1042 | var uriParts = wsurl.split(":");
1043 | uriParts[0] = "wss";
1044 | wsurl = uriParts.join(":");
1045 | }
1046 | this._wsuri = wsurl;
1047 | this.connected = false;
1048 |
1049 |
1050 |
1051 | if (this.connectOptions.mqttVersion < 4) {
1052 | this.socket = new WebSocket(wsurl, ["mqttv3.1"]);
1053 | } else {
1054 | this.socket = new WebSocket(wsurl, ["mqtt"]);
1055 | }
1056 | this.socket.binaryType = "arraybuffer";
1057 | this.socket.onopen = scope(this._on_socket_open, this);
1058 | this.socket.onmessage = scope(this._on_socket_message, this);
1059 | this.socket.onerror = scope(this._on_socket_error, this);
1060 | this.socket.onclose = scope(this._on_socket_close, this);
1061 |
1062 | this.sendPinger = new Pinger(this, this.connectOptions.keepAliveInterval);
1063 | this.receivePinger = new Pinger(this, this.connectOptions.keepAliveInterval);
1064 | if (this._connectTimeout) {
1065 | this._connectTimeout.cancel();
1066 | this._connectTimeout = null;
1067 | }
1068 | this._connectTimeout = new Timeout(this, this.connectOptions.timeout, this._disconnected, [ERROR.CONNECT_TIMEOUT.code, format(ERROR.CONNECT_TIMEOUT)]);
1069 | };
1070 |
1071 |
1072 | // Schedule a new message to be sent over the WebSockets
1073 | // connection. CONNECT messages cause WebSocket connection
1074 | // to be started. All other messages are queued internally
1075 | // until this has happened. When WS connection starts, process
1076 | // all outstanding messages.
1077 | ClientImpl.prototype._schedule_message = function (message) {
1078 | // Add messages in fifo order to array, by adding to start
1079 | this._msg_queue.unshift(message);
1080 | // Process outstanding messages in the queue if we have an open socket, and have received CONNACK.
1081 | if (this.connected) {
1082 | this._process_queue();
1083 | }
1084 | };
1085 |
1086 | ClientImpl.prototype.store = function(prefix, wireMessage) {
1087 | var storedMessage = {type:wireMessage.type, messageIdentifier:wireMessage.messageIdentifier, version:1};
1088 |
1089 | switch(wireMessage.type) {
1090 | case MESSAGE_TYPE.PUBLISH:
1091 | if(wireMessage.pubRecReceived)
1092 | storedMessage.pubRecReceived = true;
1093 |
1094 | // Convert the payload to a hex string.
1095 | storedMessage.payloadMessage = {};
1096 | var hex = "";
1097 | var messageBytes = wireMessage.payloadMessage.payloadBytes;
1098 | for (var i=0; i= 2) {
1141 | var x = parseInt(hex.substring(0, 2), 16);
1142 | hex = hex.substring(2, hex.length);
1143 | byteStream[i++] = x;
1144 | }
1145 | var payloadMessage = new Message(byteStream);
1146 |
1147 | payloadMessage.qos = storedMessage.payloadMessage.qos;
1148 | payloadMessage.destinationName = storedMessage.payloadMessage.destinationName;
1149 | if (storedMessage.payloadMessage.duplicate)
1150 | payloadMessage.duplicate = true;
1151 | if (storedMessage.payloadMessage.retained)
1152 | payloadMessage.retained = true;
1153 | wireMessage.payloadMessage = payloadMessage;
1154 |
1155 | break;
1156 |
1157 | default:
1158 | throw Error(format(ERROR.INVALID_STORED_DATA, [key, value]));
1159 | }
1160 |
1161 | if (key.indexOf("Sent:"+this._localKey) === 0) {
1162 | wireMessage.payloadMessage.duplicate = true;
1163 | this._sentMessages[wireMessage.messageIdentifier] = wireMessage;
1164 | } else if (key.indexOf("Received:"+this._localKey) === 0) {
1165 | this._receivedMessages[wireMessage.messageIdentifier] = wireMessage;
1166 | }
1167 | };
1168 |
1169 | ClientImpl.prototype._process_queue = function () {
1170 | var message = null;
1171 |
1172 | // Send all queued messages down socket connection
1173 | while ((message = this._msg_queue.pop())) {
1174 | this._socket_send(message);
1175 | // Notify listeners that message was successfully sent
1176 | if (this._notify_msg_sent[message]) {
1177 | this._notify_msg_sent[message]();
1178 | delete this._notify_msg_sent[message];
1179 | }
1180 | }
1181 | };
1182 |
1183 | /**
1184 | * Expect an ACK response for this message. Add message to the set of in progress
1185 | * messages and set an unused identifier in this message.
1186 | * @ignore
1187 | */
1188 | ClientImpl.prototype._requires_ack = function (wireMessage) {
1189 | var messageCount = Object.keys(this._sentMessages).length;
1190 | if (messageCount > this.maxMessageIdentifier)
1191 | throw Error ("Too many messages:"+messageCount);
1192 |
1193 | while(this._sentMessages[this._message_identifier] !== undefined) {
1194 | this._message_identifier++;
1195 | }
1196 | wireMessage.messageIdentifier = this._message_identifier;
1197 | this._sentMessages[wireMessage.messageIdentifier] = wireMessage;
1198 | if (wireMessage.type === MESSAGE_TYPE.PUBLISH) {
1199 | this.store("Sent:", wireMessage);
1200 | }
1201 | if (this._message_identifier === this.maxMessageIdentifier) {
1202 | this._message_identifier = 1;
1203 | }
1204 | };
1205 |
1206 | /**
1207 | * Called when the underlying websocket has been opened.
1208 | * @ignore
1209 | */
1210 | ClientImpl.prototype._on_socket_open = function () {
1211 | // Create the CONNECT message object.
1212 | var wireMessage = new WireMessage(MESSAGE_TYPE.CONNECT, this.connectOptions);
1213 | wireMessage.clientId = this.clientId;
1214 | this._socket_send(wireMessage);
1215 | };
1216 |
1217 | /**
1218 | * Called when the underlying websocket has received a complete packet.
1219 | * @ignore
1220 | */
1221 | ClientImpl.prototype._on_socket_message = function (event) {
1222 | this._trace("Client._on_socket_message", event.data);
1223 | var messages = this._deframeMessages(event.data);
1224 | for (var i = 0; i < messages.length; i+=1) {
1225 | this._handleMessage(messages[i]);
1226 | }
1227 | };
1228 |
1229 | ClientImpl.prototype._deframeMessages = function(data) {
1230 | var byteArray = new Uint8Array(data);
1231 | var messages = [];
1232 | if (this.receiveBuffer) {
1233 | var newData = new Uint8Array(this.receiveBuffer.length+byteArray.length);
1234 | newData.set(this.receiveBuffer);
1235 | newData.set(byteArray,this.receiveBuffer.length);
1236 | byteArray = newData;
1237 | delete this.receiveBuffer;
1238 | }
1239 | try {
1240 | var offset = 0;
1241 | while(offset < byteArray.length) {
1242 | var result = decodeMessage(byteArray,offset);
1243 | var wireMessage = result[0];
1244 | offset = result[1];
1245 | if (wireMessage !== null) {
1246 | messages.push(wireMessage);
1247 | } else {
1248 | break;
1249 | }
1250 | }
1251 | if (offset < byteArray.length) {
1252 | this.receiveBuffer = byteArray.subarray(offset);
1253 | }
1254 | } catch (error) {
1255 | var errorStack = ((error.hasOwnProperty("stack") == "undefined") ? error.stack.toString() : "No Error Stack Available");
1256 | this._disconnected(ERROR.INTERNAL_ERROR.code , format(ERROR.INTERNAL_ERROR, [error.message,errorStack]));
1257 | return;
1258 | }
1259 | return messages;
1260 | };
1261 |
1262 | ClientImpl.prototype._handleMessage = function(wireMessage) {
1263 |
1264 | this._trace("Client._handleMessage", wireMessage);
1265 |
1266 | try {
1267 | switch(wireMessage.type) {
1268 | case MESSAGE_TYPE.CONNACK:
1269 | this._connectTimeout.cancel();
1270 | if (this._reconnectTimeout)
1271 | this._reconnectTimeout.cancel();
1272 |
1273 | // If we have started using clean session then clear up the local state.
1274 | if (this.connectOptions.cleanSession) {
1275 | for (var key in this._sentMessages) {
1276 | var sentMessage = this._sentMessages[key];
1277 | localStorage.removeItem("Sent:"+this._localKey+sentMessage.messageIdentifier);
1278 | }
1279 | this._sentMessages = {};
1280 |
1281 | for (var key in this._receivedMessages) {
1282 | var receivedMessage = this._receivedMessages[key];
1283 | localStorage.removeItem("Received:"+this._localKey+receivedMessage.messageIdentifier);
1284 | }
1285 | this._receivedMessages = {};
1286 | }
1287 | // Client connected and ready for business.
1288 | if (wireMessage.returnCode === 0) {
1289 |
1290 | this.connected = true;
1291 | // Jump to the end of the list of uris and stop looking for a good host.
1292 |
1293 | if (this.connectOptions.uris)
1294 | this.hostIndex = this.connectOptions.uris.length;
1295 |
1296 | } else {
1297 | this._disconnected(ERROR.CONNACK_RETURNCODE.code , format(ERROR.CONNACK_RETURNCODE, [wireMessage.returnCode, CONNACK_RC[wireMessage.returnCode]]));
1298 | break;
1299 | }
1300 |
1301 | // Resend messages.
1302 | var sequencedMessages = [];
1303 | for (var msgId in this._sentMessages) {
1304 | if (this._sentMessages.hasOwnProperty(msgId))
1305 | sequencedMessages.push(this._sentMessages[msgId]);
1306 | }
1307 |
1308 | // Also schedule qos 0 buffered messages if any
1309 | if (this._buffered_msg_queue.length > 0) {
1310 | var msg = null;
1311 | while ((msg = this._buffered_msg_queue.pop())) {
1312 | sequencedMessages.push(msg);
1313 | if (this.onMessageDelivered)
1314 | this._notify_msg_sent[msg] = this.onMessageDelivered(msg.payloadMessage);
1315 | }
1316 | }
1317 |
1318 | // Sort sentMessages into the original sent order.
1319 | var sequencedMessages = sequencedMessages.sort(function(a,b) {return a.sequence - b.sequence;} );
1320 | for (var i=0, len=sequencedMessages.length; i
1674 | * Most applications will create just one Client object and then call its connect() method,
1675 | * however applications can create more than one Client object if they wish.
1676 | * In this case the combination of host, port and clientId attributes must be different for each Client object.
1677 | *
1678 | * The send, subscribe and unsubscribe methods are implemented as asynchronous JavaScript methods
1679 | * (even though the underlying protocol exchange might be synchronous in nature).
1680 | * This means they signal their completion by calling back to the application,
1681 | * via Success or Failure callback functions provided by the application on the method in question.
1682 | * Such callbacks are called at most once per method invocation and do not persist beyond the lifetime
1683 | * of the script that made the invocation.
1684 | *
1685 | * In contrast there are some callback functions, most notably onMessageArrived,
1686 | * that are defined on the {@link Paho.Client} object.
1687 | * These may get called multiple times, and aren't directly related to specific method invocations made by the client.
1688 | *
1689 | * @name Paho.Client
1690 | *
1691 | * @constructor
1692 | *
1693 | * @param {string} host - the address of the messaging server, as a fully qualified WebSocket URI, as a DNS name or dotted decimal IP address.
1694 | * @param {number} port - the port number to connect to - only required if host is not a URI
1695 | * @param {string} path - the path on the host to connect to - only used if host is not a URI. Default: '/mqtt'.
1696 | * @param {string} clientId - the Messaging client identifier, between 1 and 23 characters in length.
1697 | *
1698 | * @property {string} host - read only the server's DNS hostname or dotted decimal IP address.
1699 | * @property {number} port - read only the server's port.
1700 | * @property {string} path - read only the server's path.
1701 | * @property {string} clientId - read only used when connecting to the server.
1702 | * @property {function} onConnectionLost - called when a connection has been lost.
1703 | * after a connect() method has succeeded.
1704 | * Establish the call back used when a connection has been lost. The connection may be
1705 | * lost because the client initiates a disconnect or because the server or network
1706 | * cause the client to be disconnected. The disconnect call back may be called without
1707 | * the connectionComplete call back being invoked if, for example the client fails to
1708 | * connect.
1709 | * A single response object parameter is passed to the onConnectionLost callback containing the following fields:
1710 | *
1711 | * - errorCode
1712 | *
- errorMessage
1713 | *
1714 | * @property {function} onMessageDelivered - called when a message has been delivered.
1715 | * All processing that this Client will ever do has been completed. So, for example,
1716 | * in the case of a Qos=2 message sent by this client, the PubComp flow has been received from the server
1717 | * and the message has been removed from persistent storage before this callback is invoked.
1718 | * Parameters passed to the onMessageDelivered callback are:
1719 | *
1720 | * - {@link Paho.Message} that was delivered.
1721 | *
1722 | * @property {function} onMessageArrived - called when a message has arrived in this Paho.client.
1723 | * Parameters passed to the onMessageArrived callback are:
1724 | *
1725 | * - {@link Paho.Message} that has arrived.
1726 | *
1727 | * @property {function} onConnected - called when a connection is successfully made to the server.
1728 | * after a connect() method.
1729 | * Parameters passed to the onConnected callback are:
1730 | *
1731 | * - reconnect (boolean) - If true, the connection was the result of a reconnect.
1732 | * - URI (string) - The URI used to connect to the server.
1733 | *
1734 | * @property {boolean} disconnectedPublishing - if set, will enable disconnected publishing in
1735 | * in the event that the connection to the server is lost.
1736 | * @property {number} disconnectedBufferSize - Used to set the maximum number of messages that the disconnected
1737 | * buffer will hold before rejecting new messages. Default size: 5000 messages
1738 | * @property {function} trace - called whenever trace is called. TODO
1739 | */
1740 | var Client = function (host, port, path, clientId) {
1741 |
1742 | var uri;
1743 |
1744 | if (typeof host !== "string")
1745 | throw new Error(format(ERROR.INVALID_TYPE, [typeof host, "host"]));
1746 |
1747 | if (arguments.length == 2) {
1748 | // host: must be full ws:// uri
1749 | // port: clientId
1750 | clientId = port;
1751 | uri = host;
1752 | var match = uri.match(/^(wss?):\/\/((\[(.+)\])|([^\/]+?))(:(\d+))?(\/.*)$/);
1753 | if (match) {
1754 | host = match[4]||match[2];
1755 | port = parseInt(match[7]);
1756 | path = match[8];
1757 | } else {
1758 | throw new Error(format(ERROR.INVALID_ARGUMENT,[host,"host"]));
1759 | }
1760 | } else {
1761 | if (arguments.length == 3) {
1762 | clientId = path;
1763 | path = "/mqtt";
1764 | }
1765 | if (typeof port !== "number" || port < 0)
1766 | throw new Error(format(ERROR.INVALID_TYPE, [typeof port, "port"]));
1767 | if (typeof path !== "string")
1768 | throw new Error(format(ERROR.INVALID_TYPE, [typeof path, "path"]));
1769 |
1770 | var ipv6AddSBracket = (host.indexOf(":") !== -1 && host.slice(0,1) !== "[" && host.slice(-1) !== "]");
1771 | uri = "ws://"+(ipv6AddSBracket?"["+host+"]":host)+":"+port+path;
1772 | }
1773 |
1774 | var clientIdLength = 0;
1775 | for (var i = 0; i 65535)
1783 | throw new Error(format(ERROR.INVALID_ARGUMENT, [clientId, "clientId"]));
1784 |
1785 | var client = new ClientImpl(uri, host, port, path, clientId);
1786 |
1787 | //Public Properties
1788 | Object.defineProperties(this,{
1789 | "host":{
1790 | get: function() { return host; },
1791 | set: function() { throw new Error(format(ERROR.UNSUPPORTED_OPERATION)); }
1792 | },
1793 | "port":{
1794 | get: function() { return port; },
1795 | set: function() { throw new Error(format(ERROR.UNSUPPORTED_OPERATION)); }
1796 | },
1797 | "path":{
1798 | get: function() { return path; },
1799 | set: function() { throw new Error(format(ERROR.UNSUPPORTED_OPERATION)); }
1800 | },
1801 | "uri":{
1802 | get: function() { return uri; },
1803 | set: function() { throw new Error(format(ERROR.UNSUPPORTED_OPERATION)); }
1804 | },
1805 | "clientId":{
1806 | get: function() { return client.clientId; },
1807 | set: function() { throw new Error(format(ERROR.UNSUPPORTED_OPERATION)); }
1808 | },
1809 | "onConnected":{
1810 | get: function() { return client.onConnected; },
1811 | set: function(newOnConnected) {
1812 | if (typeof newOnConnected === "function")
1813 | client.onConnected = newOnConnected;
1814 | else
1815 | throw new Error(format(ERROR.INVALID_TYPE, [typeof newOnConnected, "onConnected"]));
1816 | }
1817 | },
1818 | "disconnectedPublishing":{
1819 | get: function() { return client.disconnectedPublishing; },
1820 | set: function(newDisconnectedPublishing) {
1821 | client.disconnectedPublishing = newDisconnectedPublishing;
1822 | }
1823 | },
1824 | "disconnectedBufferSize":{
1825 | get: function() { return client.disconnectedBufferSize; },
1826 | set: function(newDisconnectedBufferSize) {
1827 | client.disconnectedBufferSize = newDisconnectedBufferSize;
1828 | }
1829 | },
1830 | "onConnectionLost":{
1831 | get: function() { return client.onConnectionLost; },
1832 | set: function(newOnConnectionLost) {
1833 | if (typeof newOnConnectionLost === "function")
1834 | client.onConnectionLost = newOnConnectionLost;
1835 | else
1836 | throw new Error(format(ERROR.INVALID_TYPE, [typeof newOnConnectionLost, "onConnectionLost"]));
1837 | }
1838 | },
1839 | "onMessageDelivered":{
1840 | get: function() { return client.onMessageDelivered; },
1841 | set: function(newOnMessageDelivered) {
1842 | if (typeof newOnMessageDelivered === "function")
1843 | client.onMessageDelivered = newOnMessageDelivered;
1844 | else
1845 | throw new Error(format(ERROR.INVALID_TYPE, [typeof newOnMessageDelivered, "onMessageDelivered"]));
1846 | }
1847 | },
1848 | "onMessageArrived":{
1849 | get: function() { return client.onMessageArrived; },
1850 | set: function(newOnMessageArrived) {
1851 | if (typeof newOnMessageArrived === "function")
1852 | client.onMessageArrived = newOnMessageArrived;
1853 | else
1854 | throw new Error(format(ERROR.INVALID_TYPE, [typeof newOnMessageArrived, "onMessageArrived"]));
1855 | }
1856 | },
1857 | "trace":{
1858 | get: function() { return client.traceFunction; },
1859 | set: function(trace) {
1860 | if(typeof trace === "function"){
1861 | client.traceFunction = trace;
1862 | }else{
1863 | throw new Error(format(ERROR.INVALID_TYPE, [typeof trace, "onTrace"]));
1864 | }
1865 | }
1866 | },
1867 | });
1868 |
1869 | /**
1870 | * Connect this Messaging client to its server.
1871 | *
1872 | * @name Paho.Client#connect
1873 | * @function
1874 | * @param {object} connectOptions - Attributes used with the connection.
1875 | * @param {number} connectOptions.timeout - If the connect has not succeeded within this
1876 | * number of seconds, it is deemed to have failed.
1877 | * The default is 30 seconds.
1878 | * @param {string} connectOptions.userName - Authentication username for this connection.
1879 | * @param {string} connectOptions.password - Authentication password for this connection.
1880 | * @param {Paho.Message} connectOptions.willMessage - sent by the server when the client
1881 | * disconnects abnormally.
1882 | * @param {number} connectOptions.keepAliveInterval - the server disconnects this client if
1883 | * there is no activity for this number of seconds.
1884 | * The default value of 60 seconds is assumed if not set.
1885 | * @param {boolean} connectOptions.cleanSession - if true(default) the client and server
1886 | * persistent state is deleted on successful connect.
1887 | * @param {boolean} connectOptions.useSSL - if present and true, use an SSL Websocket connection.
1888 | * @param {object} connectOptions.invocationContext - passed to the onSuccess callback or onFailure callback.
1889 | * @param {function} connectOptions.onSuccess - called when the connect acknowledgement
1890 | * has been received from the server.
1891 | * A single response object parameter is passed to the onSuccess callback containing the following fields:
1892 | *
1893 | * - invocationContext as passed in to the onSuccess method in the connectOptions.
1894 | *
1895 | * @param {function} connectOptions.onFailure - called when the connect request has failed or timed out.
1896 | * A single response object parameter is passed to the onFailure callback containing the following fields:
1897 | *
1898 | * - invocationContext as passed in to the onFailure method in the connectOptions.
1899 | *
- errorCode a number indicating the nature of the error.
1900 | *
- errorMessage text describing the error.
1901 | *
1902 | * @param {array} connectOptions.hosts - If present this contains either a set of hostnames or fully qualified
1903 | * WebSocket URIs (ws://iot.eclipse.org:80/ws), that are tried in order in place
1904 | * of the host and port paramater on the construtor. The hosts are tried one at at time in order until
1905 | * one of then succeeds.
1906 | * @param {array} connectOptions.ports - If present the set of ports matching the hosts. If hosts contains URIs, this property
1907 | * is not used.
1908 | * @param {boolean} connectOptions.reconnect - Sets whether the client will automatically attempt to reconnect
1909 | * to the server if the connection is lost.
1910 | *
1911 | *- If set to false, the client will not attempt to automatically reconnect to the server in the event that the
1912 | * connection is lost.
1913 | *- If set to true, in the event that the connection is lost, the client will attempt to reconnect to the server.
1914 | * It will initially wait 1 second before it attempts to reconnect, for every failed reconnect attempt, the delay
1915 | * will double until it is at 2 minutes at which point the delay will stay at 2 minutes.
1916 | *
1917 | * @param {number} connectOptions.mqttVersion - The version of MQTT to use to connect to the MQTT Broker.
1918 | *
1919 | *- 3 - MQTT V3.1
1920 | *- 4 - MQTT V3.1.1
1921 | *
1922 | * @param {boolean} connectOptions.mqttVersionExplicit - If set to true, will force the connection to use the
1923 | * selected MQTT Version or will fail to connect.
1924 | * @param {array} connectOptions.uris - If present, should contain a list of fully qualified WebSocket uris
1925 | * (e.g. ws://iot.eclipse.org:80/ws), that are tried in order in place of the host and port parameter of the construtor.
1926 | * The uris are tried one at a time in order until one of them succeeds. Do not use this in conjunction with hosts as
1927 | * the hosts array will be converted to uris and will overwrite this property.
1928 | * @throws {InvalidState} If the client is not in disconnected state. The client must have received connectionLost
1929 | * or disconnected before calling connect for a second or subsequent time.
1930 | */
1931 | this.connect = function (connectOptions) {
1932 | connectOptions = connectOptions || {} ;
1933 | validate(connectOptions, {timeout:"number",
1934 | userName:"string",
1935 | password:"string",
1936 | willMessage:"object",
1937 | keepAliveInterval:"number",
1938 | cleanSession:"boolean",
1939 | useSSL:"boolean",
1940 | invocationContext:"object",
1941 | onSuccess:"function",
1942 | onFailure:"function",
1943 | hosts:"object",
1944 | ports:"object",
1945 | reconnect:"boolean",
1946 | mqttVersion:"number",
1947 | mqttVersionExplicit:"boolean",
1948 | uris: "object"});
1949 |
1950 | // If no keep alive interval is set, assume 60 seconds.
1951 | if (connectOptions.keepAliveInterval === undefined)
1952 | connectOptions.keepAliveInterval = 60;
1953 |
1954 | if (connectOptions.mqttVersion > 4 || connectOptions.mqttVersion < 3) {
1955 | throw new Error(format(ERROR.INVALID_ARGUMENT, [connectOptions.mqttVersion, "connectOptions.mqttVersion"]));
1956 | }
1957 |
1958 | if (connectOptions.mqttVersion === undefined) {
1959 | connectOptions.mqttVersionExplicit = false;
1960 | connectOptions.mqttVersion = 4;
1961 | } else {
1962 | connectOptions.mqttVersionExplicit = true;
1963 | }
1964 |
1965 | //Check that if password is set, so is username
1966 | if (connectOptions.password !== undefined && connectOptions.userName === undefined)
1967 | throw new Error(format(ERROR.INVALID_ARGUMENT, [connectOptions.password, "connectOptions.password"]));
1968 |
1969 | if (connectOptions.willMessage) {
1970 | if (!(connectOptions.willMessage instanceof Message))
1971 | throw new Error(format(ERROR.INVALID_TYPE, [connectOptions.willMessage, "connectOptions.willMessage"]));
1972 | // The will message must have a payload that can be represented as a string.
1973 | // Cause the willMessage to throw an exception if this is not the case.
1974 | connectOptions.willMessage.stringPayload = null;
1975 |
1976 | if (typeof connectOptions.willMessage.destinationName === "undefined")
1977 | throw new Error(format(ERROR.INVALID_TYPE, [typeof connectOptions.willMessage.destinationName, "connectOptions.willMessage.destinationName"]));
1978 | }
1979 | if (typeof connectOptions.cleanSession === "undefined")
1980 | connectOptions.cleanSession = true;
1981 | if (connectOptions.hosts) {
1982 |
1983 | if (!(connectOptions.hosts instanceof Array) )
1984 | throw new Error(format(ERROR.INVALID_ARGUMENT, [connectOptions.hosts, "connectOptions.hosts"]));
1985 | if (connectOptions.hosts.length <1 )
1986 | throw new Error(format(ERROR.INVALID_ARGUMENT, [connectOptions.hosts, "connectOptions.hosts"]));
1987 |
1988 | var usingURIs = false;
1989 | for (var i = 0; i
2038 | * @param {object} subscribeOptions - used to control the subscription
2039 | *
2040 | * @param {number} subscribeOptions.qos - the maximum qos of any publications sent
2041 | * as a result of making this subscription.
2042 | * @param {object} subscribeOptions.invocationContext - passed to the onSuccess callback
2043 | * or onFailure callback.
2044 | * @param {function} subscribeOptions.onSuccess - called when the subscribe acknowledgement
2045 | * has been received from the server.
2046 | * A single response object parameter is passed to the onSuccess callback containing the following fields:
2047 | *
2048 | * - invocationContext if set in the subscribeOptions.
2049 | *
2050 | * @param {function} subscribeOptions.onFailure - called when the subscribe request has failed or timed out.
2051 | * A single response object parameter is passed to the onFailure callback containing the following fields:
2052 | *
2053 | * - invocationContext - if set in the subscribeOptions.
2054 | *
- errorCode - a number indicating the nature of the error.
2055 | *
- errorMessage - text describing the error.
2056 | *
2057 | * @param {number} subscribeOptions.timeout - which, if present, determines the number of
2058 | * seconds after which the onFailure calback is called.
2059 | * The presence of a timeout does not prevent the onSuccess
2060 | * callback from being called when the subscribe completes.
2061 | * @throws {InvalidState} if the client is not in connected state.
2062 | */
2063 | this.subscribe = function (filter, subscribeOptions) {
2064 | if (typeof filter !== "string" && filter.constructor !== Array)
2065 | throw new Error("Invalid argument:"+filter);
2066 | subscribeOptions = subscribeOptions || {} ;
2067 | validate(subscribeOptions, {qos:"number",
2068 | invocationContext:"object",
2069 | onSuccess:"function",
2070 | onFailure:"function",
2071 | timeout:"number"
2072 | });
2073 | if (subscribeOptions.timeout && !subscribeOptions.onFailure)
2074 | throw new Error("subscribeOptions.timeout specified with no onFailure callback.");
2075 | if (typeof subscribeOptions.qos !== "undefined" && !(subscribeOptions.qos === 0 || subscribeOptions.qos === 1 || subscribeOptions.qos === 2 ))
2076 | throw new Error(format(ERROR.INVALID_ARGUMENT, [subscribeOptions.qos, "subscribeOptions.qos"]));
2077 | client.subscribe(filter, subscribeOptions);
2078 | };
2079 |
2080 | /**
2081 | * Unsubscribe for messages, stop receiving messages sent to destinations described by the filter.
2082 | *
2083 | * @name Paho.Client#unsubscribe
2084 | * @function
2085 | * @param {string} filter - describing the destinations to receive messages from.
2086 | * @param {object} unsubscribeOptions - used to control the subscription
2087 | * @param {object} unsubscribeOptions.invocationContext - passed to the onSuccess callback
2088 | or onFailure callback.
2089 | * @param {function} unsubscribeOptions.onSuccess - called when the unsubscribe acknowledgement has been received from the server.
2090 | * A single response object parameter is passed to the
2091 | * onSuccess callback containing the following fields:
2092 | *
2093 | * - invocationContext - if set in the unsubscribeOptions.
2094 | *
2095 | * @param {function} unsubscribeOptions.onFailure called when the unsubscribe request has failed or timed out.
2096 | * A single response object parameter is passed to the onFailure callback containing the following fields:
2097 | *
2098 | * - invocationContext - if set in the unsubscribeOptions.
2099 | *
- errorCode - a number indicating the nature of the error.
2100 | *
- errorMessage - text describing the error.
2101 | *
2102 | * @param {number} unsubscribeOptions.timeout - which, if present, determines the number of seconds
2103 | * after which the onFailure callback is called. The presence of
2104 | * a timeout does not prevent the onSuccess callback from being
2105 | * called when the unsubscribe completes
2106 | * @throws {InvalidState} if the client is not in connected state.
2107 | */
2108 | this.unsubscribe = function (filter, unsubscribeOptions) {
2109 | if (typeof filter !== "string" && filter.constructor !== Array)
2110 | throw new Error("Invalid argument:"+filter);
2111 | unsubscribeOptions = unsubscribeOptions || {} ;
2112 | validate(unsubscribeOptions, {invocationContext:"object",
2113 | onSuccess:"function",
2114 | onFailure:"function",
2115 | timeout:"number"
2116 | });
2117 | if (unsubscribeOptions.timeout && !unsubscribeOptions.onFailure)
2118 | throw new Error("unsubscribeOptions.timeout specified with no onFailure callback.");
2119 | client.unsubscribe(filter, unsubscribeOptions);
2120 | };
2121 |
2122 | /**
2123 | * Send a message to the consumers of the destination in the Message.
2124 | *
2125 | * @name Paho.Client#send
2126 | * @function
2127 | * @param {string|Paho.Message} topic - mandatory The name of the destination to which the message is to be sent.
2128 | * - If it is the only parameter, used as Paho.Message object.
2129 | * @param {String|ArrayBuffer} payload - The message data to be sent.
2130 | * @param {number} qos The Quality of Service used to deliver the message.
2131 | *
2132 | * - 0 Best effort (default).
2133 | *
- 1 At least once.
2134 | *
- 2 Exactly once.
2135 | *
2136 | * @param {Boolean} retained If true, the message is to be retained by the server and delivered
2137 | * to both current and future subscriptions.
2138 | * If false the server only delivers the message to current subscribers, this is the default for new Messages.
2139 | * A received message has the retained boolean set to true if the message was published
2140 | * with the retained boolean set to true
2141 | * and the subscrption was made after the message has been published.
2142 | * @throws {InvalidState} if the client is not connected.
2143 | */
2144 | this.send = function (topic,payload,qos,retained) {
2145 | var message ;
2146 |
2147 | if(arguments.length === 0){
2148 | throw new Error("Invalid argument."+"length");
2149 |
2150 | }else if(arguments.length == 1) {
2151 |
2152 | if (!(topic instanceof Message) && (typeof topic !== "string"))
2153 | throw new Error("Invalid argument:"+ typeof topic);
2154 |
2155 | message = topic;
2156 | if (typeof message.destinationName === "undefined")
2157 | throw new Error(format(ERROR.INVALID_ARGUMENT,[message.destinationName,"Message.destinationName"]));
2158 | client.send(message);
2159 |
2160 | }else {
2161 | //parameter checking in Message object
2162 | message = new Message(payload);
2163 | message.destinationName = topic;
2164 | if(arguments.length >= 3)
2165 | message.qos = qos;
2166 | if(arguments.length >= 4)
2167 | message.retained = retained;
2168 | client.send(message);
2169 | }
2170 | };
2171 |
2172 | /**
2173 | * Publish a message to the consumers of the destination in the Message.
2174 | * Synonym for Paho.Mqtt.Client#send
2175 | *
2176 | * @name Paho.Client#publish
2177 | * @function
2178 | * @param {string|Paho.Message} topic - mandatory The name of the topic to which the message is to be published.
2179 | * - If it is the only parameter, used as Paho.Message object.
2180 | * @param {String|ArrayBuffer} payload - The message data to be published.
2181 | * @param {number} qos The Quality of Service used to deliver the message.
2182 | *
2183 | * - 0 Best effort (default).
2184 | *
- 1 At least once.
2185 | *
- 2 Exactly once.
2186 | *
2187 | * @param {Boolean} retained If true, the message is to be retained by the server and delivered
2188 | * to both current and future subscriptions.
2189 | * If false the server only delivers the message to current subscribers, this is the default for new Messages.
2190 | * A received message has the retained boolean set to true if the message was published
2191 | * with the retained boolean set to true
2192 | * and the subscrption was made after the message has been published.
2193 | * @throws {InvalidState} if the client is not connected.
2194 | */
2195 | this.publish = function(topic,payload,qos,retained) {
2196 | var message ;
2197 |
2198 | if(arguments.length === 0){
2199 | throw new Error("Invalid argument."+"length");
2200 |
2201 | }else if(arguments.length == 1) {
2202 |
2203 | if (!(topic instanceof Message) && (typeof topic !== "string"))
2204 | throw new Error("Invalid argument:"+ typeof topic);
2205 |
2206 | message = topic;
2207 | if (typeof message.destinationName === "undefined")
2208 | throw new Error(format(ERROR.INVALID_ARGUMENT,[message.destinationName,"Message.destinationName"]));
2209 | client.send(message);
2210 |
2211 | }else {
2212 | //parameter checking in Message object
2213 | message = new Message(payload);
2214 | message.destinationName = topic;
2215 | if(arguments.length >= 3)
2216 | message.qos = qos;
2217 | if(arguments.length >= 4)
2218 | message.retained = retained;
2219 | client.send(message);
2220 | }
2221 | };
2222 |
2223 | /**
2224 | * Normal disconnect of this Messaging client from its server.
2225 | *
2226 | * @name Paho.Client#disconnect
2227 | * @function
2228 | * @throws {InvalidState} if the client is already disconnected.
2229 | */
2230 | this.disconnect = function () {
2231 | client.disconnect();
2232 | };
2233 |
2234 | /**
2235 | * Get the contents of the trace log.
2236 | *
2237 | * @name Paho.Client#getTraceLog
2238 | * @function
2239 | * @return {Object[]} tracebuffer containing the time ordered trace records.
2240 | */
2241 | this.getTraceLog = function () {
2242 | return client.getTraceLog();
2243 | };
2244 |
2245 | /**
2246 | * Start tracing.
2247 | *
2248 | * @name Paho.Client#startTrace
2249 | * @function
2250 | */
2251 | this.startTrace = function () {
2252 | client.startTrace();
2253 | };
2254 |
2255 | /**
2256 | * Stop tracing.
2257 | *
2258 | * @name Paho.Client#stopTrace
2259 | * @function
2260 | */
2261 | this.stopTrace = function () {
2262 | client.stopTrace();
2263 | };
2264 |
2265 | this.isConnected = function() {
2266 | return client.connected;
2267 | };
2268 | };
2269 |
2270 | /**
2271 | * An application message, sent or received.
2272 | *
2273 | * All attributes may be null, which implies the default values.
2274 | *
2275 | * @name Paho.Message
2276 | * @constructor
2277 | * @param {String|ArrayBuffer} payload The message data to be sent.
2278 | *
2279 | * @property {string} payloadString read only The payload as a string if the payload consists of valid UTF-8 characters.
2280 | * @property {ArrayBuffer} payloadBytes read only The payload as an ArrayBuffer.
2281 | *
2282 | * @property {string} destinationName mandatory The name of the destination to which the message is to be sent
2283 | * (for messages about to be sent) or the name of the destination from which the message has been received.
2284 | * (for messages received by the onMessage function).
2285 | *
2286 | * @property {number} qos The Quality of Service used to deliver the message.
2287 | *
2288 | * - 0 Best effort (default).
2289 | *
- 1 At least once.
2290 | *
- 2 Exactly once.
2291 | *
2292 | *
2293 | * @property {Boolean} retained If true, the message is to be retained by the server and delivered
2294 | * to both current and future subscriptions.
2295 | * If false the server only delivers the message to current subscribers, this is the default for new Messages.
2296 | * A received message has the retained boolean set to true if the message was published
2297 | * with the retained boolean set to true
2298 | * and the subscrption was made after the message has been published.
2299 | *
2300 | * @property {Boolean} duplicate read only If true, this message might be a duplicate of one which has already been received.
2301 | * This is only set on messages received from the server.
2302 | *
2303 | */
2304 | var Message = function (newPayload) {
2305 | var payload;
2306 | if ( typeof newPayload === "string" ||
2307 | newPayload instanceof ArrayBuffer ||
2308 | (ArrayBuffer.isView(newPayload) && !(newPayload instanceof DataView))
2309 | ) {
2310 | payload = newPayload;
2311 | } else {
2312 | throw (format(ERROR.INVALID_ARGUMENT, [newPayload, "newPayload"]));
2313 | }
2314 |
2315 | var destinationName;
2316 | var qos = 0;
2317 | var retained = false;
2318 | var duplicate = false;
2319 |
2320 | Object.defineProperties(this,{
2321 | "payloadString":{
2322 | enumerable : true,
2323 | get : function () {
2324 | if (typeof payload === "string")
2325 | return payload;
2326 | else
2327 | return parseUTF8(payload, 0, payload.length);
2328 | }
2329 | },
2330 | "payloadBytes":{
2331 | enumerable: true,
2332 | get: function() {
2333 | if (typeof payload === "string") {
2334 | var buffer = new ArrayBuffer(UTF8Length(payload));
2335 | var byteStream = new Uint8Array(buffer);
2336 | stringToUTF8(payload, byteStream, 0);
2337 |
2338 | return byteStream;
2339 | } else {
2340 | return payload;
2341 | }
2342 | }
2343 | },
2344 | "destinationName":{
2345 | enumerable: true,
2346 | get: function() { return destinationName; },
2347 | set: function(newDestinationName) {
2348 | if (typeof newDestinationName === "string")
2349 | destinationName = newDestinationName;
2350 | else
2351 | throw new Error(format(ERROR.INVALID_ARGUMENT, [newDestinationName, "newDestinationName"]));
2352 | }
2353 | },
2354 | "qos":{
2355 | enumerable: true,
2356 | get: function() { return qos; },
2357 | set: function(newQos) {
2358 | if (newQos === 0 || newQos === 1 || newQos === 2 )
2359 | qos = newQos;
2360 | else
2361 | throw new Error("Invalid argument:"+newQos);
2362 | }
2363 | },
2364 | "retained":{
2365 | enumerable: true,
2366 | get: function() { return retained; },
2367 | set: function(newRetained) {
2368 | if (typeof newRetained === "boolean")
2369 | retained = newRetained;
2370 | else
2371 | throw new Error(format(ERROR.INVALID_ARGUMENT, [newRetained, "newRetained"]));
2372 | }
2373 | },
2374 | "topic":{
2375 | enumerable: true,
2376 | get: function() { return destinationName; },
2377 | set: function(newTopic) {destinationName=newTopic;}
2378 | },
2379 | "duplicate":{
2380 | enumerable: true,
2381 | get: function() { return duplicate; },
2382 | set: function(newDuplicate) {duplicate=newDuplicate;}
2383 | }
2384 | });
2385 | };
2386 |
2387 | // Module contents.
2388 | return {
2389 | Client: Client,
2390 | Message: Message
2391 | };
2392 | // eslint-disable-next-line no-nested-ternary
2393 | })(typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {});
2394 | return PahoMQTT;
2395 | });
2396 |
--------------------------------------------------------------------------------