Usage
Initialization
The init method initializes the Bridgefy SDK with an API key. The delegate parameter is required and should be an object that conforms to the BridgefyDelegate
protocol. The verboseLogging parameter is optional and enables more detailed logging if set to true.
The following code shows how to start the SDK (using your API key) and how to assign the delegate.
The string apiKey represents a valid API key. An Internet connection is needed, at least for the first time to validate the license. The delegate is the class that will implement all the delegate methods from the BridgefySDK.
Start
After initializing the SDK, you should call the start()
function to have the SDK's services running.
The optional UUID userId is the id that the SDK will use to identify the user. If a nil value is passed, the SDK will randomly assign a UUID. The propagationProfile value is the profile the SDK will use to propagate messages through the mesh.
Once the service is started, the following delegate function is called:
The userId is the id used to identify the current user/device in the BridgefySDK.
In the case an error occurs while starting the BridgefySDK, the following delegate function is called:
Propagation Profiles
Hops limit: The maximum number of hops a message can get. Each time a message is forwarded, is considered a hop.
TTL: Time to live, is the maximum amount of time a message can be propagated since its creation.
Sharing time: The maximum amount of time a message will be kept for forwarding.
Maximum propagation: The maximum number of times a message will be forwarded from a device.
Tracklist limit: The maximum number of UUID's stored in an array to prevent sending the message to a peer which already forwarded the message.
Stop
To stop the SDK, use the following function:
After the service is stopped, the following delegate function is called:
Destroy Session
Call this method when you want to terminate the current Bridgefy session and destroy all related data:
After the session is destroy, the following delegate function is called:
Nearby peer detection
The following method is invoked when a peer has established a connection:
userId: Identifier of the user that has established a connection.
When a peer is disconnected(out of range), the following method will be invoked:
userId: Identifier of the disconnected user.
Sending data
The following method is used to send data using a transmission mode. This method returns a UUID to identify the message sent.
messageId: Unique identifier related to the message.
If the message was successfully sent, the following delegate method is called:
messageId: The unique identifier of the message sent.
Note: It Is important to notice that the call of this delegate method doesn't mean the message was delivered. This is due to the nature of how the messages travel through the mesh network created by the BridgefySDK. The ONLY scenario where you can assume that the message was delivered is when it was sent using the p2p
transmission mode; otherwise, it only means that there's no pre-validation error, and the SDK will start propagating the message.
If an error occurs while sending a message, the following delegate method is called:
Receiving Data
When a packet has been received, the following method will be invoked:
data: Received data.
messageId: The id of the message that was received
transmissionMode: The transmission mode used to propagate a message
Transmission Modes:
The mode used to propagate a message through nearby devices:
p2p(userId: UUID): Sends the message data only when the receiver is in range; otherwise an error is reported. mesh(userId: UUID)): Sends the message data using the mesh created by the SDK. It doesn’t need the receiver to be in range. broadcast(senderId: UUID): Sends a packet using mesh without a defined receiver. The packet is broadcast to all nearby users that are or aren’t in range.
Direct and mesh transmission
Direct transmission is a mechanism used to deliver packets to a user that is nearby or visible (a connection has been detected).
Mesh transmission is a mechanism used to deliver offline packets even when the receiving user isn’t nearby or visible. It can be achieved by taking advantage of other nearby peers; these receive the package, hold it, and forward it to other peers trying to find the receiver.
Last updated