This example shows how to easily detect upload and download bandwidth with Red5 Pro prior to beginning a stream.
Checking the bandwidth (download and upload simultaneously) prior to beginning a stream is relatively simple, requiring only a few pieces of setup.
- One must instantiate an
R5BandwidthDetection
instance - One must then utilize the
checkSpeeds
method of that instance - Doing so requires passing in:
- The base url (usually the same as the
host
you would provide to yourR5Configuration
) - How long you wish the total bandwidth test to take, in seconds
- Callback blocks for the successful and unsuccessful attempts at checking the bandwidth
- The base url (usually the same as the
A simplified example of this would be:
let detection = R5BandwidthDetection()
detection.checkSpeeds("your-host", forSeconds: 2.5, withSuccess: { (response) in
let responseDict = response! as NSDictionary
let download = Int32(responseDict.object(forKey: "download") as! Int)
let upload = Int32(responseDict.object(forKey: "upload") as! Int)
print("Download speed is \(download)Kbps\nUpload speed is \(upload)Kbps\n")
}) { (error) in
print("There was an error checking your speeds! \(error?.localizedDescription ?? "Unknown error")")
}
The rest of this example is based on SubscribeTest.swift and ensures that a minimum bandwidth (as defined by the tests.plist
file) is met prior to subscribing to the stream.