@@ -401,3 +401,105 @@ function doSetSoundLevel(type, serviceId, level) {
401401 showError ( 'PUT setting/volume/sound' , e . errorCode , e . errorMessage ) ;
402402 } ) ;
403403}
404+
405+ function showCopyGuard ( ) {
406+ initAll ( ) ;
407+ setTitle ( 'CopyGuard API' ) ;
408+
409+ let str = '' ;
410+ str += '<div style="text-align:center">コピーガード状態: <span id="copyGuardState"></span></div>' ;
411+ str += '<div style="text-align:center"><div data-role="controlgroup" data-type="horizontal">'
412+ str += ' <input data-inline="true" data-mini="true" onclick="turnCopyGuardOnOff(true)" type="button" value="ON" />' ;
413+ str += ' <input data-inline="true" data-mini="true" onclick="turnCopyGuardOnOff(false)" type="button" value="OFF" />' ;
414+ str += '</div></div>' ;
415+ str += '<br>' ;
416+ str += '<div style="text-align:center">状態変更イベント: <span id="changeEventState"></span></div>' ;
417+ str += '<div style="text-align:center"><div data-role="controlgroup" data-type="horizontal">'
418+ str += ' <input data-inline="true" data-mini="true" onclick="registerChangeEvent()" type="button" value="登録" />' ;
419+ str += ' <input data-inline="true" data-mini="true" onclick="unregisterChangeEvent()" type="button" value="解除" />' ;
420+ str += '</div></div>' ;
421+ reloadContent ( str ) ;
422+
423+ getCopyGuardState ( ) ;
424+ registerChangeEvent ( ) ;
425+ }
426+
427+ function getCopyGuardState ( ) {
428+ showCopyGuardState ( '確認中' ) ;
429+ sdk . get ( {
430+ profile : 'setting' ,
431+ attribute : 'copyGuard' ,
432+ } ) . then ( json => {
433+ if ( DEBUG ) {
434+ console . log ( 'Response: ' , json ) ;
435+ }
436+ showCopyGuardState ( json . enabled ? 'ON' : 'OFF' ) ;
437+ } ) . catch ( e => {
438+ showError ( 'GET /setting/copyGuard' , e . errorCode , e . errorMessage ) ;
439+ } ) ;
440+ }
441+
442+ function showCopyGuardState ( stateName ) {
443+ let e = document . getElementById ( 'copyGuardState' ) ;
444+ e . innerHTML = stateName ;
445+ }
446+
447+ function turnCopyGuardOnOff ( on ) {
448+ let method = on ? 'PUT' : 'DELETE' ;
449+ sdk . sendRequest ( method , {
450+ profile : 'setting' ,
451+ attribute : 'copyGuard' ,
452+ } ) . then ( json => {
453+ if ( DEBUG ) {
454+ console . log ( 'Response: ' , json ) ;
455+ }
456+ } ) . catch ( e => {
457+ showError ( method + ' setting/copyGuard' , e . errorCode , e . errorMessage ) ;
458+ } ) ;
459+ }
460+
461+ function showCopyGuardChangeEventState ( stateName ) {
462+ let e = document . getElementById ( 'changeEventState' ) ;
463+ e . innerHTML = stateName ;
464+ }
465+
466+ function registerChangeEvent ( ) {
467+ showCopyGuardChangeEventState ( '登録中...' ) ;
468+ let onmessage = function ( event ) {
469+ let json = JSON . parse ( event ) ;
470+ if ( DEBUG ) {
471+ console . log ( 'Event: /setting/copyGuard/onChange' , json ) ;
472+ }
473+ showCopyGuardState ( json . enabled ? 'ON' : 'OFF' ) ;
474+ } ;
475+ sdk . addEventListener ( {
476+ profile : 'setting' ,
477+ interface : 'copyGuard' ,
478+ attribute : 'onChange'
479+ } , onmessage ) . then ( json => {
480+ if ( DEBUG ) {
481+ console . log ( 'Response: ' , json ) ;
482+ }
483+ showCopyGuardChangeEventState ( '受信する' ) ;
484+ } ) . catch ( e => {
485+ showCopyGuardChangeEventState ( '登録失敗' ) ;
486+ showError ( 'PUT /setting/copyGuard/onChange' , e . errorCode , e . errorMessage ) ;
487+ } ) ;
488+ }
489+
490+ function unregisterChangeEvent ( ) {
491+ showCopyGuardChangeEventState ( '解除中...' ) ;
492+ sdk . removeEventListener ( {
493+ profile : 'setting' ,
494+ interface : 'copyGuard' ,
495+ attribute : 'onChange'
496+ } ) . then ( json => {
497+ if ( DEBUG ) {
498+ console . log ( 'Response: ' , json ) ;
499+ }
500+ showCopyGuardChangeEventState ( '受信しない' ) ;
501+ } ) . catch ( e => {
502+ showCopyGuardChangeEventState ( '解除失敗' ) ;
503+ showError ( 'DELETE /setting/copyGuard/onChange' , e . errorCode , e . errorMessage ) ;
504+ } ) ;
505+ }
0 commit comments