Skip to content

Commit

Permalink
Add sign language module
Browse files Browse the repository at this point in the history
  • Loading branch information
changgilee committed Aug 27, 2024
1 parent d1c4064 commit 100bce1
Show file tree
Hide file tree
Showing 3 changed files with 233 additions and 0 deletions.
126 changes: 126 additions & 0 deletions packages/webos/signlang/SignLangDecorator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { Component } from 'react';
import PropTypes from 'prop-types';
import hoc from '@enact/core/hoc';
import { forward } from '@enact/core/handle';
import signLang from './signLang';

/**
* SignLangDecorator is a higher-order component that adds feature for sign language
* to its wrapped component.
*
*
* Usage:
* ```
* import {Component} from 'react';
* import Button from '@enact/sandstone/Button';
* import { SignLangDecorator } from '@enact/webos/signlang';
*
* const SignLangButton = SignLangDecorator(Button);
*
* class Sample extends Component {
* render () {
* return(
* <div>
* <SignLangButton signLangId="settings_audioguide_1">Hello</SignLangButton>
* </div>
* );
* }
* }
* ```
*
* @class SignLangDecorator
* @memberof webos/signlang
* @hoc
* @public
*/

const defaultConfig = {

Check warning on line 37 in packages/webos/signlang/SignLangDecorator.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/SignLangDecorator.js#L37

Added line #L37 was not covered by tests
/**
* Set sign language request delay in milliseconds.
*
* @type {Number}
* @public
*/
signLangDelay: 0
}

const SignLangDecorator = hoc(defaultConfig, (config, Wrapped) => {
const { signLangDelay } = config;
const forwardBlur = forward('onBlur');
const forwardFocus = forward('onFocus');

Check warning on line 50 in packages/webos/signlang/SignLangDecorator.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/SignLangDecorator.js#L47-L50

Added lines #L47 - L50 were not covered by tests

return class extends Component {
static displayName = 'SignLangDecorator';

Check warning on line 53 in packages/webos/signlang/SignLangDecorator.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/SignLangDecorator.js#L52-L53

Added lines #L52 - L53 were not covered by tests

static propTypes = /** @lends webos/signlang.SignLangDecorator.prototype */ {

Check warning on line 55 in packages/webos/signlang/SignLangDecorator.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/SignLangDecorator.js#L55

Added line #L55 was not covered by tests
/**
* Unique string used in sign language.
*
* @type {String}
* @public
*/
signLangId: PropTypes.string,

/**
* Additional option for sign language
*
* @type {Object}
* @public
*/
signLangOption: PropTypes.object,
};

constructor(props) {
super(props);

Check warning on line 74 in packages/webos/signlang/SignLangDecorator.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/SignLangDecorator.js#L73-L74

Added lines #L73 - L74 were not covered by tests

this.signLangDelayId = null;

Check warning on line 76 in packages/webos/signlang/SignLangDecorator.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/SignLangDecorator.js#L76

Added line #L76 was not covered by tests
}

requestSignLang = (focusOut) => {

Check warning on line 79 in packages/webos/signlang/SignLangDecorator.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/SignLangDecorator.js#L79

Added line #L79 was not covered by tests
const { signLangId, signLangOption = {} } = this.props;

if (typeof signLangId == 'string' && signLangId.length > 0) signLang(signLangId, focusOut, signLangOption);
}

onFocus = (ev) => {
forwardFocus(ev, this.props);

Check warning on line 86 in packages/webos/signlang/SignLangDecorator.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/SignLangDecorator.js#L85-L86

Added lines #L85 - L86 were not covered by tests

if (signLangDelay == 0) {
this.requestSignLang(false);
} else {
clearTimeout(this.signLangDelayId);
this.signLangDelayId = setTimeout(() => {
this.requestSignLang(false);

Check warning on line 93 in packages/webos/signlang/SignLangDecorator.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/SignLangDecorator.js#L89-L93

Added lines #L89 - L93 were not covered by tests
}, signLangDelay);
}
}

onBlur = (ev) => {
forwardBlur(ev, this.props);

Check warning on line 99 in packages/webos/signlang/SignLangDecorator.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/SignLangDecorator.js#L98-L99

Added lines #L98 - L99 were not covered by tests

if (signLangDelay > 0) clearTimeout(this.signLangDelayId);

this.requestSignLang(true);

Check warning on line 103 in packages/webos/signlang/SignLangDecorator.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/SignLangDecorator.js#L103

Added line #L103 was not covered by tests
}

render() {
const props = Object.assign({}, this.props);
delete props.onFocus;
delete props.onBlur;
delete props.signLangId;
delete props.signLangDelay;
delete props.signLangOption;

Check warning on line 112 in packages/webos/signlang/SignLangDecorator.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/SignLangDecorator.js#L106-L112

Added lines #L106 - L112 were not covered by tests

return (

Check warning on line 114 in packages/webos/signlang/SignLangDecorator.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/SignLangDecorator.js#L114

Added line #L114 was not covered by tests
<Wrapped
{...props}
onFocus={this.onFocus}
onBlur={this.onBlur}
/>
);
}
};
});

export default SignLangDecorator;
export { SignLangDecorator };
15 changes: 15 additions & 0 deletions packages/webos/signlang/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Provides utility functions and higher-order components for working with webOS Sign Language APIs.
*
* @module webos/signlang
* @exports signLang
* @exports SignLangDecorator
*/

import signLang from './signLang';
import SignLangDecorator from './SignLangDecorator';

export {
signLang,
SignLangDecorator
};
92 changes: 92 additions & 0 deletions packages/webos/signlang/signLang.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/* eslint-disable no-console */

import LS2Request from '../LS2Request';
import { platform } from '../platform';
import { info } from '@enact/webos/pmloglib';

let signLangEnabled = null;
let appId = null;

Check warning on line 8 in packages/webos/signlang/signLang.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/signLang.js#L7-L8

Added lines #L7 - L8 were not covered by tests

const checkSignLang = () => new Promise((resolve, reject) => {

Check warning on line 10 in packages/webos/signlang/signLang.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/signLang.js#L10

Added line #L10 was not covered by tests
if (signLangEnabled === null) {
new LS2Request().send({

Check warning on line 12 in packages/webos/signlang/signLang.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/signLang.js#L12

Added line #L12 was not covered by tests
service: 'luna://com.webos.settingsservice',
method: 'getSystemSettings',
subscribe: true,
parameters: {
'keys': ['signLanguageGuidance'],
'category': 'option'
},
onSuccess: function (res) {
info('enact_signlang_checkSignLang', { "onSuccess": res }, '');

Check warning on line 21 in packages/webos/signlang/signLang.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/signLang.js#L20-L21

Added lines #L20 - L21 were not covered by tests

if (res && res.settings.signLanguageGuidance === 'on') {
signLangEnabled = true;

Check warning on line 24 in packages/webos/signlang/signLang.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/signLang.js#L24

Added line #L24 was not covered by tests
appId = typeof window == 'object' && window.PalmSystem && window.PalmSystem.getIdentifier && window.PalmSystem.getIdentifier();
resolve();
return;

Check warning on line 27 in packages/webos/signlang/signLang.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/signLang.js#L26-L27

Added lines #L26 - L27 were not covered by tests
}

signLangEnabled = false;
reject();

Check warning on line 31 in packages/webos/signlang/signLang.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/signLang.js#L30-L31

Added lines #L30 - L31 were not covered by tests
},
onFailure: function (err) {
info('enact_signlang_checkSignLang', { "onFailure": err }, '');

Check warning on line 34 in packages/webos/signlang/signLang.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/signLang.js#L33-L34

Added lines #L33 - L34 were not covered by tests

reject('Failed to get sign language setting value: ' + JSON.stringify(err));

Check warning on line 36 in packages/webos/signlang/signLang.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/signLang.js#L36

Added line #L36 was not covered by tests
}
});
} else if (signLangEnabled) {
resolve();
} else {
reject();

Check warning on line 42 in packages/webos/signlang/signLang.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/signLang.js#L40-L42

Added lines #L40 - L42 were not covered by tests
}
});

const requestSignLang = (signLangId, focusOut, option) => () => new Promise((resolve, reject) => {
const parameters = { 'appId': appId, 'signGuidanceId': signLangId, 'focusOut': focusOut, ...option };

Check warning on line 47 in packages/webos/signlang/signLang.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/signLang.js#L46-L47

Added lines #L46 - L47 were not covered by tests

info('enact_signlang_requestSignLang', parameters, '');

Check warning on line 49 in packages/webos/signlang/signLang.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/signLang.js#L49

Added line #L49 was not covered by tests

new LS2Request().send({

Check warning on line 51 in packages/webos/signlang/signLang.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/signLang.js#L51

Added line #L51 was not covered by tests
service: 'luna://com.webos.service.signlanguageavatar',
method: 'play',
parameters: parameters,
onSuccess: resolve,
onFailure: (err) => {
info('enact_signlang_requestSignLang', { "onFailure": err }, '');

Check warning on line 57 in packages/webos/signlang/signLang.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/signLang.js#L56-L57

Added lines #L56 - L57 were not covered by tests

reject('Failed to requestSignLang: ' + JSON.stringify(err));

Check warning on line 59 in packages/webos/signlang/signLang.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/signLang.js#L59

Added line #L59 was not covered by tests
}
});
});

/**
* Request sign language when sign language is enabled.
*
* @function
* @param {String} text Text used in sign language.
* @param {Boolean} [focusOut=false] Control the start and stop of sign language.
* @param {Object} [option={}] Additional option in sign language.
* @returns {undefined}
* @memberof webos/signlang
* @public
*/
const signLang = (signLangId, focusOut = false, option = {}) => {
if (platform.tv) {
checkSignLang()

Check warning on line 77 in packages/webos/signlang/signLang.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/signLang.js#L77

Added line #L77 was not covered by tests
.then(requestSignLang(signLangId, focusOut, option))
.catch(message => {

Check warning on line 79 in packages/webos/signlang/signLang.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/signLang.js#L79

Added line #L79 was not covered by tests
if (message) {
console.error(`Failed to requestSignLang: ${message}`);

Check warning on line 81 in packages/webos/signlang/signLang.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/signLang.js#L81

Added line #L81 was not covered by tests
}
});
} else {
console.warn('Platform doesn\'t support sing language api.');

Check warning on line 85 in packages/webos/signlang/signLang.js

View check run for this annotation

Codecov / codecov/patch

packages/webos/signlang/signLang.js#L84-L85

Added lines #L84 - L85 were not covered by tests
}
};

export default signLang;
export {
signLang
};

0 comments on commit 100bce1

Please sign in to comment.