Controlling Cameras and Devices

The Smarter AI platform libraries give you control to manage who can edit and view your cameras and devices. Each of your cameras and devices are called an Associated Endpoint and the list of all your Associated Endpoints are referred as Access Control List (ACL). This section describes how to fetch and manage associated endpoints, share access to other users and manage their roles.

Getting Associated Endpoints

📘

Android

  1. To get all associated endpoints, attach the interface Access.AssociatedEndpointsListener to Access by calling RegisterAssociatedEndpointsListener(AssociatedEndpointsListener listener) method of Access class.
AnyConnectApi.get().getAccess().RegisterAssociatedEndpointsListener(listener);
  1. Then call getAssociatedEndpoints() method of Access to get all associated endpoints.
Access.AccessRet getAssociatedEndpointResult = AnyConnectApi.get().getAccess().getAssociatedEndpoints();
  1. Calling the getAssociatedEndpoints() method is asynchronous and once the endpoints are fetched, they are posted in the onAclReceive(int apiStatus, AssociatedEndpoint[] endpoints) method of the registered interface.
listener = new Access.AssociatedEndpointsListener() {
    @Override
    public void onAclReceive(int apiStatus, Access.AssociatedEndpoint[] endpoints) {
            // apiStatus 0 for success. Error otherwise
            // endpoints is an array of Access.AssociatedEndpoint
            // See JavaDoc for Access.AssociatedEndpoint
    }
};

An apiStatus and the array of the Associated Endpoints are provided through the parameter of onAclReceive method.
Unregister the attached interface in onAclReceive after receiving a response.

📘

iOS

  1. To get all associated endpoints, call getAssociatedEndpoints(AssociatedEndpointCallback callback) method of Access class to register callback function.

Declaration of AssociatedEndpointCallback is:

typedef std::function<void(const int apiStatus, const std::vector<std::shared_ptr<types::AssociatedEndpoint>> associatedEndpoints)AssociatedEndpointCallback;
  1. Calling the getAssociatedEndpoints(AssociatedEndpointCallback callback) method is asynchronous and once the endpoints are fetched, you will start receiving endpoints through callback function.
AccessRet getAssociatedEndpointResult = access->getAssociatedEndpoints([self](const int apiStatus, std::vector<std::shared_ptr<types::AssociatedEndpoint>> associatedEndpointList) {
        // apiStatus 0 for success. Error otherwise
        // endpoints is an array of AssociatedEndpoint
        // See AccessTypes.h for AssociatedEndpoint
    });
    if (getAssociatedEndpointResult != AccessRet::OK) {
        // Error while fetching endpoints
    } else {
        // Got registered endpoints successfully
    }

An apiStatus and the array of the Associated Endpoints are provided through the parameter of AssociatedEndpointCallback method.

See the Status Codes for Access Library section for more details of apiStatus.

Getting Presence of Associated Endpoints

📘

Android

  1. To get the presence of your Associated Endpoints, prepare a String array endpointIds which will contain the IDs of the endpoints whose presence you want to fetch.
  2. Then attach the interface Access.GetPresenceListener to Access by calling RegisterGetEndpointPresenceListener(GetPresenceListener listener) method of Access class.
AnyConnectApi.get().getAccess().RegisterGetEndpointPresenceListener(getPresenceListener);
  1. Then call getPresence(String[] endpointIds) method of Access by passing the endpointIds in the parameter.
AnyConnectApi.get().getAccess().getPresence(endpointIds);
  1. Calling getPresence(String[] endpointIds) is asynchronous and once the presence of the specified endpoints arrive, they are posted to the onPresenceStatus(int apiStatus, String[] presenceStatus) method of the registered interface.
getPresenceListener = new Access.GetPresenceListener() {
    @Override
    public void onPresenceStatus(int apiStatus, String[] presenceStatus) {
        // apiStatus 0 for success. Error otherwise
        // presenceStatus is an array containing presence of specified endpoints
        // each element of presenceStatus contains presence as endpointId=presence format
    }
};

When the response arrives, an apiStatus with a list containing the presences of all specified endpoints are provided in the onPresenceStatus method.
Iterate on presenceStatus to get the presence of all specified endpoints. Each element of presenceStatus contains data in endpointId=Presence format.
Presence of each endpoint can either be Online or Offline. Unregister the attached interface in onPresenceStatus after getting the response.

📘

iOS

  1. To get presence of Associated Endpoints, prepare a vector endpointIds containing the IDs of the endpoints whose presence you want to fetch.
  2. Then call getPresence(const std::vector<types::Endpoint>& endpointIds, PresenceStatusCallback callback) method of Access class to register callback function.

Declaration of PresenceStatusCallback is:

typedef std::function<void(const int apiStatus, const std::map<Endpoint, PresenceStatus>& presenceStatus)> PresenceStatusCallback;
  1. Calling the getPresence(const std::vector<types::Endpoint>& endpointIds, PresenceStatusCallback callback) method is asynchronous and once the presence of your specified endpoints arrives, you will receive it through the callback function.
AccessRet getPresenceOfEndpointResult = access->getPresence(endpointIds, [self] (const int apiStatus, const std::map<Endpoint, PresenceStatus>& presenceStatus) {
        // apiStatus 0 for success. Error otherwise
    });
    if (getPresenceOfEndpointResult != AccessRet::OK) {
        //getPresence Failed
    }

When the response arrives, an apiStatus with a list containing the presences of specified endpoints are provided as a Map of endpointID vs presenceStatus. Iterate on this map for getting presence of all specified endpoints. Presence of each endpoint can either be Online or Offline.

See the Status Codes for Access Library section for more details of apiStatus.

Sharing Access of Associated Endpoints

Using the Smarter AI platform library, you can share the access of your Associated Endpoints.
To share access of your endpoints with other users, you must define the role of that user.
Each role enables certain capabilities of a user to the endpoint.
Currently there are 3 types of roles in Smarter AI platform library.

The capabilities of these roles are given below.

Owner
Manage endpoint information, Manage users, Reset endpoint, Stream

Admin
Manage endpoint information, Manage users, Stream

Viewer
Stream

Add New User to an Endpoint

📘

Android

  1. To add a new user to an endpoint, attach the Access.AssociationCompleteListener interface to Access by calling the RegisterAssociationCompleteListener(AssociationCompleteListener listener) method of Access class.
AnyConnectApi.get().getAccess().RegisterAssociationCompleteListener(associationCompleteListener);
  1. Then call associateEndpoint(String endpointId, String userEmail, PeerRole role) method of Access class by passing the endpointId, userEmail and role of the user in parameter.
AnyConnectApi.get().getAccess().associateEndpoint(endpointId, userEmail, Access.PeerRole.Admin);

Calling associateEndpoint method adds the user with specified privilege to the specified endpoint.
If you want to add someone as a Viewer, provide Access.PeerRole.Viewer as the last parameter of the associateEndpoint method.
In associateEndpoint method, only Admin and Viewer is applicable as a PeerRole.

  1. This method call is asynchronous and once the response arrives, it's posted to the onAssociationComplete(int status) with a status in the parameter.
associationCompleteListener = new Access.AssociationCompleteListener() {
    @Override
    public void onAssociationComplete(int status) {
    // status 0 for success. Error otherwise
    }
};

📘

iOS

  1. To add a new user to an endpoint, call associateEndpoint(Endpoint endpointId, std::string userEmail, PeerRole role, ApiStatusCallback callback) method of the Access class.
AccessRet accessRet = access->associateEndpoint(endpointId, userEmail, PeerRole::Admin, [self](const int apiStatus){
    // apiStatus 0 for success. Error otherwise
});
  1. Calling associateEndpoint(Endpoint endpointId, std::string userEmail, PeerRole role, ApiStatusCallback callback) method adds the user with specified privileges to the specified endpoint.

    If you want to add someone as a Viewer, provide PeerRole::Viewer as the parameter of the associateEndpoint method.
    In associateEndpoint method, only Admin and Viewer is applicable as a PeerRole.

  2. This method call is asynchronous and once the response arrives, you will receive it through the ApiStatusCallback callback method.

Declaration of ApiStatusCallback is:

typedef std::function <void(const int& status)> ApiStatusCallback;

See the Status Codes for Access Library section for more details of apiStatus.

Get All Associated Users of an Endpoint

📘

Android

  1. To get all the associated users of a particular endpoint, attach the
    Access.AssociatedUsersListener interface to Access by calling the RegisterAssociatedUsersListener(AssociatedUsersListener listener) method of the Access class.

    ```java
    AnyConnectApi.get().getAccess().RegisterAssociatedUsersListener(associatedUsersListener);
    ```
    
  2. Then call getAssociatedUsers(String endpointId) method of Access with endpointId in the parameter.

    AnyConnectApi.get().getAccess().getAssociatedUsers(endpointId);
    
  3. Calling getAssociatedUsers is asynchronous and once the response arrives, it is posted to the onReceiveUsers(int apiStatus, String endpointId, Access.AssociatedUser[] users) method of the registered interface with an apiStatus, endpointId and an array of the AssociatedUser.

    ```java
    associatedUsersListener = new Access.AssociatedUsersListener() {
    @Override
    public void onReceiveUsers(int apiStatus, String endpointId, Access.AssociatedUser[] users) {
        // apiStatus 0 for success. Error otherwise
        // endpointId is same as the provided endpointId of getAssociatedUsers
        // users is an array of Access.AssociatedUser
        // See Access JavaDoc for more details of Access.AssociatedUser
    }
    };
    ```
    

    Unregister the attached interface after the response has arrived in onReceiveUsers method.

📘

iOS

  1. To get all associated users, call the getAssociatedUsers(Endpoint endpointId, AssociatedUserCallback callback) method of the Access class to register callback function.

Declaration of AssociatedUserCallback is:

typedef std::function<void(const int apiStatus, const std::vector<std::shared_ptr<types::AssociatedUser>> associatedUsers)> AssociatedUserCallback;
  1. Calling the getAssociatedUsers(Endpoint endpointId, AssociatedUserCallback callback) method is asynchronous and once the users are fetched, you will start receiving users through the callback function.
AccessRet getAssociatedUsersResult  = access->getAssociatedUsers(endpointID, [self] (const int apiStatus, const std::vector<std::shared_ptr<types::AssociatedUser>> associatedUsers){
        // apiStatus 0 for success. Error otherwise
        // endpointId is same as the provided endpointId of getAssociatedUsers
        // users is an array of AssociatedUser
        // See AccessTypes.h for more details of AssociatedUser
    });

    if (getAssociatedUsersResult != OK) {
        // Error while fetching AssociatedUser
    } else {
        // AssociatedUser fetch successfully
    }

An apiStatus and the array of the Associated AssociatedUser are provided through the parameter of the AssociatedUserCallback method.

See the Status Codes for Access Library section for more details of apiStatus.

Update Role of Existing Associated User

📘

Android

  1. To update the role of an existing user of a particular endpoint, attach Access.AssociationUpdateListener interface to Access by calling RegisterAssociationUpdateListener(AssociationUpdateListener listener) method of the Access class.
AnyConnectApi.get().getAccess().RegisterAssociationUpdateListener(associationUpdateListener);
  1. Then call the updateAssociationRole(String endpointId, String userId, PeerRole role) method of the Access class with endpointId, userId and the new role of that user.
    This new role can be Admin or Viewer.
AnyConnectApi.get().getAccess().updateAssociationRole(endpointId, userId, Access.PeerRole.Viewer);
  1. Calling updateAssociationRole is asynchronous and once the response arrives, it's posted to the onAssociationUpdate(int status) with a status.
associationUpdateListener = new Access.AssociationUpdateListener() {
    @Override
    public void onAssociationUpdate(int status) {
        // status 0 for success. Error otherwise
    }
};

Unregister the attached interface after getting the response in onAssociationUpdate.

📘

iOS

  1. To update the role of an existing user of a particular endpoint, you need to call the updateAssociationRole(Endpoint endpointId, uint64_t userId, PeerRole role, ApiStatusCallback callback) method of the Access class with endpointId, userId and the new role of that user.

Declaration of ApiStatusCallback is:

typedef std::function <void(const int& status)> ApiStatusCallback;
  1. Calling the updateAssociationRole(Endpoint endpointId, uint64_t userId, PeerRole role, ApiStatusCallback callback) method is asynchronous and once the response arrives, you will receive through callback ApiStatusCallback method with a status.
AccessRet accessRet = access->updateAssociationRole(endpointID, userID, PeerRole::Viewer, [self](const int apiStatus) {
    // status 0 for success. Error otherwise
});

See the Status Codes for Access Library section for more details of apiStatus.

Remove Associated User from Endpoint

📘

Android

  1. To remove a particular user from an Associated Endpoint, attach the Access.RemoveAssociationCompleteListener interface to Access by calling the RegisterRemoveAssociationCompleteListener(RemoveAssociationCompleteListener listener) method of the Access class.
AnyConnectApi.get().getAccess().RegisterRemoveAssociationCompleteListener(removeAssociationCompleteListener);

  1. Then call removeAssociation(String endpointId, String userId) with the endpointId of the Associated Endpoint and the userId of the user that needs to be removed.
AnyConnectApi.get().getAccess().removeAssociation(endpointId, userId);
  1. Calling removeAssociation method is asynchronous and when the response arrives, it's posted to the onCompleteAssociationRemove(int status, String userId) method with a status and the userId of the removed user.
removeAssociationCompleteListener = new Access.RemoveAssociationCompleteListener() {
    @Override
    public void onCompleteAssociationRemove(int status, String userId) {
        // status 0 for success. Error otherwise
        // userId indicates the Id of removed user
    }
};

Unregister the attached interface after getting the response in onCompleteAssociationRemove.

📘

iOS

  1. To remove a particular user from an Associated Endpoint, call removeAssociation(Endpoint endpointId, uint64_t userId, ApiStatusCallback callback) method of the Access class with the endpointId of your associated endpoint and the userId of the user that need to be removed.

Declaration of ApiStatusCallback is:

typedef std::function <void(const int& status)> ApiStatusCallback;
  1. Calling removeAssociation(Endpoint endpointId, uint64_t userId, ApiStatusCallback callback) method is asynchronous and when the response arrives, you will receive it through callback ApiStatusCallback method with a status.
AccessRet removeAssociationResult = access->removeAssociation(endpointID, userID, [self](const int apiStatus) {
    // status 0 for success. Error otherwise
});

See the Status Codes for Access Library section for more details of apiStatus.

Updating Endpoint Information

📘

Android

  1. To update information of an Associated Endpoint, create an instance of Access.EndpointUpdateRequest and set the fields which needs to be update.
    You can update only one field at a time.
Access.EndpointUpdateRequest updateRequest = AnyConnectApi.get().getAccess().new EndpointUpdateRequest();
updateRequest.setLabel("Sweet home camera");

In the above code snippet, an instance of Access.EndpointUpdateRequest is created and the label has been set.

  1. Next, attach Access.EndpointInfoUpdateListener interface to Access by calling the RegisterEndpointInfoUpdateListener(EndpointInfoUpdateListener listener) method of the Access class.
AnyConnectApi.get().getAccess().RegisterEndpointInfoUpdateListener(endpointInfoUpdateListener);
  1. Then, call the updateEndpointInfo(String endpointId, EndpointUpdateRequest updateRequest) method of the Access class with endpointId and updateRequest in the parameter.
AnyConnectApi.get().getAccess().updateEndpointInfo(endpointId, updateRequest);
  1. Calling updateEndpointInfo is asynchronous and when the response arrives, it gets posted to the onEndpointUpdated(int status) method with a status.
endpointInfoUpdateListener = new Access.EndpointInfoUpdateListener() {
    @Override
    public void onEndpointUpdated(int status) {
        // status 0 for success. Error otherwise
    }
};

Unregister the attached interface once a response arrives in onEndpointUpdated.

📘

iOS

  1. To update information of an Associated Endpoint, create an instance of EndpointUpdateRequest and set the fields which you want to update.
    You can update only one field at a time.
std::shared_ptr<types::EndpointUpdateRequest> endpointUpdateRequest = std::make_shared<types::EndpointUpdateRequest>();
endpointUpdateRequest->setLabel("Sweet home camera");

In the above code snippet, an instance of EndpointUpdateRequest is created and the label has been set.

  1. Next call the updateEndpointInfo(const Endpoint endpointId, const std::shared_ptr<types::EndpointUpdateRequest> endpointInfo, ApiStatusCallback callback) method of the Access class to update label.

Declaration of ApiStatusCallback is:

typedef std::function <void(const int& status)> ApiStatusCallback;
  1. Calling the updateEndpointInfo(const Endpoint endpointId, const std::shared_ptr<types::EndpointUpdateRequest> endpointInfo, ApiStatusCallback callback) method is asynchronous and when the response arrives, you will receive it through the callback ApiStatusCallback method with a status.
AccessRet updateEndpointInfoResult = access->updateEndpointInfo(endpointID, endpointUpdateRequest, [self](const int apiStatus){
    // status 0 for success. Error otherwise
};

See the Status Codes for Access Library section for more details of apiStatus.

Getting Endpoint Information Using EndpointId

Android iOS

📘

Android

  1. To get information of a specific endpoint, attach interface Access.EndpointInfoListener to Access by calling the RegisterEndpointInfoListener(EndpointInfoListener listener) method.
AnyConnectApi.get().getAccess().RegisterEndpointInfoListener(endpointInfoListener);
  1. Then call the getEndpointInfo(String endpointId) method of Access with endpointId in the parameter.
AnyConnectApi.get().getAccess().getEndpointInfo(endpointId);
  1. Calling getEndpointInfo is asynchronous and once the response arrives, it's posted to the onEndpointReceived(int status, Access.EndpointInfo endpointInfo) method with status and endpointInfo in the parameter.
endpointInfoListener = new Access.EndpointInfoListener() {
@Override
public void onEndpointReceived(int status, Access.EndpointInfo endpointInfo) {
        // status 0 for success. Error otherwise
        // endpointInfo contains all information of the endpoint
        // See Access JavaDoc for more information of Access.EndpointInfo
}
};

Unregister the attached interface once a response arrives in onEndpointReceived.

📘

iOS

  1. To get information of a specific endpoint, call the getEndpointInfo(const Endpoint endpointId, EndpointInfoCallback callback) method of the Access class to register callback function.

Declaration of EndpointInfoCallback is:

typedef std::function<void(const int apiStatus, const std::shared_ptr<types::EndpointInfo> endpointInfo)> EndpointInfoCallback;
  1. Calling the getEndpointInfo(const Endpoint endpointId, EndpointInfoCallback callback) method is asynchronous and once the information is fetched, you will start receiving through callback function.
AccessRet ret = access->getEndpointInfo(endpointID, [self](const int& apiStatus, std::shared_ptr<types::EndpointInfo> endpointInfo){
    // apiStatus 0 for success. Error otherwise
    // See AccessTypes.h for EndpointInfo
});

See the Status Codes for Access Library section for more details of apiStatus.

Resetting Associated Endpoint

Resetting an associated endpoint will remove the endpoint for the system.

📘

Android

  1. To reset your endpoint, call resetEndpoint(String endpointId) of the Access class with endpointId as the parameter.

    AnyConnectApi.get().getAccess().resetEndpoint(endpointId);
    
  2. Calling resetEndpoint returns an AccessRet enum. If resetting an endpoint is successful, then AccessRet.OK is returned.

📘

iOS

  1. To reset your endpoint, call resetEndpoint(Endpoint endpointId) method of Access class with endpointId as the parameter.

    AccessRet accessRet = access->resetEndpoint(endpointID);
    
  2. Calling resetEndpoint method returns an AccessRet enum. If resetting an endpoint is successful, then AccessRet.OK is returned.

See the Method Return Value section for more details of AccessRet.