-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1c4064
commit 100bce1
Showing
3 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = { | ||
/** | ||
* 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'); | ||
|
||
return class extends Component { | ||
static displayName = 'SignLangDecorator'; | ||
|
||
static propTypes = /** @lends webos/signlang.SignLangDecorator.prototype */ { | ||
/** | ||
* 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); | ||
|
||
this.signLangDelayId = null; | ||
} | ||
|
||
requestSignLang = (focusOut) => { | ||
const { signLangId, signLangOption = {} } = this.props; | ||
|
||
if (typeof signLangId == 'string' && signLangId.length > 0) signLang(signLangId, focusOut, signLangOption); | ||
} | ||
|
||
onFocus = (ev) => { | ||
forwardFocus(ev, this.props); | ||
|
||
if (signLangDelay == 0) { | ||
this.requestSignLang(false); | ||
} else { | ||
clearTimeout(this.signLangDelayId); | ||
this.signLangDelayId = setTimeout(() => { | ||
this.requestSignLang(false); | ||
}, signLangDelay); | ||
} | ||
} | ||
|
||
onBlur = (ev) => { | ||
forwardBlur(ev, this.props); | ||
|
||
if (signLangDelay > 0) clearTimeout(this.signLangDelayId); | ||
|
||
this.requestSignLang(true); | ||
} | ||
|
||
render() { | ||
const props = Object.assign({}, this.props); | ||
delete props.onFocus; | ||
delete props.onBlur; | ||
delete props.signLangId; | ||
delete props.signLangDelay; | ||
delete props.signLangOption; | ||
|
||
return ( | ||
<Wrapped | ||
{...props} | ||
onFocus={this.onFocus} | ||
onBlur={this.onBlur} | ||
/> | ||
); | ||
} | ||
}; | ||
}); | ||
|
||
export default SignLangDecorator; | ||
export { SignLangDecorator }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
const checkSignLang = () => new Promise((resolve, reject) => { | ||
if (signLangEnabled === null) { | ||
new LS2Request().send({ | ||
service: 'luna://com.webos.settingsservice', | ||
method: 'getSystemSettings', | ||
subscribe: true, | ||
parameters: { | ||
'keys': ['signLanguageGuidance'], | ||
'category': 'option' | ||
}, | ||
onSuccess: function (res) { | ||
info('enact_signlang_checkSignLang', { "onSuccess": res }, ''); | ||
|
||
if (res && res.settings.signLanguageGuidance === 'on') { | ||
signLangEnabled = true; | ||
appId = typeof window == 'object' && window.PalmSystem && window.PalmSystem.getIdentifier && window.PalmSystem.getIdentifier(); | ||
resolve(); | ||
return; | ||
} | ||
|
||
signLangEnabled = false; | ||
reject(); | ||
}, | ||
onFailure: function (err) { | ||
info('enact_signlang_checkSignLang', { "onFailure": err }, ''); | ||
|
||
reject('Failed to get sign language setting value: ' + JSON.stringify(err)); | ||
} | ||
}); | ||
} else if (signLangEnabled) { | ||
resolve(); | ||
} else { | ||
reject(); | ||
} | ||
}); | ||
|
||
const requestSignLang = (signLangId, focusOut, option) => () => new Promise((resolve, reject) => { | ||
const parameters = { 'appId': appId, 'signGuidanceId': signLangId, 'focusOut': focusOut, ...option }; | ||
|
||
info('enact_signlang_requestSignLang', parameters, ''); | ||
|
||
new LS2Request().send({ | ||
service: 'luna://com.webos.service.signlanguageavatar', | ||
method: 'play', | ||
parameters: parameters, | ||
onSuccess: resolve, | ||
onFailure: (err) => { | ||
info('enact_signlang_requestSignLang', { "onFailure": err }, ''); | ||
|
||
reject('Failed to requestSignLang: ' + JSON.stringify(err)); | ||
} | ||
}); | ||
}); | ||
|
||
/** | ||
* 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() | ||
.then(requestSignLang(signLangId, focusOut, option)) | ||
.catch(message => { | ||
if (message) { | ||
console.error(`Failed to requestSignLang: ${message}`); | ||
} | ||
}); | ||
} else { | ||
console.warn('Platform doesn\'t support sing language api.'); | ||
} | ||
}; | ||
|
||
export default signLang; | ||
export { | ||
signLang | ||
}; |