Skip to content

Commit

Permalink
Merge pull request #66 from eventials/master
Browse files Browse the repository at this point in the history
AutoSwitchRules are now configurable
  • Loading branch information
Germano Fronza authored Sep 6, 2016
2 parents 1327d6e + c55c947 commit 2fe6f7e
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 13 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ var player = new Clappr.Player({
playbackType: 'live',
bufferTime: 1,
startLevel: 0,
switchRules: {
"SufficientBandwidthRule": {
"bandwidthSafetyMultiple": 1.15,
"minDroppedFps": 2
},
"InsufficientBufferRule": {
"minBufferLength": 2
},
"DroppedFramesRule": {
"downSwitchByOne": 10,
"downSwitchByTwo": 20,
"downSwitchToZero": 24
},
"InsufficientBandwidthRule": {
"bitrateMultiplier": 1.15
}
}
},
});
```
Expand All @@ -40,6 +57,7 @@ The plugin accepts several **optional** configuration options, such as:
- `autoSwitch` (default **false**) - Whether video should autoSwitch quality
- `useAppInstance` (default **false**) - Set it to `true` if your source url contains the app instance (not required if the app instance is `_definst_`).
- `proxyType` (default **none**) - Determines which fallback methods are tried if an initial connection attempt to Flash Media Server fails.
- `switchRules` (default **system defined**) - Rules defined to autoSwitch video quality based in some conditions.

## Building

Expand Down
Binary file modified dist/assets/RTMP.swf
Binary file not shown.
4 changes: 2 additions & 2 deletions dist/rtmp.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/rtmp.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/rtmp.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clappr-rtmp",
"version": "0.0.18",
"version": "0.0.19",
"description": "RTMP Support for Clappr Player",
"main": "dist/rtmp.js",
"author": "Flávio Ribeiro",
Expand Down
Binary file modified public/RTMP.swf
Binary file not shown.
4 changes: 2 additions & 2 deletions public/flash.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<param name="allowFullScreen" value="false">
<param name="wmode" value="<%= wmode %>">
<param name="tabindex" value="1">
<param name=FlashVars value="playbackId=<%= playbackId %>&scaling=<%= scaling %>&bufferTime=<%= bufferTime %>&playbackType=<%= playbackType %>&startLevel=<%= startLevel %>&useAppInstance=<%= useAppInstance %>&proxyType=<%= proxyType %>&autoSwitch=<%= autoSwitch %>"/>
<param name=FlashVars value="playbackId=<%= playbackId %>&scaling=<%= scaling %>&bufferTime=<%= bufferTime %>&playbackType=<%= playbackType %>&startLevel=<%= startLevel %>&useAppInstance=<%= useAppInstance %>&proxyType=<%= proxyType %>&autoSwitch=<%= autoSwitch %>&switchRules=<%= switchRules %>"/>
<embed
name="<%= cid %>"
type="application/x-shockwave-flash"
Expand All @@ -22,7 +22,7 @@
swliveconnect="true"
allowfullscreen="false"
bgcolor="#000000"
FlashVars="playbackId=<%= playbackId %>&scaling=<%= scaling %>&bufferTime=<%= bufferTime %>&playbackType=<%= playbackType %>&startLevel=<%= startLevel %>&useAppInstance=<%= useAppInstance %>&proxyType=<%= proxyType %>&autoSwitch=<%= autoSwitch %>"
FlashVars="playbackId=<%= playbackId %>&scaling=<%= scaling %>&bufferTime=<%= bufferTime %>&playbackType=<%= playbackType %>&startLevel=<%= startLevel %>&useAppInstance=<%= useAppInstance %>&proxyType=<%= proxyType %>&autoSwitch=<%= autoSwitch %>&switchRules=<%= switchRules %>"
src="<%= swfPath %>"
width="100%"
height="100%">
Expand Down
Binary file modified src/OSMF.swc
Binary file not shown.
15 changes: 10 additions & 5 deletions src/RTMP.as
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,17 @@ package {
private function playerPlay(url:String=null):void {
try {
if (!mediaElement) {
if (isLive) {
urlResource = new StreamingURLResource(url, StreamType.LIVE, NaN, NaN, null, useAppInstance, null, proxyType);
} else {
urlResource = new StreamingURLResource(url, StreamType.RECORDED, NaN, NaN, null, useAppInstance, null, proxyType);
}
var streamType:String = (isLive ? StreamType.LIVE : StreamType.RECORDED);

urlResource = new StreamingURLResource(url, streamType, NaN, NaN, null, useAppInstance, null, proxyType);

var startLevel:int = int(this.root.loaderInfo.parameters.startLevel);

if (this.root.loaderInfo.parameters.switchRules != "") {
var switchRules:Object = JSON.parse(this.root.loaderInfo.parameters.switchRules.replace(/&quote;/g, '"'));
urlResource.addMetadataValue(MetadataNamespaces.RESOURCE_INITIAL_SWITCH_RULES, switchRules);
}

if (startLevel > -1) {
urlResource.addMetadataValue(MetadataNamespaces.RESOURCE_INITIAL_INDEX, startLevel);
}
Expand Down Expand Up @@ -245,6 +248,8 @@ package {
mediaPlayer.play();
}
} catch (err:Error) {
debugLog('Catch error: ' + err.messsage);

playbackState = "ERROR";
_triggerEvent('statechanged');
}
Expand Down
Binary file modified src/SMILPlugin.swc
Binary file not shown.
11 changes: 11 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export default class RTMP extends Flash {
this.options.rtmpConfig.proxyType = this.options.rtmpConfig.proxyType || 'none'
this.options.rtmpConfig.startLevel = this.options.rtmpConfig.startLevel === undefined ? -1 : this.options.rtmpConfig.startLevel
this.options.rtmpConfig.autoSwitch = this.options.rtmpConfig.autoSwitch === undefined ? false : this.options.rtmpConfig.autoSwitch
this.options.rtmpConfig.switchRules = this.options.rtmpConfig.switchRules;

this.addListeners()
this._setupPlaybackType()
}
Expand Down Expand Up @@ -160,6 +162,14 @@ export default class RTMP extends Flash {
this.trigger(Events.PLAYBACK_SETTINGSUPDATE, this.name)
}

get _switchRulesJSON() {
if (this.options.rtmpConfig.switchRules !== undefined) {
return JSON.stringify(this.options.rtmpConfig.switchRules).replace(/"/g, '&quot;')
}

return "";
}

render() {
this.$el.html(this.template({
cid: this.cid,
Expand All @@ -171,6 +181,7 @@ export default class RTMP extends Flash {
playbackType: this.options.rtmpConfig.playbackType,
startLevel: this.options.rtmpConfig.startLevel,
autoSwitch: this.options.rtmpConfig.autoSwitch,
switchRules: this._switchRulesJSON,
useAppInstance: this.options.rtmpConfig.useAppInstance,
proxyType: this.options.rtmpConfig.proxyType
}))
Expand Down

0 comments on commit 2fe6f7e

Please sign in to comment.