Skip to content

Commit

Permalink
Merge pull request #204 from red5pro/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
bustardcelly authored Mar 16, 2022
2 parents 9f614a7 + eb18976 commit 92ef495
Show file tree
Hide file tree
Showing 17 changed files with 613 additions and 627 deletions.
63 changes: 48 additions & 15 deletions R5ProTestbed.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

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
}
97 changes: 50 additions & 47 deletions R5ProTestbed/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions R5ProTestbed/R5Streaming.framework/Headers/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ extern "C" {
#define STRINGIFY_(s) #s
#define STRINGIFY(s) STRINGIFY_(s)

#define R5PRO_MAJOR_VERSION 9
#define R5PRO_MAJOR_VERSION 10
#define R5PRO_MINOR_VERSION 0
#define R5PRO_REVISION 0
#define R5PRO_BUILD 0
#define R5PRO_BUILD b826


#define R5PRO_VERSION STRINGIFY(R5PRO_MAJOR_VERSION.R5PRO_MINOR_VERSION.R5PRO_REVISION.R5PRO_BUILD)
Expand Down
Binary file modified R5ProTestbed/R5Streaming.framework/Info.plist
Binary file not shown.
Binary file modified R5ProTestbed/R5Streaming.framework/R5Streaming
Binary file not shown.
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)
}
})
}
}
69 changes: 69 additions & 0 deletions R5ProTestbed/Tests/ConferenceStreamManager/README.md
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`.

Loading

0 comments on commit 92ef495

Please sign in to comment.