Backgroungeolocation engage ionic3 - background

I'm using mauron85 Backgroundgeolocation plugin for my ionic 3 application.
It works, the only problem is the timing when it engage.
The problem is even if I subscribe and start the plugin, it engage only after a couple of minutes.
Namely it returns the position in the moment that I start it, but before engaging and actively tracking it takes some time.
Also sometime when I put the app in background it does not start recording.
That is the code I used:
import { BackgroundGeolocation, BackgroundGeolocationConfig, BackgroundGeolocationResponse } from '#ionic-native/background-geolocation';
Then the consifugration and start:
let config: BackgroundGeolocationConfig = {
locationProvider: 0,
desiredAccuracy: 10,
stationaryRadius: 1,
distanceFilter: 1,
activitiesInterval: 100,
interval: 1000,
notificationTitle: 'TiCaccio is tracking you',
notificationText: 'you know it, right?'
// debug: true
};
this.backgroundGeolocation.configure(config).subscribe((location: BackgroundGeolocationResponse) => {
console.log("Background location", location);
this.lat = location.latitude;
this.lng = location.longitude;
});
this.backgroundGeolocation.start();
Now the problem is in fact that sometimes it engage, sometimes not. And even when it engage it just do that after a couple of minutes.

Related

how to get current time from videojs.wavesurfer

I want to get the current time, within the video being played when I click within the audio waveform.
I'm playing a video stream, I want to be able to pause, then add a note to a table about something within the video. So I need to get the currentTime.
I merge an audio stream with the video and play in a div.
let options = {
controls: true,
bigPlayButton: false,
autoplay: false,
loop: false,
fluid: false,
width: 1000,
height: 200,
plugins: {
// enable videojs-wavesurfer plugin
wavesurfer: {
// configure videojs-wavesurfer
backend: 'MediaElement',
displayMilliseconds: true,
debug: true,
waveColor: 'black',
progressColor: 'purple',
cursorColor: 'yellow',
hideScrollbar: true,
// put waveform in separate container
container: '#waveform'
}
}
};
let videoplayer = videojs('myClip', options, function() {
let videofile = $("#mergedVideo").text()
console.log(" Playing "+videofile)
// load wav file from url
videoplayer.src({src: videofile, type: 'video/mp4'});
});
// Here is the pause... always gives an error..
videoplayer.on('pause', function () {
let currenttime = videoplayer.getCurrentTime();
$('#currentTime').text(currenttime);
alert(" PAUSED ")
});
but i'm getting videoplayer.getCurrentTime is not a function in console. I have this working perfectly for just audio streams.
Any help would be grealty appreciated.
It's currentTime(). There's a getCurrentTime() on the lower level tech abstraction, but you shouldn't (need to) use it directly.

Expo Notifications repeats after a specified date

Im trying to schedule a daily notification with expo notifications. I need to fire this notification from a specified date in the future. So it will be for example: schedule the notification on 20 days in the future and from there fire it daily until cancelled. How can't find anything in the documentation on how to do this. Does anyone have an idea?
You can set a starting date like this:
await Notifications.scheduleNotificationAsync({
content: {
title,
body,
sound: true,
vibrate: [0, 255, 255, 255],
},
trigger: {
date: "your-date"
},
});
Later on you can switch on repeats like this:
trigger: {
repeats: true //or false
},
I'm not sure what you mean by fire until cancelled. Should the user specifically cancel the notification or is som state variable changing? Either way, I think you can add repeats: true or false depending on any variable.
Hope this helps!

React Native expo-location: How to make the background location service update more often?

I'm building a sports app with Expo / React Native and trying to figure out a good way to track user location while the app is in the background. I have built a solution with expo-location (https://docs.expo.io/versions/latest/sdk/location/#locationstartlocationupdatesasynctaskname-options) which successfully receives location updates, and I even managed to send the location updates to the UI with the help of an EventEmitter.
Now the problem here is, the Expo Location task keeps the location updates deferred for a VERY long time (like 12 minutes) before sending a location update to the UI. This is despite setting all the relevant options to zero or very small.
I would love to use Expo Location because I got it mostly working, but unbelievably it seems that the library lacks an option/tool to force the background task to send updates often enough (like once in 5 seconds).
I would be grateful if anyone had a solution to really making the Expo background location send updates often enough. Now it sends updates "when I feel like it", about once in 5 or 12 minutes, despite setting all the relevant options and parameters I found in the documentation.
I already came to the conclusion that Expo background location is practically broken and I should switch to another location library (https://github.com/mauron85/react-native-background-geolocation). However I'm using Expo managed workflow and installing this mauron85 location library (otherwise really promising) doesn't work, because it requires setting manually dependencies --> I need to eject from Expo managed workflow --> ejecting breaks my project structure in a way I don't know how to solve. Really frustrating!
Relevant parts of my code:
top part:
import * as Location from 'expo-location';
import * as TaskManager from 'expo-task-manager';
import EventEmitter from 'EventEmitter'
const locationEmitter = new EventEmitter();
const BACKGROUND_LOCATION_TRACKER = 'BACKGROUND_LOCATION_TRACKER'
const LOCATION_UPDATE = 'LOCATION_UPDATE'
componentDidMount after requesting location permissions:
await Location.startLocationUpdatesAsync(BACKGROUND_LOCATION_TRACKER, {
accuracy: LocationAccuracy.BestForNavigation,
timeInterval: 0, // all set to 0 to make it update as often as possible!!! doesn't help
distanceInterval: 0,
deferredUpdatesInterval: 0,
deferredUpdatesDistance: 0,
showsBackgroundLocationIndicator: true,
foregroundService: {
notificationTitle: 'title',
notificationBody: 'recording',
notificationColor: '#008000',
},
// pausesUpdatesAutomatically: true,
});
locationEmitter.on(LOCATION_UPDATE, (locationData) => {
console.log('locationEmitter locationUpdate fired! locationData: ', locationData);
let coordinatesAmount = locationData.newRouteCoordinates.length - 1;
this.setState({
latitude: locationData.newRouteCoordinates[coordinatesAmount - 1].latitude,
longitude: locationData.newRouteCoordinates[coordinatesAmount - 1].longitude,
routeCoordinates: this.state.routeCoordinates.concat(locationData.newRouteCoordinates)
})
})
define location task:
TaskManager.defineTask(BACKGROUND_LOCATION_TRACKER, async ({ data, error }) => {
if (error) {
console.error(error);
return;
}
if (data) {
const { locations } = data;
console.log('backgroundLocationTracker received new locations: ', locations)
// const [location] = locations;
const locationsLength = locations.length;
const newRouteCoordinates = [];
// const totalNewDistance = 0.0;
for (i = 0; i < locationsLength; i++) {
const { latitude, longitude } = locations[i].coords;
const tempCoords = {
latitude,
longitude,
};
newRouteCoordinates.push(tempCoords);
// totalNewDistance += GLOBAL.screen1.calcDistance(newRouteCoordinates[i], newRouteCoordinates[i - 1])
};
console.log('backgroundLocationTracker: latitude ', locations[locationsLength - 1].coords.latitude,
', longitude: ', locations[locationsLength - 1].coords.longitude, ', routeCoordinates: ', newRouteCoordinates,
', prevLatLng: ', newRouteCoordinates[locationsLength - 1]);
let locationData = { newRouteCoordinates }
locationEmitter.emit(LOCATION_UPDATE, locationData)
}
});
As I said, it all WORKS (!) in the sense that I do get location updates from the background to the UI. The only problem here is that I can't figure out how to make the background task send location updates more often! It just keeps collecting a huge batch of 50+ location updates for even 10+ minutes before it bothers to send them to the UI!
All help appreciated, thanks.
I thought I would have to eject from expo too, but I changed my options and now it updates just as I intended.
The problem was the acuracy, I switched to "best for navigation" just as your example and it worked.
Here is my options, I think you should try to define some milisseconds, don't leave interval at 0 and don't set distance interval nor defered distance:
{accuracy: Location.Accuracy.BestForNavigation,
timeInterval: 1000,
showsBackgroundLocationIndicator: true,
foregroundService:{
notificationTitle: "Covid Tracker",
notificationBody: "Rastreando sua localização",
notificationColor: "#AA1111"
},
deferredUpdatesInterval: 100
}

Making cytoscape.js animations play continuously

Is there any way to make an animation play continuously?
Here is a demo using ani.play() but it does it only once. Not continuously.
I want a 'flashing' node. It should grow and shrink in size constantly till the user says stop.
For now, I've done this
var jAni = cy.$('#rose').animation({
style: {
'background-color': 'red',
'width': 75
},
duration: 1000
});
jAni.play();
Exactly as mentioned in the documentation for ani.play()
You must chain your promises. Auto-rewind doesn't mean auto-replay, just like a tape.
let loopAnimation = ele => {
return (
ele.animation(opts).play()
.promise('complete').then(loopAnimation)
);
};
loopAnimation(someNode);

Stop a Animated.loop with native driver - so it triggers the start callback

I am running a loop like this:
const anim = new Animated.Value(0);
const res = Animated.loop(
Animated.timing(anim, {
duration: 2000,
toValue: 1,
easing:Easing.inOut(Easing.linear),
useNativeDriver: true,
isInteraction: false
})
);
res.start(e => console.log('anim stopped, e:'));
setTimeout(()=>res.stop(), 5000); // does not trigger callback
// setTimeout(()=>anim.stopAnimation(), 5000); // does not trigger callback
The animation runs, and loops properly. (animated value goes back to 0 at start of each loop).
And the animation stops, if i do either res.stop() or anim.stopAnimation(). But the start callback never triggers. I'm worried that something is still running and I might have a memory leak. Can you please advise on how to properly stop a native driver loop?
Although I couldn't find it in the documentation, there is an optional onComplete key available on the AnimationConfig type (I found it at the top of Animation.js in the repo). The log will now appear when your animation is stopped by adding the callback inside of your configuration:
const res = Animated.loop(
Animated.timing(anim, {
duration: 2000,
toValue: 1,
easing:Easing.inOut(Easing.linear),
useNativeDriver: true,
isInteraction: false,
onComplete: (e) => console.log('anim stopped, e:') // New config option
})
);
There's no guarantee that this won't be a breaking change in the future, but it seems like a pretty safe key name to stick with, so I don't see them refactoring that anytime soon.
As for your concern about the memory leak, the Animated.loop calls the stop() method of the child animation, so you should have no concerns there.