Skip to content

Commit

Permalink
Merge pull request #458 from red5pro/feature/mixer-general-testbeds
Browse files Browse the repository at this point in the history
Feature/mixer general testbeds
  • Loading branch information
ankita-red5 authored Jan 31, 2022
2 parents c9e0806 + 22708b6 commit 2eb0a77
Show file tree
Hide file tree
Showing 14 changed files with 271 additions and 215 deletions.
29 changes: 14 additions & 15 deletions src/page/sample-mixer-pages/2x2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
const requiresStreamManager = !sm ? false : !(sm && sm === 'false')
const ws = window.query('ws') || 'null'
const webSocketEndpointForLayouts = `wss://${ws}?testbed=grid&type=cef&id=${cefId}&event-id=${eventId}`
const red5ProHost = window.query('host') || configuration.host
const red5ProHost = window.query('host') || 'localhost'//configuration.host
const streamManagerHost = configuration.host

// Round Trip Authentication
const username = window.query('username') || 'default-username'
Expand Down Expand Up @@ -91,16 +92,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
};
}

var protocol = serverSettings.protocol;
function getSocketLocationFromProtocol() {
return !secureConnection
? { protocol: 'ws', port: serverSettings.wsport }
: { protocol: 'wss', port: serverSettings.wssport };
}

var defaultConfiguration = {
protocol: getSocketLocationFromProtocol().protocol,
port: getSocketLocationFromProtocol().port,
const defaultConfiguration = {
protocol: 'ws',
port: '5080',
streamMode: configuration.recordBroadcast ? 'record' : 'live'
}

Expand All @@ -112,12 +106,12 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// Red5 Pro configuration to subscribe
var baseConfig = Object.assign({}, config, {
host: red5ProHost,
protocol: secureConnection ? 'wss' : 'ws',
port: secureConnection ? '443' : 5080,
protocol: 'ws',
port: 5080,
streamName: configuration.stream1,
app: scope,
connectionParams: {
host: configuration.host,
host: red5ProHost,
app: scope,
username,
password,
Expand Down Expand Up @@ -173,6 +167,11 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
const startSubscribers = (streamList) => {
console.log('sub to ', streamList)
if (Object.keys(activeSubscribers).length >= rowCount * rowCount) {
console.warn('Page is already subscribing to the maximum number of streams. Ignore new subscribe request')
return
}

console.log(`[mixer]:: Starting new subscribers from list: ${JSON.toString(streamList, null, 2)}`)
const subscribers = streamList.map(name => {
let freeSlot = findNextAvailableSlot()
Expand All @@ -187,7 +186,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
sub.next = subscribers[index + 1]
}
if (index === 0) {
sub.start(baseConfig, requiresStreamManager)
sub.start(baseConfig, streamManagerHost)
}
})
}
Expand Down
78 changes: 38 additions & 40 deletions src/page/sample-mixer-pages/2x2/subscriber-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,28 +174,15 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/**
* Generates Red5 Pro URL to check for stream availability
*/
const getAvailableUrlBasedOnConfig = (config, sm = false) => {
console.log(config)
const {
host,
port,
app
} = config
const protocol = 'https'
if (sm) {
const getAvailableUrl = (streamManagerHost = null) => {
if (streamManagerHost != null) {
const protocol = 'https'
const host = streamManagerHost
const port = 443
return `${protocol}://${host}:${port}/streammanager/api/4.0/event/list`
}

return `http://127.0.0.1:5080/live/streams.jsp`

/*const loc = 'localhost' //window.location
const uri = new URL(loc)
if (loc.port === '5080') {
return `${loc.protocol}//${loc.hostname}:${loc.port}/${app}/streams.jsp`
}
else {
return `${loc.protocol}//${loc.hostname}/${app}/streams.jsp`
}*/
}

/**
Expand Down Expand Up @@ -342,7 +329,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
resolve() {
if (this.next) {
this.next.start(this.baseConfiguration, this.requiresStreamManager)
this.next.start(this.baseConfiguration, this.streamManagerHost)
}
this.next = undefined
}
Expand All @@ -356,7 +343,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
console.error(event)
}
if (this.next) {
this.next.start(this.baseConfiguration, this.requiresStreamManager)
this.next.start(this.baseConfiguration, this.streamManagerHost)
}
this.next = undefined
}
Expand All @@ -381,7 +368,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
} else if (event.type === 'Subscribe.Play.Unpublish') {
// this.unpublished = true
this.stop()
this.start(this.baseConfiguration, this.requiresStreamManager)
this.start(this.baseConfiguration, this.streamManagerHost)
} else if (event.type === 'Subscribe.Metadata') {
const {
streamingMode
Expand Down Expand Up @@ -471,15 +458,15 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* @param {Object} config
* The configuration object for initialization.
* @param {Boolean} requiresStreamManager
* Flag to intergate with Stream Manager for subscription.
* @param {String} streamManagerHost
* Hostname of Stream Manager if used.
*/
async start(config, requiresStreamManager) {
async start(config, streamManagerHost = null) {
this.streamManagerHost = streamManagerHost
this.cancelled = false
this.unpublished = false
this.baseConfiguration = JSON.parse(JSON.stringify(config))
this.baseConfiguration.app = this.baseConfiguration.app + this.roomName
this.requiresStreamManager = requiresStreamManager

// generate unique id for each time in case reconnect.
const uid = Math.floor(Math.random() * 0x10000).toString(16)
Expand All @@ -498,19 +485,35 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
rtcConfig.mediaElementId = this.parent.id
}

let availableUrl = getAvailableUrlBasedOnConfig(rtcConfig, this.requiresStreamManager)
this.subscriber = new red5prosdk.RTCSubscriber()
this.subscriber.on('*', this.onSubscriberEvent)

this.displayInfo(`Requesting ${this.streamName}...`)
try {
if (requiresStreamManager) {
const subscriberSM = await window.streamManagerUtil.getEdge(config.host, this.baseConfiguration.app, this.streamName)
let availableUrlLocal = getAvailableUrl()
const availableLocal = await getIsAvailable(availableUrlLocal, this.streamName, false)
if (!availableLocal) {
console.log('Stream not available locally, searching on Stream Manager')
let availableUrlSM = getAvailableUrl(this.streamManagerHost)
const availableSM = await getIsAvailable(availableUrlSM, this.streamName, true)
if (!availableSM) {
throw new Error(`${this.streamName} Not Available`)
}
this.requiresStreamManager = true
}

if (this.requiresStreamManager) {
rtcConfig.app = 'streammanager'
rtcConfig.protocol = 'wss'
rtcConfig.port = '443'
rtcConfig.host = this.streamManagerHost

const subscriberSM = await window.streamManagerUtil.getEdge(rtcConfig.host, this.baseConfiguration.app, this.streamName)
const {
serverAddress,
scope
} = subscriberSM
rtcConfig.app = 'streammanager'

rtcConfig.connectionParams = {
...config.connectionParams, ...{
host: serverAddress,
Expand All @@ -519,11 +522,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
}
}

const available = await getIsAvailable(availableUrl, this.streamName, this.requiresStreamManager)
if (!available) {
throw new Error(`${this.streamName} Not Available`)
}

await this.subscriber.init(rtcConfig)
await this.subscriber.subscribe()
if (this.forceMute) {
Expand All @@ -534,7 +532,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
console.error(e)
this.reject()
this.displayError(typeof e === 'string' ? e : e.message)
this.retryConnection(config, requiresStreamManager)
this.retryConnection(config, this.streamManagerHost)
}
}

Expand All @@ -543,10 +541,10 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* @param {Object} config
* The configuration to use in initialization of subscriber.
* @param {Boolean} requiresStreamManager
* Flag to use Stream Manager integration.
* @param {String} streamManagerHost
* Hostname of the Stream Manager.
*/
async retryConnection(config, requiresStreamManager) {
async retryConnection(config, streamManagerHost = null) {

try {
clearTimeout(this.retryConnectTimeout)
Expand All @@ -559,12 +557,12 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
this.retryConnectTimeout = setTimeout(() => {
this.displayInfo(`Retrying Connection for ${this.streamName}...`)
clearTimeout(this.retryConnectTimeout)
this.start(config, requiresStreamManager)
this.start(config, streamManagerHost)
}, RETRY_DELAY)
} catch (e) {
console.error(e)
this.displayError(typeof e === 'string' ? e : e.message)
this.retryConnection(config, requiresStreamManager)
this.retryConnection(config, streamManagerHost)
}
}

Expand Down
30 changes: 14 additions & 16 deletions src/page/sample-mixer-pages/3x3/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
const requiresStreamManager = !sm ? false : !(sm && sm === 'false')
const ws = window.query('ws') || 'null'
const webSocketEndpointForLayouts = `wss://${ws}?testbed=grid&type=cef&id=${cefId}&event-id=${eventId}`

const red5ProHost = window.query('host') || configuration.host
const red5ProHost = window.query('host') || 'localhost'//configuration.host
const streamManagerHost = configuration.host

// Round Trip Authentication
const username = window.query('username') || 'default-username'
Expand Down Expand Up @@ -90,16 +90,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
};
}

var protocol = serverSettings.protocol;
function getSocketLocationFromProtocol() {
return !secureConnection
? { protocol: 'ws', port: serverSettings.wsport }
: { protocol: 'wss', port: serverSettings.wssport };
}

var defaultConfiguration = {
protocol: getSocketLocationFromProtocol().protocol,
port: getSocketLocationFromProtocol().port,
const defaultConfiguration = {
protocol: 'ws',
port: '5080',
streamMode: configuration.recordBroadcast ? 'record' : 'live'
}

Expand All @@ -109,12 +102,13 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
getUserMediaConfiguration())

var baseConfig = Object.assign({}, config, {
protocol: getSocketLocationFromProtocol().protocol,
port: getSocketLocationFromProtocol().port,
host: red5ProHost,
protocol: 'ws',
port: 5080,
streamName: configuration.stream1,
app: scope,
connectionParams: {
host: configuration.host,
host: red5ProHost,
app: scope,
username,
password,
Expand Down Expand Up @@ -168,6 +162,10 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
const startSubscribers = (streamList) => {
console.log('sub to ', streamList)
if (Object.keys(activeSubscribers).length >= rowCount * rowCount) {
console.warn('Page is already subscribing to the maximum number of streams. Ignore new subscribe request')
return
}
console.log(`[mixer]:: Starting new subscribers from list: ${JSON.toString(streamList, null, 2)}`)
const subscribers = streamList.map(name => {
let freeSlot = findNextAvailableSlot()
Expand All @@ -182,7 +180,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
sub.next = subscribers[index + 1]
}
if (index === 0) {
sub.start(baseConfig, requiresStreamManager)
sub.start(baseConfig, streamManagerHost)
}
})
}
Expand Down
Loading

0 comments on commit 2eb0a77

Please sign in to comment.