DDPClient
public class DDPClient: NSObject
DDPClient is the base class for communicating with a server using the DDP protocol
-
Undocumented
Declaration
Swift
public class DDPClient: NSObject
-
Creates a random String id
Declaration
Swift
public func getId() -> String
-
Makes a DDP connection to the server
Declaration
Swift
public func connect(url:String, callback:((session:String)->())?)
Parameters
url
The String url to connect to, ex.
wss://todos.meteor.com/websocket
callback
A closure that takes a String argument with the value of the websocket session token
-
Sets the XCGLogger loglevel.
Declaration
Swift
public func setLogLevel(logLevel:XCGLogger.LogLevel)
Parameters
logLevel
An XCGLogger LogLevel enum value, ex. .Info, .Debug, .Error
-
Executes a method on the server. If a callback is passed, the callback is asynchronously executed when the method has completed. The callback takes two arguments: result and error. It the method call is successful, result contains the return value of the method, if any. If the method fails, error contains information about the error.
Declaration
Swift
public func method(name: String, params: AnyObject?, callback: DDPMethodCallback?) -> String
Parameters
name
The name of the method
params
An object containing method arguments, if any
callback
The closure to be executed when the method has been executed
-
Sends a subscription request to the server.
Declaration
Swift
public func sub(name: String, params: [AnyObject]?) -> String
Parameters
name
The name of the subscription
params
An object containing method arguments, if any
-
Sends a subscription request to the server. If a callback is passed, the callback asynchronously runs when the client receives a ‘ready’ message indicating that the initial subset of documents contained in the subscription has been sent by the server.
Declaration
Swift
public func sub(name:String, params: [AnyObject]?, callback: DDPCallback?) -> String
Parameters
name
The name of the subscription
params
An object containing method arguments, if any
callback
The closure to be executed when the server sends a ‘ready’ message
-
Sends an unsubscribe request to the server.
Declaration
Swift
public func unsub(name: String) -> String?
Parameters
name
The name of the subscription
-
Sends an unsubscribe request to the server. If a callback is passed, the callback asynchronously runs when the client receives a ‘ready’ message indicating that the subset of documents contained in the subscription have been removed.
Declaration
Swift
public func unsub(name: String, callback: DDPCallback?) -> String?
Parameters
name
The name of the subscription
callback
The closure to be executed when the server sends a ‘ready’ message
-
Executes when a subscription is ready.
Declaration
Swift
public func subscriptionIsReady(subscriptionId: String, subscriptionName:String) {}
Parameters
subscriptionId
A String representation of the hash of the subscription name
subscriptionName
The name of the subscription
-
Executes when a subscription is removed.
Declaration
Swift
public func subscriptionWasRemoved(subscriptionId:String, subscriptionName:String) {}
Parameters
subscriptionId
A String representation of the hash of the subscription name
subscriptionName
The name of the subscription
-
Executes when the server has sent a new document.
Declaration
Swift
public func documentWasAdded(collection:String, id:String, fields:NSDictionary?)
Parameters
collection
The name of the collection that the document belongs to
id
The document’s unique id
fields
The documents properties
-
Executes when the server sends a message to remove a document.
Declaration
Swift
public func documentWasRemoved(collection:String, id:String)
Parameters
collection
The name of the collection that the document belongs to
id
The document’s unique id
-
Executes when the server sends a message to update a document.
Declaration
Swift
public func documentWasChanged(collection:String, id:String, fields:NSDictionary?, cleared:[String]?)
Parameters
collection
The name of the collection that the document belongs to
id
The document’s unique id
fields
Optional object with EJSON values containing the fields to update
cleared
Optional array of strings (field names to delete)
-
Executes when the server sends a message indicating that the result of a method has changed.
Declaration
Swift
public func methodWasUpdated(methods:[String])
Parameters
methods
An array of strings (ids passed to ‘method’, all of whose writes have been reflected in data messages)
-
Executes when the client receives an error message from the server. Such a message is used to represent errors raised by the method or subscription, as well as an attempt to subscribe to an unknown subscription or call an unknown method.
Declaration
Swift
public func didReceiveErrorMessage(message: DDPError)
Parameters
message
A DDPError object with information about the error