| author | hamidouk |
| Wed, 04 Jan 2012 11:38:07 +0100 | |
| branch | popcorn-port |
| changeset 577 | 227d21a90fc5 |
| parent 558 | 29a370694c53 |
| child 582 | 1bca6b7f56e1 |
| permissions | -rw-r--r-- |
| 123 | 1 |
/* init.js - initialization and configuration of Popcorn and the widgets |
2 |
exemple json configuration: |
|
|
141
becd5f52fa24
this commit fixes an elusive integration bug where the object would get called
hamidouk
parents:
136
diff
changeset
|
3 |
|
| 123 | 4 |
*/ |
5 |
||
| 531 | 6 |
/** |
7 |
set up the IriSP.__dataloader instance - |
|
8 |
we need it because we have to get the metadata |
|
9 |
about the video before that the widget have even |
|
10 |
loaded. |
|
11 |
*/ |
|
|
453
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
12 |
IriSP.setupDataLoader = function() { |
|
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
13 |
/* we set it up separately because we need to |
|
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
14 |
get data at the very beginning, for instance when |
|
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
15 |
setting up the video */ |
|
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
16 |
IriSP.__dataloader = new IriSP.DataLoader(); |
|
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
17 |
}; |
|
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
18 |
|
| 531 | 19 |
/** do some magic to configure popcorn according to the options object passed. |
20 |
Works for html5, jwplayer and youtube videos |
|
21 |
*/ |
|
|
158
1813e6e4f0d6
made a small change to the way popcorn is integrated into the page.
hamidouk
parents:
141
diff
changeset
|
22 |
IriSP.configurePopcorn = function (layoutManager, options) { |
| 123 | 23 |
var pop; |
|
287
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
24 |
var ret = layoutManager.createDiv(); |
|
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
25 |
var containerDiv = ret[0]; |
| 123 | 26 |
|
| 127 | 27 |
switch(options.type) { |
| 123 | 28 |
/* |
29 |
todo : dynamically create the div/video tag which |
|
30 |
will contain the video. |
|
31 |
*/ |
|
32 |
case "html5": |
|
|
158
1813e6e4f0d6
made a small change to the way popcorn is integrated into the page.
hamidouk
parents:
141
diff
changeset
|
33 |
var tmpId = Popcorn.guid("video"); |
|
1813e6e4f0d6
made a small change to the way popcorn is integrated into the page.
hamidouk
parents:
141
diff
changeset
|
34 |
IriSP.jQuery("#" + containerDiv).append("<video src='" + options.file + "' id='" + tmpId + "'></video>"); |
|
402
6148fb647f46
html5 video can now set the height and width of the video.
hamidouk
parents:
315
diff
changeset
|
35 |
|
|
6148fb647f46
html5 video can now set the height and width of the video.
hamidouk
parents:
315
diff
changeset
|
36 |
if (options.hasOwnProperty("width")) |
|
6148fb647f46
html5 video can now set the height and width of the video.
hamidouk
parents:
315
diff
changeset
|
37 |
IriSP.jQuery("#" + containerDiv).css("width", options.width); |
|
6148fb647f46
html5 video can now set the height and width of the video.
hamidouk
parents:
315
diff
changeset
|
38 |
|
|
6148fb647f46
html5 video can now set the height and width of the video.
hamidouk
parents:
315
diff
changeset
|
39 |
if (options.hasOwnProperty("height")) |
|
6148fb647f46
html5 video can now set the height and width of the video.
hamidouk
parents:
315
diff
changeset
|
40 |
IriSP.jQuery("#" + containerDiv).css("height", options.height); |
|
6148fb647f46
html5 video can now set the height and width of the video.
hamidouk
parents:
315
diff
changeset
|
41 |
|
|
500
a784e70993b3
removed mediafragment references as they're implemented by the mediafragment
hamidouk
parents:
461
diff
changeset
|
42 |
pop = Popcorn("#" + tmpId); |
| 123 | 43 |
break; |
| 127 | 44 |
|
45 |
case "jwplayer": |
|
46 |
var opts = IriSP.jQuery.extend({}, options); |
|
47 |
delete opts.container; |
|
|
558
29a370694c53
delete type variable which seemed to sometimes (but not always) confuse the jwplayer,
hamidouk
parents:
557
diff
changeset
|
48 |
delete opts.type; |
|
453
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
49 |
|
|
456
7fcdb501effd
added a switch to choose different options if using rtmp or not.
hamidouk
parents:
453
diff
changeset
|
50 |
if (options.provider === "rtmp") { |
|
7fcdb501effd
added a switch to choose different options if using rtmp or not.
hamidouk
parents:
453
diff
changeset
|
51 |
/* exit if we can't access the metadata */ |
|
7fcdb501effd
added a switch to choose different options if using rtmp or not.
hamidouk
parents:
453
diff
changeset
|
52 |
if (typeof(IriSP.__jsonMetadata) === "undefined") { |
|
7fcdb501effd
added a switch to choose different options if using rtmp or not.
hamidouk
parents:
453
diff
changeset
|
53 |
break; |
|
7fcdb501effd
added a switch to choose different options if using rtmp or not.
hamidouk
parents:
453
diff
changeset
|
54 |
}; |
|
453
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
55 |
|
|
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
56 |
|
|
456
7fcdb501effd
added a switch to choose different options if using rtmp or not.
hamidouk
parents:
453
diff
changeset
|
57 |
// the json format is totally illogical |
|
7fcdb501effd
added a switch to choose different options if using rtmp or not.
hamidouk
parents:
453
diff
changeset
|
58 |
opts.streamer = IriSP.__jsonMetadata["medias"][0]["meta"]["item"]["value"]; |
|
7fcdb501effd
added a switch to choose different options if using rtmp or not.
hamidouk
parents:
453
diff
changeset
|
59 |
var source = IriSP.__jsonMetadata["medias"][0]["href"]; |
|
453
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
60 |
|
|
456
7fcdb501effd
added a switch to choose different options if using rtmp or not.
hamidouk
parents:
453
diff
changeset
|
61 |
// the source if a full url but jwplayer wants an url relative to the |
|
7fcdb501effd
added a switch to choose different options if using rtmp or not.
hamidouk
parents:
453
diff
changeset
|
62 |
// streamer url, so we've got to remove the common part. |
|
7fcdb501effd
added a switch to choose different options if using rtmp or not.
hamidouk
parents:
453
diff
changeset
|
63 |
opts.file = source.slice(opts.streamer.length); |
|
7fcdb501effd
added a switch to choose different options if using rtmp or not.
hamidouk
parents:
453
diff
changeset
|
64 |
} else { |
|
7fcdb501effd
added a switch to choose different options if using rtmp or not.
hamidouk
parents:
453
diff
changeset
|
65 |
/* other providers type, video for instance - |
|
7fcdb501effd
added a switch to choose different options if using rtmp or not.
hamidouk
parents:
453
diff
changeset
|
66 |
pass everything as is */ |
|
7fcdb501effd
added a switch to choose different options if using rtmp or not.
hamidouk
parents:
453
diff
changeset
|
67 |
} |
|
7fcdb501effd
added a switch to choose different options if using rtmp or not.
hamidouk
parents:
453
diff
changeset
|
68 |
|
|
557
e331072ce8fd
added more autoconfig, and an option to specify in site.js where to get the
hamidouk
parents:
539
diff
changeset
|
69 |
if (!options.hasOwnProperty("flashplayer")) { |
|
558
29a370694c53
delete type variable which seemed to sometimes (but not always) confuse the jwplayer,
hamidouk
parents:
557
diff
changeset
|
70 |
opts.flashplayer = IriSP.jwplayer_swf_path; |
|
557
e331072ce8fd
added more autoconfig, and an option to specify in site.js where to get the
hamidouk
parents:
539
diff
changeset
|
71 |
} |
|
e331072ce8fd
added more autoconfig, and an option to specify in site.js where to get the
hamidouk
parents:
539
diff
changeset
|
72 |
|
|
e331072ce8fd
added more autoconfig, and an option to specify in site.js where to get the
hamidouk
parents:
539
diff
changeset
|
73 |
if (!options.hasOwnProperty("controlbar.position")) { |
|
558
29a370694c53
delete type variable which seemed to sometimes (but not always) confuse the jwplayer,
hamidouk
parents:
557
diff
changeset
|
74 |
opts["controlbar.position"] = "none"; |
|
557
e331072ce8fd
added more autoconfig, and an option to specify in site.js where to get the
hamidouk
parents:
539
diff
changeset
|
75 |
} |
|
558
29a370694c53
delete type variable which seemed to sometimes (but not always) confuse the jwplayer,
hamidouk
parents:
557
diff
changeset
|
76 |
|
|
430
c0b529ae20d2
don't overwrite popcorn when using our jwplayer wrapper.
hamidouk
parents:
422
diff
changeset
|
77 |
pop = IriSP.PopcornReplacement.jwplayer("#" + containerDiv, opts); |
| 127 | 78 |
break; |
| 198 | 79 |
|
80 |
case "youtube": |
|
81 |
var opts = IriSP.jQuery.extend({}, options); |
|
82 |
delete opts.container; |
|
83 |
opts.controls = 0; |
|
84 |
opts.autostart = false; |
|
| 204 | 85 |
templ = "width: {{width}}px; height: {{height}}px;"; |
| 198 | 86 |
var str = Mustache.to_html(templ, {width: opts.width, height: opts.height}); |
87 |
// Popcorn.youtube wants us to specify the size of the player in the style attribute of its container div. |
|
88 |
IriSP.jQuery("#" + containerDiv).attr("style", str); |
|
89 |
|
|
|
500
a784e70993b3
removed mediafragment references as they're implemented by the mediafragment
hamidouk
parents:
461
diff
changeset
|
90 |
pop = Popcorn.youtube("#" + containerDiv, opts.video, opts); |
| 198 | 91 |
break; |
| 127 | 92 |
|
93 |
default: |
|
94 |
pop = undefined; |
|
| 123 | 95 |
}; |
96 |
|
|
| 127 | 97 |
return pop; |
| 123 | 98 |
}; |
99 |
||
| 531 | 100 |
/** Configure the gui and instantiate the widgets passed as parameters |
101 |
@param guiOptions the gui object as seen in the examples. |
|
102 |
*/ |
|
|
158
1813e6e4f0d6
made a small change to the way popcorn is integrated into the page.
hamidouk
parents:
141
diff
changeset
|
103 |
IriSP.configureWidgets = function (popcornInstance, layoutManager, guiOptions) { |
|
453
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
104 |
|
|
8568e47379a2
added autoconfiguration of the media source for rtmp streams.
hamidouk
parents:
430
diff
changeset
|
105 |
var serialFactory = new IriSP.SerializerFactory(IriSP.__dataloader); |
| 127 | 106 |
var params = {width: guiOptions.width, height: guiOptions.height}; |
|
158
1813e6e4f0d6
made a small change to the way popcorn is integrated into the page.
hamidouk
parents:
141
diff
changeset
|
107 |
|
| 127 | 108 |
var ret_widgets = []; |
|
141
becd5f52fa24
this commit fixes an elusive integration bug where the object would get called
hamidouk
parents:
136
diff
changeset
|
109 |
var index; |
| 127 | 110 |
|
|
141
becd5f52fa24
this commit fixes an elusive integration bug where the object would get called
hamidouk
parents:
136
diff
changeset
|
111 |
for (index = 0; index < guiOptions.widgets.length; index++) { |
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
112 |
var widgetConfig = guiOptions.widgets[index]; |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
113 |
var widget = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig); |
| 127 | 114 |
ret_widgets.push(widget); |
|
141
becd5f52fa24
this commit fixes an elusive integration bug where the object would get called
hamidouk
parents:
136
diff
changeset
|
115 |
|
| 127 | 116 |
}; |
|
141
becd5f52fa24
this commit fixes an elusive integration bug where the object would get called
hamidouk
parents:
136
diff
changeset
|
117 |
|
| 127 | 118 |
return ret_widgets; |
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
119 |
}; |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
120 |
|
| 531 | 121 |
/** configure modules. @see configureWidgets */ |
| 461 | 122 |
IriSP.configureModules = function (popcornInstance, modulesList) { |
123 |
|
|
124 |
var serialFactory = new IriSP.SerializerFactory(IriSP.__dataloader); |
|
125 |
var ret_modules = []; |
|
126 |
var index; |
|
127 |
|
|
128 |
for (index = 0; index < modulesList.length; index++) { |
|
129 |
var moduleConfig = modulesList[index]; |
|
130 |
|
|
131 |
var serializer = serialFactory.getSerializer(moduleConfig.metadata); |
|
132 |
var module = new IriSP[moduleConfig.type](popcornInstance, moduleConfig, serializer); |
|
133 |
ret_modules.push(module); |
|
134 |
}; |
|
135 |
||
136 |
return ret_modules; |
|
137 |
}; |
|
138 |
||
| 531 | 139 |
/** instantiate a widget - only called by configureWidgets, never by the user. Handles widget |
140 |
dependencies. |
|
141 |
@param popcornInstance popcorn instance the widget will user |
|
142 |
@param serialFactory serializer factory to instantiate the widget with |
|
143 |
@param layoutManager layout manager |
|
144 |
@param widgetConfig configuration options for the widget |
|
145 |
*/ |
|
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
146 |
IriSP.instantiateWidget = function(popcornInstance, serialFactory, layoutManager, widgetConfig) { |
|
287
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
147 |
/* create div returns us a container for the widget and a spacer */ |
|
315
4466bf448426
updated layout and init to give more meaningful names to the widgets divs.
hamidouk
parents:
287
diff
changeset
|
148 |
var ret = layoutManager.createDiv(widgetConfig.type); |
|
287
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
149 |
var container = ret[0]; |
|
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
150 |
var spacer = ret[1]; |
|
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
151 |
|
| 175 | 152 |
var arr = IriSP.jQuery.extend({}, widgetConfig); |
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
153 |
arr.container = container; |
|
287
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
154 |
arr.spacer = spacer; |
|
539
3ba5b82aebb6
added code to select widgets to the layoutmanager, similar to what jquery does.
hamidouk
parents:
531
diff
changeset
|
155 |
arr.layoutManager = layoutManager; |
| 175 | 156 |
|
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
157 |
var serializer = serialFactory.getSerializer(widgetConfig.metadata); |
| 175 | 158 |
|
159 |
if (typeof serializer == "undefined") |
|
160 |
debugger; |
|
161 |
|
|
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
162 |
// instantiate the object passed as a string |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
163 |
var widget = new IriSP[widgetConfig.type](popcornInstance, arr, serializer); |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
164 |
|
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
165 |
if (widgetConfig.hasOwnProperty("requires")) { |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
166 |
// also create the widgets this one depends on. |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
167 |
// the dependency widget is available in the parent widget context as |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
168 |
// this.WidgetName (for instance, this.TipWidget); |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
169 |
|
| 175 | 170 |
var i = 0; |
171 |
for(i = 0; i < widgetConfig.requires.length; i++) { |
|
172 |
var widgetName = widgetConfig.requires[i]["type"]; |
|
173 |
widget[widgetName] = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig.requires[i]); |
|
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
174 |
} |
| 175 | 175 |
} |
176 |
|
|
|
171
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
177 |
serializer.sync(IriSP.wrap(widget, function() { this.draw(); })); |
|
158f0193ec54
added support for dependency widgets (i.e : a widget can now depend on another,
hamidouk
parents:
158
diff
changeset
|
178 |
return widget; |
|
287
5c7495102bd7
added a spacer div to simplify some graphic animations.
hamidouk
parents:
216
diff
changeset
|
179 |
}; |