P粉5503233382023-09-06 00:32:52
What you want to do is really difficult. Synchronizing such a device is difficult. Doing this is nearly impossible when you don't own and control the hardware. Frankly, I don't think you'll ever get what you want.
Timestamps never work. For one, these devices won't all have the same timing. They will all be slightly off. Your next idea is to send them the time from a central source such as your server. The problem is that sending data to each device will take a different, random amount of time. You could try to guess the latency by pre-calculating the round-trip time for a dozen packets, but that's still a guess and may not be accurate for the next packet. NTP helps keep devices' times close to the same time, but not as precise as you want.
Even if it does achieve the accuracy you want - Android is not a real-time operating system. Not so with the iPhone. Even if you set your alarm for 12:00:00, it won't fire at exactly 12:00:00.000. Sometime after that, it will fire when the operating system has idle time, idle cores, and considers your application to be the most important scheduled application. This may take hundreds of milliseconds. There are operating systems that can give you the promise you want. Known as real-time operating systems, they are often used in embedded devices that cannot fail, such as medical equipment and controllers for expensive machines. They are a completely different approach to writing operating systems than those used by consumer devices.
I would really recommend rethinking your needs and being more realistic about them. There are technologies that allow you to get what you want, but not on random hardware on consumer operating systems over the Internet.
Also, if you want to do this - I really don't recommend using React Native, it runs the interpreter in a garbage collected language and has very random timing. You'll want to at least write your launcher in C, as this is the most predictable approach.
But really, please reconsider your needs. Why does it need to start within 50 milliseconds? When you do things over the internet, does it really matter if people are out of sync for a second?