XPSDKConnection
@objc
open class XPSDKConnection : NSObject, XPSDKRequestDelegate
Main Connection. This class encapsulates:
- connection state management
- commands sending to the server
- keep alive messages (LiveMessage commands). * The class uses XPSDKRequest to send commands to server. Most commands methods (if not all), such as getViews and requestStream return a connectionRequest object to the callee. This object can be used to cancel the request if needed via the cancelRequest method.
-
The main connection
Declaration
Swift
open static var sharedConnection: XPSDKConnection
-
The connection’s list of delegates
Declaration
Swift
open let delegates: NSMutableSet
-
Server features
Declaration
Swift
open internal(set) var features: NSDictionary?
-
Connection url
Declaration
Swift
open var url: URL?
-
Connection url endpoint
Declaration
Swift
open var urlEntPoint: String
-
Flag that is set to YES when the connection is race connection
Declaration
Swift
open var isRaceConnection: Bool
-
Certificate cookie
Declaration
Swift
open var certificateCookie: Data?
-
flag - set to YES if authentication is complete
Declaration
Swift
open var authenticationComplete: Bool
-
Connection state
Declaration
Swift
open var state: XPSDKConnectionState
-
DHEncryption
Declaration
Swift
open var dhe: DHEncryption?
-
Connection id
Declaration
Swift
open var id: String?
-
Reachability
Declaration
Swift
open var reachability: Reachability?
-
Server info
Declaration
Swift
open var serverInfo: XPSDKServerInfo?
-
Old connection
Declaration
Swift
open var oldConnection: AnyObject?
-
Race connections
Declaration
Swift
open let raceConnections: NSMutableSet
-
Declaration
Swift
open var server: AnyObject?
-
Setups url string for connection to server
Declaration
Swift
public func setupWithURLString(_ urlString: String)
Parameters
urlString
the url (in string format) for connection to server
-
Setups connection with server info (containing data for server host, port, flag to indicate secure connection)
Declaration
Swift
public func setupWithServerInfo(_ serInfo: XPSDKServerInfo)
Parameters
serInfo
object of type XPSDKServerInfo, containing data for server host, port, flag to indicate secure connection
-
Setups credentials for server connection and flag to indicate whether credentials should be saved
Declaration
Swift
public func setupWithUsername(_ username: String, password: String, shouldSave: Bool)
Parameters
username
the username
password
the password
shouldSave
flag to indicate whether credentials should be saved
-
Adds race connection
Declaration
Swift
public func addRaceConnection(_ raceConnection: XPSDKConnection?)
Parameters
raceConnection
the race connection to be added
-
Adds request
Declaration
Swift
public func addRequest(_ request: XPSDKRequest?)
Parameters
request
the request to be added
-
Adds connection delegate
Declaration
Swift
public func addDelegate(_ delegate: XPMobileSDKConnectionDelegate?)
Parameters
delegate
the delegate to be added
-
Removes connection delegate
Declaration
Swift
public func removeDelegate(_ delegate: XPMobileSDKConnectionDelegate?)
Parameters
delegate
the delegate to be added
-
Declaration
Swift
public func explicitSetOfConnectionState(_ state: NSNumber)
-
Updates application’s network activity indicator, depending on whether there is an request in execution, or an open video connection
Declaration
Swift
public func updateNetworkIndicator()
-
Declaration
Swift
public static func resetSharedConnection()
-
Declaration
Swift
public func sendCommand( name:String, parameters:[String:String]?, successHandler:SuccessResponse?, failureHandler: FailureBlock? )
-
connect: Connect to server
More details about the Connect command could be found in the Mobile Server Protocol documentation.
Declaration
Swift
public func connect(successHandler: SuccessResponse?, failureHandler: FailureBlock?) -> XPSDKRequest
Parameters
successHandler
The success block which returns XPSDKResponse
failureHandler
The failure block which returns NSError
-
disconnect: Disconnects from server
Declaration
Swift
public func disconnect(withSuccessHandler successHandler: SuccessResponse?, failureHandler: FailureBlock?) -> XPSDKRequest
Parameters
successHandler
The success block which returns XPSDKResponse
failureHandler
The failure block which returns NSError
-
requestStream(forCameraID:size:method:signal:fps:compressionLevel:userInitiatedDownsampling:keyFramesOnly:resizeSupported:time:usesTranscoding:successHandler:failureHandler:)
Request stream method
More details about the RequestStream command could be found in the Mobile Server Protocol documentation.
Declaration
Swift
public func requestStream(forCameraID cameraID: XPSDKViewID, size: CGSize, method: XPSDKVideoConnectionMethod, signal: XPSDKVideoConnectionSignal, fps:Int, compressionLevel:Int, userInitiatedDownsampling:Bool, keyFramesOnly:Bool, resizeSupported: Bool, time: NSDate?, usesTranscoding: Bool, successHandler: @escaping (XPSDKResponse, XPSDKVideoConnection) -> Void, failureHandler: FailureBlock?)
Parameters
cameraID
the ID of camera for which the video stream is requested
size
The size of the video to be streamed
method
Type of the method for retrieving video data (Push or Pull)
signal
Type of the requested signal (live, playback or upload)
fps
Frame rate of the requested video (frames per second)
userInitiatedDownsampling
Flag to indicate whether user has initiated downsampling
successHandler
The success block which returns XPSDKResponse
failureHandler
The failure block which returns NSError
-
Cancel request stream method
Declaration
Swift
public func cancelRequestStream(request: XPSDKRequest)
Parameters
request
The request that will be cancelled
-
closeVideoConnection: Close video connection
More details about the CloseVideoConnection command could be found in the Mobile Server Protocol documentation.
Declaration
Swift
public func closeVideoConnection(videoConnection: XPSDKVideoConnection, successHandler: SuccessResponse?, failureHandler: FailureBlock?)
Parameters
videoConnection
The video connection that will be closed
successHandler
The success block which returns XPSDKResponse
failureHandler
The failure block which returns NSError
-
purgeVideoConnections: close and remove all video connections
Declaration
Swift
public func purgeVideoConnections()
-
Change stream with fps method
More details about the ChangeStream command could be found in the Mobile Server Protocol documentation.
Declaration
Swift
public func changeStream(forVideoID videoID: String, fps: Int, successHandler: SuccessResponse?, failureHandler: FailureBlock?)
Parameters
videoID
ID of the video connection (GUID)
fps
new value for frames per second
successHandler
The success block which returns XPSDKResponse
failureHandler
The failure block which returns NSError
-
Change stream with size and source rectangle method
More details about the ChangeStream command could be found in the Mobile Server Protocol documentation.
Declaration
Swift
public func changeStream(forVideoID videoID: String, size: CGSize, sourceRect: CGRect, successHandler: SuccessResponse?, failureHandler: FailureBlock?)
Parameters
videoID
ID of the video connection (GUID)
size
The new size of the video (Width and Height in pixels)
sourceRect
The coordinates of the cropping rectangle (Top, Left, Right, Bottom)
successHandler
The success block which returns XPSDKResponse
failureHandler
The failure block which returns NSError
-
Declaration
Swift
public func changeStream(forVideoID videoID: String, size: CGSize, successHandler: SuccessResponse?, failureHandler: FailureBlock?)
-
Declaration
Swift
public func changeStream(forVideoID videoID: String, sourceRect: CGRect, successHandler: SuccessResponse?, failureHandler: FailureBlock?)
-
Change stream with playback speed method
More details about the ChangeStream command could be found in the Mobile Server Protocol documentation.
Declaration
Swift
public func changeStream(forVideoID videoID: String, playSpeed: Float, successHandler: SuccessResponse?, failureHandler: FailureBlock?)
Parameters
videoID
ID of the video connection (GUID)
playSpeed
Speed of the playback (floating point). Sign determines the direction.
successHandler
The success block which returns XPSDKResponse
failureHandler
The failure block which returns NSError
-
Get previous sequence of playback video method
More details about the ChangeStream command could be found in the Mobile Server Protocol documentation.
Declaration
Swift
public func previousSequence(forVideoID videoID: String, successHandler: SuccessResponse?, failureHandler: FailureBlock?)
Parameters
videoID
ID of the video connection (GUID)
successHandler
The success block which returns XPSDKResponse
failureHandler
The failure block which returns NSError
-
Get next sequence of playback video method
More details about the ChangeStream command could be found in the Mobile Server Protocol documentation.
Declaration
Swift
public func nextSequence(forVideoID videoID: String, successHandler: SuccessResponse?, failureHandler: FailureBlock?)
Parameters
videoID
ID of the video connection (GUID)
successHandler
The success block which returns XPSDKResponse
failureHandler
The failure block which returns NSError
-
Get previous frame of playback video method
More details about the ChangeStream command could be found in the Mobile Server Protocol documentation.
Declaration
Swift
public func previousFrame(forVideoID videoID: String, successHandler: SuccessResponse?, failureHandler: FailureBlock?)
Parameters
videoID
ID of the video connection (GUID)
successHandler
The success block which returns XPSDKResponse
failureHandler
The failure block which returns NSError
-
Get next frame of playback video method
More details about the ChangeStream command could be found in the Mobile Server Protocol documentation.
Declaration
Swift
public func nextFrame(forVideoID videoID: String, successHandler: SuccessResponse?, failureHandler: FailureBlock?)
Parameters
videoID
ID of the video connection (GUID)
successHandler
The success block which returns XPSDKResponse
failureHandler
The failure block which returns NSError
-
Seek to timestamp in playback video method
More details about the ChangeStream command could be found in the Mobile Server Protocol documentation.
Declaration
Swift
public func seekToTimestamp(forVideoID videoID: String, timestamp: NSNumber, seekType: String, successHandler: SuccessResponse?, failureHandler: FailureBlock?)
Parameters
videoID
ID of the video connection (GUID)
timestamp
Timestamp
seekType
seek type
successHandler
The success block which returns XPSDKResponse
failureHandler
The failure block which returns NSError
-
Seek to time in playback video method
More details about the ChangeStream command could be found in the Mobile Server Protocol documentation.
Declaration
Swift
public func seekToTime(forVideoID videoID: String, time: NSDate, seekType: String, successHandler: SuccessResponse?, failureHandler: FailureBlock?)
Parameters
videoID
ID of the video connection (GUID)
time
time (NSDate)
seekType
seek type
successHandler
The success block which returns XPSDKResponse
failureHandler
The failure block which returns NSError
-
Move camera with ptzMotion method
More details about the ChangeStream command could be found in the Mobile Server Protocol documentation.
Declaration
Swift
public func moveCamera(forVideoID videoID: String, ptzMotion: XPSDKPTZMotion, successHandler: SuccessResponse?, failureHandler: FailureBlock?)
Parameters
videoID
ID of the video connection (GUID)
ptzMotion
PTZ Motion (Up, Down, Left, Right, ZoomIn, ZoomOut, Home
successHandler
The success block which returns XPSDKResponse
failureHandler
The failure block which returns NSError
-
Move camera with ptz preset method
More details about the ChangeStream command could be found in the Mobile Server Protocol documentation.
Declaration
Swift
public func moveCamera(forVideoID videoID: String, ptzPreset: XPSDKCameraPTZPreset, successHandler: SuccessResponse?, failureHandler: FailureBlock?)
Parameters
videoID
ID of the video connection (GUID)
ptzPreset
PTZ Preset
successHandler
The success block which returns XPSDKResponse
failureHandler
The failure block which returns NSError
-
Request to start live or payback audio session
Declaration
Swift
public func requestAudio(forMicrophoneId micId: String, audioEncoding: String, signalType: String, methodType: String, successHandler: SuccessResponse?, failureHandler: FailureBlock?)
Parameters
micId
Id of the microphone, which stream is requested (GUID)
audioEncoding
Shows the encoding of the output. Possible values: Pcm/Mp3.
signalType
Type of the requested signal. Possible values: Live/Playback
methodType
Type of the method for retrieving video data. Possible values: Push/Pull
successHandler
The success block which returns XPSDKResponse
failureHandler
The failure block which returns NSError
-
Request to close audio stream.
Declaration
Swift
public func closeAudioStream(forAudioId audioId: String, successHandler: SuccessResponse?, failureHandler: FailureBlock?)
Parameters
audioId
The audio stream that will be closed
successHandler
The success block which returns XPSDKResponse
failureHandler
The failure block which returns NSError
-
requestAudioStreamIn(forItemId:audioEncoding:samplingRate:bitsPerSample:numberOfChannels:successHandler:failureHandler:)
Request to start push audio session.
Declaration
Swift
public func requestAudioStreamIn(forItemId itemId: String, audioEncoding: String, samplingRate: String, bitsPerSample: String, numberOfChannels: String, successHandler: SuccessResponse?, failureHandler: FailureBlock?) -> XPSDKRequest
Parameters
itemId
Id of the item (speaker), which stream is requested (GUID)
audioEncoding
Shows the encoding of the output. Possible values: Pcm/Mp3.
samplingRate
The audio sampling rate in Hz value
bitsPerSample
Audio bits per sample. Possible values: 8/16.
numberOfChannels
Number of audio channels (mono or stereo). Possible Values: ½.
successHandler
The success block which returns XPSDKResponse
failureHandler
The failure block which returns NSError
-
login: Login method
Declaration
Swift
public func login(withSuccessHandler successHandler: SuccessResponse?, failureHandler: FailureBlock?) -> XPSDKRequest?
Parameters
successHandler
The success block which returns XPSDKResponse
failureHandler
The failure block which returns NSError