Github user robpaveza commented on a diff in the pull request:
https://github.com/apache/cordova-plugin-vibration/pull/38#discussion_r38669813
--- Diff: src/windows/VibrationProxy.js ---
@@ -60,12 +61,43 @@ if (VibrationDevice) {
fail(e);
}
},
- vibrateWithPattern: function(success, fail, args) {
- // TODO: Implement with setTimeout.
- fail('"vibrateWithPattern" is unsupported by this platform.');
+ vibrateWithPattern: function (success, fail, args) {
+ // Cancel current vibrations first
+ module.exports.cancelVibration(function () {
+ // Removes the first zero
+ if (args[0] && args[0][0] === 0) {
+ args[0].shift(0);
+ }
+
+ patternChainPromise = args[0].reduce(function
(previousValue, currentValue, index) {
+ if (index % 2 === 0) {
+ return previousValue.then(function () {
+ return new WinJS.Promise(function (complete,
error) {
+ module.exports.vibrate(function () {},
function(err) {
+ console.error(err);
+ error(err);
+ }, [currentValue]);
+
+ setTimeout(function () {
+ complete();
+ }, parseInt(currentValue, 10));
+ });
+ });
+ } else {
+ return previousValue.then(function () {
+ return new WinJS.Promise(function (complete) {
--- End diff --
Prefer `WinJS.Promise.timeout(parseInt(currentValue, 10))` to `new
WinJS.Promise( ... setTimeout(...))`.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]