-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #204 from red5pro/develop
Develop
- Loading branch information
Showing
17 changed files
with
613 additions
and
627 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
R5ProTestbed.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"object": { | ||
"pins": [ | ||
{ | ||
"package": "Starscream", | ||
"repositoryURL": "https://github.com/daltoniam/Starscream", | ||
"state": { | ||
"branch": null, | ||
"revision": "df8d82047f6654d8e4b655d1b1525c64e1059d21", | ||
"version": "4.0.4" | ||
} | ||
} | ||
] | ||
}, | ||
"version": 1 | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
85 changes: 85 additions & 0 deletions
85
R5ProTestbed/Tests/ConferenceStreamManager/ConferenceStreamManagerTest.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// | ||
// ConferenceStreamManagerTest.swift | ||
// R5ProTestbed | ||
// | ||
// Created by Andy Zupko on 5/4/20. | ||
// Copyright © 2020 Infrared5. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import R5Streaming | ||
|
||
@objc(ConferenceStreamManagerTest) | ||
class ConferenceStreamManagerTest: ConferenceTest { | ||
|
||
func delayRetryRequest (streamName: String, context: String, action: String, resolver: @escaping (_ ip: String) -> Void) { | ||
|
||
// 2 seconds | ||
DispatchQueue.main.asyncAfter(deadline: .now() + 2) { | ||
print("Retrying request for " + context + "/" + streamName) | ||
self.requestServer(streamName, context: context, action: action, resolve: resolver) | ||
} | ||
|
||
} | ||
|
||
func requestServer(_ streamName: String, context: String, action: String, resolve: @escaping (_ ip: String) -> Void) { | ||
|
||
print("Requesting for stream: " + streamName + " - and action= " + action) | ||
|
||
let port = (Testbed.getParameter(param: "server_port") as! String) | ||
let portURI = port == "80" || port == "443" ? "" : ":" + port | ||
let version = (Testbed.getParameter(param: "sm_version") as! String) | ||
let originURI = (Testbed.getParameter(param: "host") as! String) + portURI + "/streammanager/api/" + version + "/event/" + context + "/" + streamName + "?action=" + action | ||
|
||
let url = (portURI.isEmpty ? "https://" : "http://") + originURI | ||
|
||
NSURLConnection.sendAsynchronousRequest( | ||
NSURLRequest( url: NSURL(string: url)! as URL ) as URLRequest, | ||
queue: OperationQueue(), | ||
completionHandler:{ (response: URLResponse?, data: Data?, error: Error?) -> Void in | ||
|
||
if ((error) != nil) { | ||
print(error!) | ||
return | ||
} | ||
|
||
// The string above is in JSON format, we specifically need the serverAddress value | ||
var json: [String: AnyObject] | ||
do{ | ||
json = try JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions()) as! [String: AnyObject] | ||
} catch { | ||
print(error) | ||
return | ||
} | ||
|
||
if let ip = json["serverAddress"] as? String { | ||
resolve(ip) | ||
} | ||
else if let errorMessage = json["errorMessage"] as? String { | ||
print(AccessError.error(message: errorMessage)) | ||
self.delayRetryRequest(streamName: streamName, context: context, action: action, resolver: resolve) | ||
} | ||
|
||
}) | ||
} | ||
|
||
override func publish() { | ||
let context = (Testbed.getParameter(param: "context") as! String) + "/" + roomName! | ||
requestServer(pubName as! String, context: context, action: "broadcast", resolve: { (url) in | ||
DispatchQueue.main.async { | ||
self.config?.host = url | ||
super.publish() | ||
} | ||
}) | ||
} | ||
|
||
override func subscribe(toName : String) { | ||
let context = (Testbed.getParameter(param: "context") as! String) + "/" + roomName! | ||
requestServer(toName, context: context, action: "subscribe", resolve: { (url) in | ||
DispatchQueue.main.async { | ||
self.config?.host = url | ||
super.subscribe(toName: toName) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Conference Chat | ||
|
||
This example demonstrates multi-party communication using Red5 Pro. It should be used in conjunction with a conference WebSocket host such as [this example](https://github.com/red5pro/red5pro-conference-host). | ||
|
||
It is recommended to view this example as part of the `webrtcexamples` webapp shipped with the [Red5 Pro Server](https://account.red5pro.com/download). | ||
|
||
## Basic Publisher | ||
|
||
**Please refer to the [Basic Publisher Documentation](../Publish/README.md) to learn more about the basic setup of a publisher.** | ||
|
||
## Basic Subscriber | ||
|
||
**Please refer to the [Basic Subscriber Documentation](../Subscribe/README.md) to learn more about the basic setup of a subscriber.** | ||
|
||
## Example Code | ||
|
||
- **[ConferenceTest.swift](ConferenceTest.swift)** | ||
- **[ConferenceViewController.swift](ConferenceViewController.swift)** | ||
|
||
# Setup | ||
|
||
## WebSocket Conference Host | ||
|
||
The `WebSocket Conference Host` refers to the socket endpoint that manages the list of active streams and their scopes for a given conference session. | ||
|
||
We have provided a basic example at [https://github.com/red5pro/red5pro-conference-host](https://github.com/red5pro/red5pro-conference-host). | ||
|
||
The endpoint for the `WebSocket Conference Host` is defined in the **tests.plist** as the `conference_host` property. By default it is set to a local IP address and port on your network (e.g., `ws://10.0.0.75:8001`). Change this to either the local IP or the remote IP of the machine that you launch the `WebSocket Conference Host` on. | ||
|
||
> The reason it is defined as a local IP on your network and not `localhost` is because `localhost` would refer to the actual device that the testbed is launched on. We assume you would not also be running the `WebSocket Conference Host` NodeJS server on your iOS device :) | ||
Once a publish session has begun, a connection to the `WebSocket Conference Host` is established and messages with regards to active stream listing are handled: | ||
|
||
```swift | ||
@objc func connectSocket () { | ||
// Endpoint location of host. See: https://github.com/red5pro/red5pro-conference-host | ||
// Note: Even though you may launch the conference host server on localhost, you cannot | ||
// specify `localhost` in the URL. You need to define the private IP of your machine on the | ||
// same router that the tethered iOS device is on (e.g., 10.0.0.x). | ||
// This is because defining `localhost` as the endpoint here would indicate your iOS device. | ||
let host = Testbed.getParameter(param: "conference_host" as String)? | ||
.replacingOccurrences(of: "http:", with:"ws:") | ||
.replacingOccurrences(of: "https:", with: "wss:") | ||
let url = URL(string: "\(host!)?room=\(self.roomName!)&streamName=\(self.pubName!)") | ||
socket = WebSocketProvider(url: url!) | ||
socket?.delegate = self | ||
socket?.connect() | ||
} | ||
|
||
func webSocketDidConnect(_ webSocket: WebSocketProvider) {} | ||
func webSocketDidDisconnect(_ webSocket: WebSocketProvider) {} | ||
|
||
func webSocket(_ webSocket: WebSocketProvider, didReceiveMessage message: String) { | ||
// message = { room: str, streams: str[] } | ||
let json: AnyObject? = message.parseJSONString | ||
let jsonDict = json as? [String: Any] | ||
|
||
if jsonDict?["room"] as? String == self.roomName! { | ||
if let streams = jsonDict?["streams"] as? Array<String> { | ||
stringToQueue(incoming: streams.joined(separator: ",")) | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Starscream | ||
|
||
By default, the WebSocket implementation used is the [Starscream](https://github.com/daltoniam/Starscream) iOS library. It is installed via the `Swift Package Manager`. | ||
|
Oops, something went wrong.