Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
on{x} recipe to make pagerduty texts always play ringtone, then play annoying sound every minute until unlocked
// =====================================================================
// Crank up the volume and play an annoying sound every minute when you
// get a text from PagerDuty. Put things back when you unlock the screen.
// @intjonathan
// =====================================================================
var strVersion = 'v0.3';
var lngInterval = 1*60*1000; // 1 minute
var strAlarmFilePath = "file:///mnt/sdcard/Music/Ringer.mp3";
console.log('Started script: Repeat smsReceive buzz and sound until unlock phone.');
// Register callback on sms received event
device.messaging.on('smsReceived', function (sms) {
console.info('sms received from', sms.data.from, 'with the following body:', sms.data.body);
if (device.screen.isLocked && sms.data.from == '12817243738')
{
device.localStorage.setItem('alarmPath', strAlarmFilePath);
playAudio = device.audio.ringerMode == 'normal' ? 'true' : 'false';
device.localStorage.setItem('playPageAudio', playAudio);
device.localStorage.setItem('oldRingVolume', device.audio.ringerVolume);
device.localStorage.setItem('oldMediaVolume', device.media.volume);
if (playAudio == 'true') {
device.audio.ringerVolume = 100;
device.media.volume = 80;
device.applications.launchViewer(device.localStorage.getItem('alarmPath'), "audio/*");
}
var now = new Date();
device.scheduler.setTimer(
{
name: "smsReceivedAlarm",
time: now.getTime() + lngInterval,
interval: lngInterval,
exact: false
},
function () {
device.signals.emit('repeatNotification');
}
);
}
});
// Annoying notification
device.signals.on("repeatNotification", function(signal) {
device.audio.vibrate(1000);
if(device.localStorage.getItem('playPageAudio') == 'true') {
device.applications.launchViewer(device.localStorage.getItem('alarmPath'), "audio/*"); // Play Alarm Sound
}
});
// Teardown the alarm and volume boosts on unlock
device.screen.on("unlock", function() {
if(device.localStorage.getItem('oldMediaVolume')) {
console.info('Unlock screen and stop timer.');
device.scheduler.removeTimer("smsReceivedAlarm");
device.media.volume = device.localStorage.getItem('oldMediaVolume');
device.audio.ringerVolume = device.localStorage.getItem('oldRingVolume');
storage.clear();
}
});
console.log('Completed script: Repeat smsReceive alarm until unlock phone');
console.log('Running version : ' + strVersion);
@brandon-dacrib

This comment has been minimized.

Copy link

@brandon-dacrib brandon-dacrib commented Oct 5, 2012

I get an error on line #62 "Javascript Exception:ReferenceError: "storage" is not defined. I am using on x 0.59.1. Any clues?

@brandon-dacrib

This comment has been minimized.

Copy link

@brandon-dacrib brandon-dacrib commented Oct 9, 2012

I did try commenting that line out to no avail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.