Module: Network

Network API This file defines the Connection singleton, which is the entry point of the Network API. It is an abstraction layer over the communication with the Mobile server. It encapsulates the low-level XML creation and parsing. It is responsible for creating the high-level ConnectionRequest, ConnectionResponse, VideoConnection and ItemHeaderParser instances.

Classes

Connection
ConnectionObserverInterface

Methods

(inner) Disconnect(params, successCallback, failCallback)

Sends a disconnect command to the server. Performing any other normal requests that requires a valid connectionId will not be possible from now on.
Parameters:
Name Type Description
params Object Parameters to sent to the server. May contain:
- {String} ConnectionId - Connection ID retrieved from Connect command
- {String} ProcessingMessage - (optional) [Yes/No] Indicates whether processing
                               messages should be sent from server while
                               processing the request. Default depends on the
                               value in connect command.
successCallback function function that is called when the command execution was successful and the result is passed as a parameter.
failCallback function function that is called when the command execution has failed and the error is passed as a parameter.

(inner) GetBookmarks(params, successCallback, failCallback)

Gets a list of bookmarks. There are 3 valid usages of the command. The first one is to provide Count in order to retrieve only the latest bookmarks. The second one is to provide BookmarkId in order to retrieve a single bookmark. And the last one is to get a list of bookmarks searching from specified bookmark - than BookmarkId and Count should be provided.
Parameters:
Name Type Description
params Object Parameters to sent to the server. May contain:
- {String} BookmarkId - GUID of the Bookmark.
						   If specified along with Count, StartTime will be ignored and the Bookmark will be considered as a start time of the search interval.
						   If only BookmarkId is specified than single bookmark will be returned as a result
- {Number} Count - Maximum number of bookmarks to be returned in the result. If you want to retrieve a specific bookmark you should not specify the count, but provide the BookmarkId only.
- {String} StartTime - (Optional) Start time of the search interval. It specifies from where the search of bookmark will begin. If not specified current time will be considered as a start time.
- {String} EndTime - (Optional) End time of the search interval. If the EndTime is set before the StartTime than the bookmarks will be returned in reversed order again starting to search from StartTime to EndTime.
- {String} MyBookmarks - (Optional)YES/NO - flag whether to send only my Bookmarks
- {String} Keyword - (Optional)Search string to appear in either of the fields 'Reference', 'Header', 'Description'
- {String} SearchCameraIds - (Optional) Included cameras GUIDs in a comma separated string
successCallback function function that is called when the command execution was successful and the result is passed as a parameter.
failCallback function function that is called when the command execution has failed and the error is passed as a parameter.

(inner) LiveMessage(params:, successCallback:, failCallback:)

Sends a LiveMessage command to the server.
Parameters:
Name Type Description
params: Object Parameters to sent to the server
successCallback: function function that is called when the command execution was successful and the result is passed as a parameter.
failCallback: function function that is called when the command execution has failed and the error is passed as a parameter.

(inner) RequestAudioStreamIn(params, successCallback, errorCallback) → {ConnectionRequest}

Sends a RequestAudioStreamIn connection command to get an upstream for audio push to the server.
Parameters:
Name Type Description
params AudioConnectionOptions Configuration. Should contain:
- {String} itemId - Id of the item (speaker), which stream is requested (GUID)
- {String} AudioEncoding - Shows the encoding of the output. Possible values - Pcm, Mp3.
- {Number} AudioSamplingRate - The audio sampling rate in Hz value
- {Number} AudioBitsPerSample - 8/16  - Audio bits per sample
- {Number} AudioChannelsNumber - 1/2 - Number of audio channels (mon or stereo)
- {String} StreamDataType - Shows if this is video, audio or metadata. Possible values - Video, Audio, MetaData.
- {String} SignalType - Type of the requested signal - Live, Playback
- {String} MethodType - Type of the method for retrieving video data - Push or Pull
- {String} StreamHeaders - Shows available stream headers. Possible values - AllPresent, NoHeaders.
- {String} Challenge - (only if CHAPSupproted is true) GUID previously given by the server
- {String} ChalAnswer - (only if CHAPSupproted is true) Challenge itself plus a SHA512 hash encoded as base64
successCallback function function that is called when the command execution was successful and a stream parameters object is passed as a parameter.
errorCallback function function that is called when the command execution has failed and an error object is passed as a parameter.
Returns:
- the ConnectionRequest object
Type
ConnectionRequest

(inner) addObserver(object:)

Adds an observer to the Connection singleton.
Parameters:
Name Type Description
object: an arbitrary object implementing the ConnectionObserverInterface interface
See:
  • ConnectionObserverInterface

(inner) cancelRequest(connectionRequest)

Cancels a request. Provide the ConnectionRequest object, returned by the method used to create it.
Parameters:
Name Type Description
connectionRequest ConnectionRequest

(inner) changeStream(videoConnection, cropping:, size:, successCallback:, failCallback:)

Sends a ChangeStream command to the server. Changes the visual part of the stream that the given videoConnection represents.
Parameters:
Name Type Description
videoConnection VideoConnection
cropping: contains top, left, bottom, and right properties for cropping
size: contains width and height properties that define the received frame size
successCallback: function function that is called when the command execution was successful and the result is passed as a parameter.
failCallback: function function that is called when the command execution has failed and the error is passed as a parameter.

(inner) closeStream(videoId)

Closes a stream by the given videoId.
Parameters:
Name Type Description
videoId String

(inner) closeStream(videoId)

Closes a stream by the given videoId.
Parameters:
Name Type Description
videoId String

(inner) connectWithId(server:, connectionId:, serverId:)

Connects to the server with an existing connectionId.
Parameters:
Name Type Description
server: String url of the server to connect to
connectionId: String token provided from external login request
serverId: String token provided from external login request

(inner) connectionCodeError()

Sent to observers when connection is in the process of logging in, a code has been sent to the server for verification, but this code is wrong.

(inner) connectionDidConnect(parameters:)

Sent to observers when connection has connected to the server and is about to send credentials
Parameters:
Name Type Description
parameters: object, the object containing the response parameters.

(inner) connectionDidDisconnect()

Sent to observers when connection to the server was closed on request via disconnect method.

(inner) connectionDidLogIn()

Sent to observers when connection has logged in.

(inner) connectionFailedToConnect()

Sent to observers when connection attempted to connect to the server but failed. Note that error may be a null object if we have failed to even parse the response from the server.

(inner) connectionFailedToConnectWithId()

Sent to observers when connecting with external connection ID has failed.

(inner) connectionFailedToLogIn()

Sent to observers when connection has failed to log in. Check the error to determine if it was due to incorrect credentials! Note that error may be a null object if we have failed to even parse the response from the server.

(inner) connectionLostConnection()

Sent to observers when connection to the server was lost.

(inner) connectionProcessingDisconnect()

Sent to observers when the disconnect command is sent.

(inner) connectionRequestSucceeded()

Sent to observers every time a request to the server has been received properly and without timeout or other terminal errors. You can use that to keep track of the connection and monitor it is properly working.

(inner) connectionRequiresCode(provider:)

Sent to observers when connection is in the process of logging in, but requires additional verification code.
Parameters:
Name Type Description
provider: string, the provider used to send a verification code.

(inner) connectionStateChanged()

Sent to observers when the connection state changes in any way
Create a temporary disposable download link.
Parameters:
Name Type Description
exportId: String the uniq id of the export.
investigationId: String the uniq id of the investigation.
exportType: String the type of the export: DB, AVI, MKV
successCallback: function function that is called when the command execution was successful and the result is passed as a parameter.
failCallback: function function that is called when the command execution has failed and the error is passed as a parameter.

(inner) deleteBookmark(id:, successCallback:, failCallback:)

Deletes bookmark by id.
Parameters:
Name Type Description
id: String the unique id of the bookmark.
successCallback: function function that is called when the command execution was successful and the result is passed as a parameter.
failCallback: function function that is called when the command execution has failed and the error is passed as a parameter.

(inner) destroy()

Destructor. As much as there is such thing in JavaScript.

(inner) getAllExports(successCallback:, failCallback:)

Gets all exports.
Parameters:
Name Type Description
successCallback: function function that is called when the command execution was successful and the result is passed as a parameter.
failCallback: function function that is called when the command execution has failed and the error is passed as a parameter.

(inner) getAllViews(successCallback:, failCallback:)

Sends a GetAllViewsAndCameras command to the server. Retrieves all folders, views and cameras in a single command.
Parameters:
Name Type Description
successCallback: function function that is called when the command execution was successful and the result is passed as a parameter.
failCallback: function function that is called when the command execution has failed and the error is passed as a parameter.

(inner) getAllViews(successCallback:, failCallback:)

Sends a GetItems command to the server. Retrieves all folders and cameras inside in a single command.
Parameters:
Name Type Description
successCallback: function function that is called when the command execution was successful and the result is passed as a parameter.
failCallback: function function that is called when the command execution has failed and the error is passed as a parameter.

(inner) getCameraCapabilities(cameraId:, successCallback:, failCallback:)

Gets the camera capabilities - export, live, playback, ptz, presets.
Parameters:
Name Type Description
cameraId: String unique ID of the camera
successCallback: function function that is called when the command execution was successful and the result is passed as a parameter.
failCallback: function function that is called when the command execution has failed and the error is passed as a parameter.

(inner) getDBStartTime(cameraId, successCallback:, failCallback:)

Gets the start time of the recordings for a particular camera.
Parameters:
Name Type Description
cameraId String
successCallback: function function that is called when the command execution was successful and the result is passed as a parameter.
failCallback: function function that is called when the command execution has failed and the error is passed as a parameter.

(inner) getExport(id:, successCallback:, failCallback:)

Gets and export by id.
Parameters:
Name Type Description
id: String the uniq id of the export.
successCallback: function function that is called when the command execution was successful and the result is passed as a parameter.
failCallback: function function that is called when the command execution has failed and the error is passed as a parameter.

(inner) getNextSequence(itemId, timestamp:, successCallback:, failCallback:)

Gets the next sequence by given time for the given cameraId.
Parameters:
Name Type Description
itemId String (Multiple items possible) ID of the item (camera) (GUID) for which are retrieved Sequences.
timestamp: Number milliseconds in UTC, a sequence after this moment will be returned
successCallback: function function that is called when the command execution was successful and the result is passed as a parameter.
failCallback: function function that is called when the command execution has failed and the error is passed as a parameter.

(inner) getOutputsAndEvents(successCallback:, failCallback:)

Sends a GetOutputsAndEvents command to the server.
Parameters:
Name Type Description
successCallback: function function that is called when the command execution was successful and the result is passed as a parameter.
failCallback: function function that is called when the command execution has failed and the error is passed as a parameter.

(inner) getPrevSequence(itemId, timestamp:, successCallback:, failCallback:)

Gets the previous sequence by given time.
Parameters:
Name Type Description
itemId String (Multiple items possible) ID of the item (camera) (GUID) for which are retrieved Sequences.
timestamp: Number milliseconds in UTC, a sequence before this moment will be returned
successCallback: function function that is called when the command execution was successful and the result is passed as a parameter.
failCallback: function function that is called when the command execution has failed and the error is passed as a parameter.

(inner) getPtzPresets(cameraId:, successCallback,)

Sends a GetPtzPresets command to the server.
Parameters:
Name Type Description
cameraId: GUID the current camera related to the presets this request will return
successCallback, function failCallback: failCallback

(inner) getSequenceInInterval(itemId, startTime:, endTime:, investigationId, successCallback:, failCallback:)

Gets all the sequences in the given interval of time.
Parameters:
Name Type Description
itemId String (Multiple items possible) ID of the item (camera) (GUID) for which are retrieved Sequences.
startTime: Number milliseconds in UTC, the start time of the interval
endTime: Number milliseconds in UTC, the end time of the interval
investigationId String The id of the investigation (export) to be used for extracting the sequences.
successCallback: function function that is called when the command execution was successful and the result is passed as a parameter.
failCallback: function function that is called when the command execution has failed and the error is passed as a parameter.

(inner) getSequencesForView(itemId, startTime:, endTime:, minTimeBetweenSequences:, successCallback:, failCallback:, seqType, itemKind)

Gets all the sequences for the view.
Parameters:
Name Type Description
itemId Array (Multiple items possible) ID of the item (camera) (GUID) for which are retrieved Sequences.
startTime: Number milliseconds in UTC, the start time of the interval
endTime: Number milliseconds in UTC, the end time of the interval
minTimeBetweenSequences: Number (optional) If sequences have time gap lower than this value (in seconds), they will be merged in one big sequence. Default value is 0
successCallback: function function that is called when the command execution was successful and the result is passed as a parameter.
failCallback: function function that is called when the command execution has failed and the error is passed as a parameter.
seqType SeqType Type of the sequences requests � enumeration (Motion, Recording, RecordingWithTrigger).
itemKind String The kind of item for which the sequences are being requested (Camera, Microphone).

(inner) getServerStatus(successCallback:, failCallback:)

Gets server statistic (CPU load, network trafic etc.)
Parameters:
Name Type Description
successCallback: function function that is called when the command execution was successful and the result is passed as a parameter.
failCallback: function function that is called when the command execution has failed and the error is passed as a parameter.

(inner) getThumbnail(cameraId:, successCallback:, failCallback:)

Sends a GetThumbnail command to the server in order to obtain an image representation for a given camera.
Parameters:
Name Type Description
cameraId: String the unique GUID of the camera
successCallback: function function that is called when the command execution was successful and the result is passed as a parameter.
failCallback: function function that is called when the command execution has failed and the error is passed as a parameter.

(inner) getUserExports(successCallback:, failCallback:)

Gets the exports for the currently logged user.
Parameters:
Name Type Description
successCallback: function function that is called when the command execution was successful and the result is passed as a parameter.
failCallback: function function that is called when the command execution has failed and the error is passed as a parameter.

(inner) getViews(viewId, successCallback:, failCallback:)

Sends a GetViews command to the server. Sub views, child of the given viewId, will be returned in the given callback.
Parameters:
Name Type Description
viewId String
successCallback: function function that is called when the command execution was successful and the result is passed as a parameter.
failCallback: function function that is called when the command execution has failed and the error is passed as a parameter.

(inner) initialize(storage:)

Initializes the Connection singleton. Must be called before using any of the other methods.
Parameters:
Name Type Description
storage: optional, the storage used to store server features in, and to initialize them from (for example XPMobileSDK.localStorage, XPMobileSDK.sessionStorage, or any object implementing their methods). The server features are retrieved on login. The idea is to keep the connection state if you want to connectWithId, but it is cleared for some reason (browser refresh for example).

(inner) motionDetection(videoConnection, options:)

Sends a ChangeStream command to the server. Changes the motion detection settings of the stream that the given videoConnection represents.
Parameters:
Name Type Description
videoConnection VideoConnection
options: Object contains any or all of the motion, sensitivity, grid and cpu parameters.

(inner) playbackGoTo(videoConnection, millisecondsSinceUnixEpoch, seekType:, successCallback:, failCallback:)

Sends a ChangeStream command to the server. Goes to the closest possible match of specific time.
Parameters:
Name Type Description
videoConnection VideoConnection
millisecondsSinceUnixEpoch Number
seekType: String optional, 'Time' (default), 'TimeOrBefore', 'TimeOrAfter'
successCallback: function function that is called when the command execution was successful and the result is passed as a parameter.
failCallback: function function that is called when the command execution has failed and the error is passed as a parameter.

(inner) playbackSeek(videoConnection, seekType:)

Sends a ChangeStream command to the server. Seeks to either of: 'DbStart', 'DbEnd', 'PrevSeq', 'NextSeq', 'PrevFrame' or 'NextFrame'.
Parameters:
Name Type Description
videoConnection VideoConnection
seekType: String 'DbStart', 'DbEnd', 'PrevSeq', 'NextSeq', 'PrevFrame' or 'NextFrame'

(inner) playbackSpeed(videoConnection, speed)

Sends a ChangeStream command to the server. Controls playback speed as a float. Negative number means backwards. 1.0 means normal speed.
Parameters:
Name Type Description
videoConnection VideoConnection
speed Number

(inner) ptzMove(videoConnection:, direction:)

Sends a ControlPTZ command to the server. Controls PTZMove. Directions are: 'Up', 'Down', 'Left', 'Right', 'UpLeft', 'UpRight', 'DownLeft', 'DownRight', 'ZoomIn', 'ZoomOut', 'Home'. The camera needs to support PTZ, otherwise nothing will happen.
Parameters:
Name Type Description
videoConnection: VideoConnection the current stream related to the PTZ this request will activate
direction: String 'Up', 'Down', 'Left', 'Right', 'UpLeft', 'UpRight', 'DownLeft', 'DownRight', 'ZoomIn', 'ZoomOut', 'Home'

(inner) ptzPreset(videoConnection:, presetName:)

Sends a ControlPTZ command to the server. Controls PTZ Preset. The parameter needs to be a valid preset name, otherwise nothing will happen.
Parameters:
Name Type Description
videoConnection: VideoConnection the current stream related to the preset this request will activate
presetName: String the name of the preset to be activated

(inner) removeObserver(object:)

Removes an existing observer from the Connection singleton.
Parameters:
Name Type Description
object: an arbitrary object implementing the ConnectionObserverInterface interface
See:
  • ConnectionObserverInterface

(inner) requestAudioStream(microphoneId:, successCallback:, failCallback:, options:)

Sends a RequestAudioStream command to the server.
Parameters:
Name Type Description
microphoneId: String the unique GUID of the microphone that should be started
successCallback: function function that is called when the command execution was successful and the result is passed as a parameter.
failCallback: function function that is called when the command execution has failed and the error is passed as a parameter.
options: int optional parameter containing various configuration, includes: - signal: live or playback - {int} compressionLevel - {boolean} reuseConnection - if true, the API will reuse existing connections for the same microphone
Returns:
the request object

(inner) requestAudioStreamIn(itemId, options, successCallback, errorCallback) → {ConnectionRequest}

Sends a RequestAudioStreamIn connection command to get an upstream for audio push to the server.
Parameters:
Name Type Description
itemId String Id of the item (speaker), which stream is requested (GUID)
options AudioConnectionOptions optional, optional configuration. May contain:
- {Number} AudioSamplingRate - The audio sampling rate in Hz value
- {Number} AudioBitsPerSample - 8/16  - Audio bits per sample
- {Number} AudioChannelsNumber - 1/2 - Number of audio channels (mon or stereo)
successCallback function function that is called when the command execution was successful and a stream parameters object is passed as a parameter.
errorCallback function function that is called when the command execution has failed and an error object is passed as a parameter.
Returns:
- the ConnectionRequest object
Type
ConnectionRequest

(inner) requestCode(successCallback:, failCallback:)

Sends a verification code request command after a log-in command, that requires a second step of verification.
Parameters:
Name Type Description
successCallback: function function that is called when the command execution was successful and the result is passed as a parameter.
failCallback: function function that is called when the command execution has failed and the error is passed as a parameter.

(inner) requestStream(cameraId:, size:, successCallback:, failCallback:, options:)

Sends a RequestStream command to the server.
Parameters:
Name Type Description
cameraId: String the unique GUID of the camera that should be started
size: includes width and height as mandatory properties
successCallback: function function that is called when the command execution was successful and the result is passed as a parameter.
failCallback: function function that is called when the command execution has failed and the error is passed as a parameter.
options: int optional parameter containing various configuration, includes: - signal: live or playback - {int} jpegCompressionLevel - {boolean} keyFramesOnly - {boolean} reuseConnection - if true, the API will reuse existing connections for the same camera - {int} time - timestamp for playback
Returns:
the request object

(inner) resumeCarousel(videoId:)

Pauses a carousel.
Parameters:
Name Type Description
videoId: String ID of the video

(inner) sendCommand(commandName:, requestParams:, options:, successCallback:, failCallback:)

Sends requests to the server. Creates ConnectionRequest instances.
Parameters:
Name Type Description
commandName: string, the name of the command
requestParams: json object, the parameters of the command
options: object, optional, can contain: - timeout: integer, time interval in milliseconds after which the request will be aborted - reuseConnection: boolean, flag to reuse connection or not - viewId: string, the unique GUID of the view that we will work on - cameraId: String, the unique GUID of the camera that should be started - successCallback: function, callback that is provided by the client code of the Network API which will be called during the execution of the callback parameter.
successCallback: function, the callback to be called after the response is returned and parsed
failCallback: function, callback that is provided by the client code of the Network API which will be called if something is wrong with the command.

(inner) startInvestigationExport(investigationId:, exportType:, includeAudio, password, successCallback:, failCallback:)

Starts an investigation export.
Parameters:
Name Type Description
investigationId: String the uniq id of the investigation.
exportType: String the type of the export: DB, AVI, MKV
includeAudio String YES/NO - flag whether to include audio in the investigation export
password String password used to encrypt exported video
successCallback: function function that is called when the command execution was successful and the result is passed as a parameter.
failCallback: function function that is called when the command execution has failed and the error is passed as a parameter.

(inner) swipe(params:)

It is used to change the camera orientation by moving it in the direction of the swipe. The swipe direction and length are calculated based on the start and end points of the gesture. The swipe speed is calculated based on the time it took to perform the gesture from the start point to the end point. The calculated direction defines the direction of the PTZ movement, whereas the length and the speed are used to determine the amount of the PTZ movement.
Parameters:
Name Type Description
params:
   - CameraId: String
   - GestureXPercent: the percentage of distance between start and finish [-100:100]
   - GestureYPercent: the percentage of distance between start and finish [-100:100]

(inner) tapAndHold(params:)

It is used to change the camera orientation by moving it in the direction of the tap. The reference point of the movement is the center of the screen. The tap and the reference points are used to calculate the direction and the speed of the camera movement.
Parameters:
Name Type Description
params: - CameraId: String - GestureXPercent: the percentage of distance between start and finish [-100:100] - GestureYPercent: the percentage of distance between start and finish [-100:100]

(inner) toggleAnalytics(enabled)

Toggles the Analytic Data setting
Parameters:
Name Type Description
enabled Boolean Enable or not analytics

(inner) toggleDirectStreaming(enabled)

Toggles the Direct streaming setting
Parameters:
Name Type Description
enabled Boolean Enable or not direct streaming

(inner) verifyCode(code)

Sends a code for verification after a it has been requested with requestCode command.
Parameters:
Name Type Description
code String second step authentication pin code

(inner) {triggerOutputOrEvent}(objectId:, triggerType:, successCallback:, failCallback:)

Triggers an output or event.
Parameters:
Name Type Description
objectId: String the objectId of the item
triggerType: String 'TriggerOutput' or 'TriggerEvent'
successCallback: function function that is called when the command execution was successful and the result is passed as a parameter.
failCallback: function function that is called when the command execution has failed and the error is passed as a parameter.