This is a message.

Stream from multiple sources for better reliability

Having multiple sources provides reliability because the viewer is less likely to be affected if some of the sources are not available. We also gain performance because we can balance the load by distributing the viewers between several servers.

Search engine friendly content

Events related to the cluster appear here:

Here we have configured three HTTP streaming sources into a cluster. The URLs of the first two hosts are wrong on purpose to demonstrate failing hosts. The streaming will begin from the third host and you can see what is happening in the box below the player.

Features

  • Fallback to another host when the primary host is not available.
  • Load balancing by distributing requests evenly between configured hosts.
  • Supports HTTP, RTMP and pseudostreaming.
  • Host failures are remembered and new connection attempts are only attempted after a preconfigured timeout.

Example

The configuration for the above demo is shown below. It listens to the onConnect and onConnectFailed events to show info of the connection attempts.

// a global variable that references our info box
var info = document.getElementById("info");
 
flowplayer("player", "http://releases.flowplayer.org/swf/flowplayer-3.2.18.swf", {
log: { level: 'debug', filter: 'org.flowplayer.cluster.*' },
plugins: {
 
// cluster plugin configuration
cluster: {
 
url: "flowplayer.cluster-3.2.10.swf",
 
// our hosts on the cluster
hosts: [
// first two hosts will fail
'http://invalid.flowplayer.org/video',
'http://nonexistent.flowplayer.org/video',
 
// this one will answer (if the server is up)
'http://stream.flowplayer.org'
],
 
// callback method for connection attempt
onConnect: function(host, index) {
info.innerHTML += "attempting to connect: " + host + "<br />";
},
 
// callback method for connection failure
onConnectFailed: function(host, index) {
info.innerHTML += "connection failed to: " + host + "<br />";
}
}
 
},
 
// use our cluster plugin as a "URL resolver"
clip: {
urlResolvers: 'cluster',
 
onStart: function(clip) {
info.innerHTML += "clip started: " + clip.url;
}
}
});

JavaScript

Configuration

Here is a list of the configuration options:

property / datatypeDefaultDescription

hosts

null

The hosts that are part of the cluster. These should be base URLs for each host to be used together with the clip's URL. The complete URL will be formed by concatenating the host URL and the clip's URL.

connectTimeout

2000

Connection timeout for a single connection attempt, given in milliseconds. After this timeout has been reached, the connection attempt is considered a failure and the next host in the cluster is evaluated.

connectCount

3

Number of times to loop through all the hosts in the cluster before giving up.

failureExpiry

2000

The expiry time (in milliseconds) to wait before a failed server is attempted again. The failure timestamp is stored in the client browser and a new connection attempt is only attempted after this time has expired.

loadBalance

false

When this is set to true the plugin accesses the configured hosts randomly providing the ability to balance the streaming load more evenly between each host to improve overall performance. If any of the hosts does not work, then another host is chosen.

Load balancing

The plugin can be set to randomly pick hosts from the cluster. This allows for simple load balancing completely controlled on the client side. This is achieved with the loadBalance property. Click on the splash image to see an example. It will randomly pick a host from the two alternatives.

Clustering events appear here

We have two different video servers: p.demo.flowplayer.netdna-cdn.com is hosted by HDDN and stream.flowplayer.org by Amazon. These two are accessed randomly so that in the end both servers will be loaded evenly. The load balancing is enabled with the loadBalance property.

// a global variable that references our info box
var infoBox = document.getElementById("balanceInfo");
flowplayer("balancer", "http://releases.flowplayer.org/swf/flowplayer-3.2.18.swf", {
 
// configuration for the clustering plugin
plugins: {
cluster: {
url: "flowplayer.cluster-3.2.10.swf",
 
// two working hosts
hosts: [
'http://p.demo.flowplayer.netdna-cdn.com/vod/demo.flowplayer',
'http://stream.flowplayer.org'
],
 
// that are load balanced (accessed randomly)
loadBalance: true,
 

// callback method that updates our info box
onConnect: function(host, index) {
infoBox.innerHTML += "attempting to connect to: " + host + "<br />";
}
}
},
 
clip: {
 
// our clip uses clustering plugin
urlResolvers: 'cluster',
 
onStart: function(clip) {
infoBox.innerHTML += "started clip: " + clip.url;
}
}
 

});

JavaScript

It's also possible to work with a combination of client-side and server-side load balancing. The server-side load balancing is usually done using a load balancer running in front of the RTMP or HTTP streaming servers.

Clustering RTMP servers

A cluster of RTMP servers is configured like this:

flowplayer("player", "/path/to/flowplayer-3.2.18.swf", {
 
clip: {
// for FMS we don't use the file extension here
url: 'Extremists',
provider: 'rtmp',
 
// the clustering plugin is configured as a connectionProvider
// when used with RTMP
connectionProvider: 'clustering'
},
 
plugins: {
// we don't need the netConnectionUrl here because it is
// taken from the hosts array of the cluster
rtmp: {
url: "flowplayer.rtmp-3.2.13.swf"
},
clustering: {
url: "flowplayer.cluster-3.2.10.swf",
netConnectionUrl: 'rtmp://cyzy7r959.rtmphost.com/flowplayer',
 
// Our hosts array contains the netConnectionUrls to the servers
hosts: [
{host:'rtmp://cyzy7r959.badhost1.com/flowplayer'},
{host:'rtmp://cyzy7r959.badhost2.com/flowplayer'},
{host:'rtmp://cyzy7r959.rtmphost.com/flowplayer'}
]
}
}
});

JavaScript

JavaScript API

Methods

MethodReturnsDescription

setLoadBalancing(value)

Plugin

Enables/disables load balancing. When enabled, the plugin randomly picks hosts from the cluster. For example: setLoadBalancing(true)

Events

EventWhen does it fire?

onConnect()

Fires when the plugin starts a new connection attempt. The callback is fed with two arguments:

  • host - the URL from the hosts list where the connection is attempted from.
  • hostIndex - the index of the host in the hosts list.

onConnectFailed()

Fires when a connection attempt has failed. The callback is fed with two arguments:

  • host - the URL from the hosts list where the failure happened.
  • hostIndex - the index of the host in the hosts list.

onFailed()

Fires when all hosts in the cluster have failed. See also the connectCount option, that specifies how many times the hosts are evaluated before failing.

Download

flowplayer.cluster-3.2.10.swf

just the working flash file to get you going

flowplayer.cluster-3.2.10.zip

working flash file (swf) + README.txt and LICENSE.txt

flowplayer.cluster-3.2.10-src.zip

source code

Please right-click and choose "Save link as..." (or similar)

Note: For XSS security reasons Flash plugins must be located at and loaded from the same domain as the core player flowplayer-3.2.18.swf.

This is a Flash plugin, and its features are therefore not available on iOS. For iOS please consult the ipad plugin.

See the version history for this tool.

Found a bug?

If you encounter problems with this script, please turn to the Flowplayer Flash plugin forum with a link to a minimal sample page (no extra html, css, javascript) demonstrating the issue.