What are Streamie Functions? What can I do with them? How do they work? The shortest answer is this: Functions allow you to extend Streamie’s functionality. Some customer requirements are so unique that finding a generally useful way to implement the feature isn’t practical. Functions are the answer to that question. In fact, that was the original motivation for the feature.
Note: You can find API information for Functions here.
We are presently working on a contract that requires in-app support for activating a siren / strobe alarm attached to some of the cameras. The camera has a proprietary API for controlling the alarm. Additionally, you must be on the same network as the company to make that API call. Streamie allows users to seamlessly access cameras remotely, so the user expectation is that tapping a button will activate the alarms whether one is local or remote. It needs to “just work”. Additionally, the nature of the proprietary API is that there’s no good way to make a direct implementation in Streamie somehow generally useful for other people. Let’s solve this problem with Functions.
A Function is defined by some source code (written in JavaScript, at the moment), a set of buttons, cameras, file servers, members and functions. Yes, a Function can reference other Functions, which is key to this solution. We’ll create one function (the “first function”) that implements the camera’s API call for activating / deactivating the alarm, and then another function (the “second function”) that tells one or more devices to run the first function. The end user will exclusively use the second function.
The First Function For this solution, we need the first function to include the list of cameras with alarms attached to them and a simple API call to activate / deactivate the alarm, depending on which button is pressed. This solves the problem as long as the device on which you tap the button is presently connected to the same network as the cameras with the alarms.
The Second Function We’re also going to make a 2nd Function that runs the 1st Function on a specific member device. We have one or more always-on Streamie member devices at each physical location, and we want one of those devices to actually run the 1st Function. We use the Member Control functionality that’s accessible in the Home ==> Members ==> |Member| screen via JavaScript to send a command to that device to run the 1st function.
The Result Whether home or away, a user can tap the alarm on/off button, and it will “just work”.
Before we jump into code and screenshots, it’s worth mentioning that you don’t have to manually trigger functions: for any ONVIF or UniFi camera that supports motion events (or other event types), you can create a Run Function action. If you want one (or more) alarms to activate when motion is detected between certain hours (for instance), Streamie can do that. Additionally, you can edit a camera and specify which Functions should be accessible to you when streaming that camera. If you see a problem, just tap on the camera while its still streaming and choose the Alarm function.
This Function’s configuration is simple: we’ve got an Alarm Start and an Alarm Stop button, and we provide a list of all of the cameras that include attached alarms. The two buttons have corresponding values of “alarm-start” and “alarm-stop” for which the source code of this Function will check.
This Function can be run in two different contexts: in the context of a specific camera, or not. Our streamieMain() function handles this distinction.
If you are streaming a camera and you run this function, we want the function to apply just to that specific camera. If you add a Run Function action to a camera that’s triggered by a motion event, we want this function to apply just to that specific camera. In contrast, if you tap on one of the buttons, we want it to apply to all of the cameras we’ve listed in the function.
Here’s the source code.
This is functional and it is adequate as long as we are local to the cameras. However, we need to solve the problem of having a single method to activate the alarms that works whether we are local or remote. This is what the user will expect. The user shouldn’t have to reason about localities in a critical moment.
Here’s our 2nd Function’s configuration. The key elements of this Function are (1) selecting the Member devices that will run the 1st Function we created, and (2) selecting the Function Button that we want to run on those member devices.
The source code is very simple. We get the list of member devices from the function’s configuration and the list of function buttons. For each member device, we send it a runFunction() command with the function-and-button you’ve specified.
Using Permission Groups, we can prevent the end user from having access to the 1st Alarm Function entirely, and only access to this 2nd Alarm Function. The user should be allowed to run the function, but not edit the code or configuration. As long as the alway-on devices we’ve specified in the 2nd Alarm function have access to the 1st Alarm function, we’re golden.
Don’t forget that you can import and export your Functions for backup purposes or to share with others. Additionally, within Streamie you can use the Discover button found in Home ==> Functions ==> Options ==> Add Function to browse some example Functions (including the content from above) we’ve created that can serve as a starting point for making your own. This is also very necessary because we lack anything remotely resembling adequate API documentation, so you’re going to have to browse our example source code to know what’s possible.
Created: 3 months ago
Updated: 2 months ago
Author: Curtis Jones
Streamie provides a best-in-class user experience on your iPhone, iPad, Apple TV and Apple Silicon Mac, with an intuitive user interface that makes it simple to discover, stream, record, monitor and share your HomeKit, Google Nest, Ubiquiti UniFi Protect and ONVIF-compatible IP and RTSP cameras. Streamie keeps you informed with motion event notifications and it works with most cameras using its advanced audio and video codec support. You can watch your cameras from anywhere, record 24/7 to your private NAS, remotely manage multiple locations, device permissions and seamlessly synchronize settings across your devices; configure Hubitat smart home automations, live stream to YouTube and rely on the in-app technical support system when you need help -- and you can also reach us by phone. Download Streamie today for all of your CCTV needs.