kurento_rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.travis.yml +4 -0
  4. data/CODE_OF_CONDUCT.md +13 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +41 -0
  8. data/Rakefile +25 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +7 -0
  11. data/kurento_rails.gemspec +30 -0
  12. data/lib/generators/kurento_rails/install_generator.rb +45 -0
  13. data/lib/generators/kurento_rails/templates/config/events.rb +24 -0
  14. data/lib/generators/kurento_rails/templates/controllers/kurento_controller.rb +27 -0
  15. data/lib/generators/kurento_rails/templates/controllers/kurento_websockets_controller.rb +103 -0
  16. data/lib/generators/kurento_rails/templates/javascript/kurento-rails-js/adapterjs/publish/adapter.min.js +3 -0
  17. data/lib/generators/kurento_rails/templates/javascript/kurento-rails-js/kurento-client/js/kurento-client.map +1 -0
  18. data/lib/generators/kurento_rails/templates/javascript/kurento-rails-js/kurento-client/js/kurento-client.min.js +557 -0
  19. data/lib/generators/kurento_rails/templates/javascript/kurento-rails-js/kurento-rails.js +635 -0
  20. data/lib/generators/kurento_rails/templates/javascript/kurento-rails-js/kurento-utils/js/kurento-utils.map +1 -0
  21. data/lib/generators/kurento_rails/templates/javascript/kurento-rails-js/kurento-utils/js/kurento-utils.min.js +36 -0
  22. data/lib/generators/kurento_rails/templates/migrations/create_video_streams.rb +13 -0
  23. data/lib/generators/kurento_rails/templates/models/kurento_rails_video_stream.rb +2 -0
  24. data/lib/generators/kurento_rails/templates/views/kurento/broadcast.html.slim +2 -0
  25. data/lib/generators/kurento_rails/templates/views/kurento/index.html.slim +2 -0
  26. data/lib/generators/kurento_rails/templates/views/kurento/old_streams.html.slim +2 -0
  27. data/lib/kurento_rails.rb +5 -0
  28. data/lib/kurento_rails/version.rb +3 -0
  29. data/src/events.rb +24 -0
  30. data/src/kurento-rails.coffee +387 -0
  31. data/src/kurento_controller.rb +27 -0
  32. data/src/kurento_rails_video_stream.rb +2 -0
  33. data/src/kurento_websockets_controller.rb +103 -0
  34. metadata +161 -0
@@ -0,0 +1,635 @@
1
+ (function() {
2
+ var StreamingHelper, kurentoRailsHelpers,
3
+ hasProp = {}.hasOwnProperty;
4
+
5
+ kurentoRailsHelpers = {};
6
+
7
+ kurentoRailsHelpers.getRailsUrlFromBrowser = (function(_this) {
8
+ return function() {
9
+ return location.hostname + "/websocket";
10
+ };
11
+ })(this);
12
+
13
+ kurentoRailsHelpers.generateKurentoVideoUrl = (function(_this) {
14
+ return function(baseFileLocation, videoName) {
15
+ var date, dateString;
16
+ date = new Date();
17
+ dateString = (date.getMonth() + 1) + "-" + (date.getDate()) + "-" + (date.getFullYear()) + "_" + (date.getHours()) + ":" + (date.getMinutes()) + ":" + (date.getSeconds());
18
+ return baseFileLocation + "/" + (encodeURIComponent(videoName.toLowerCase().replace(/\s/g, '-'))) + "-" + dateString + ".webm";
19
+ };
20
+ })(this);
21
+
22
+ kurentoRailsHelpers.onIceCandidate = (function(_this) {
23
+ return function(webRtcEndpoint, webRtcPeer, onError) {
24
+ webRtcPeer.on('icecandidate', function(candidate) {
25
+ candidate = kurentoClient.register.complexTypes.IceCandidate(candidate);
26
+ return webRtcEndpoint.addIceCandidate(candidate, onError);
27
+ });
28
+ return webRtcEndpoint.on('OnIceCandidate', function(event) {
29
+ return webRtcPeer.addIceCandidate(event.candidate, onError);
30
+ });
31
+ };
32
+ })(this);
33
+
34
+ StreamingHelper = (function() {
35
+ function StreamingHelper(kurentoUrl, railsUrl) {
36
+ var onBroadcastingError, onBroadcastingOffer, onLiveViewError, onLiveViewOffer, onRecordedError, onRecordedOffer, timeoutFunction;
37
+ this.kurentoUrl = kurentoUrl;
38
+ this.railsUrl = railsUrl != null ? railsUrl : kurentoRailsHelpers.getRailsUrlFromBrowser();
39
+ this.kurento = kurentoClient(this.kurentoUrl);
40
+ this.rails_websocket_dispatcher = new WebSocketRails(this.railsUrl);
41
+ this.broadcast = {};
42
+ this.view = {};
43
+
44
+ /* BROADCASTING FUNCTIONS AND MEMBERS */
45
+ this.broadcast.kurentoObjects = {};
46
+ this.broadcast.kurentoObjects.pipeline = null;
47
+ this.broadcast.kurentoObjects.webRtcPeer = null;
48
+ this.broadcast.kurentoObjects.recorder = null;
49
+ this.broadcast.kurentoObjects.webRtcEndpoint = null;
50
+ this.broadcast.kurentoObjects.videoStreamId = null;
51
+ this.broadcast.kurentoObjects.currentCallback = null;
52
+ onBroadcastingError = (function(_this) {
53
+ return function(error) {
54
+ if (error) {
55
+ console.log("Broadcasting error:", error);
56
+ _this.broadcast.stopBroadcasting();
57
+ if (_this.broadcast.kurentoObjects.currentCallback) {
58
+ return _this.broadcast.kurentoObjects.currentCallback(error);
59
+ }
60
+ }
61
+ };
62
+ })(this);
63
+ onBroadcastingOffer = (function(_this) {
64
+ return function(error, offer) {
65
+ if (error) {
66
+ return onBroadcastingError(error);
67
+ }
68
+ return _this.kurento.create('MediaPipeline', function(error, pipeline) {
69
+ var file_url, mediaElements;
70
+ if (error || !_this.broadcast.kurentoObjects.webRtcPeer) {
71
+ return onBroadcastingError(error);
72
+ }
73
+ _this.broadcast.kurentoObjects.pipeline = pipeline;
74
+ file_url = kurentoRailsHelpers.generateKurentoVideoUrl(_this.broadcast.kurentoObjects.baseFileLocation, _this.broadcast.kurentoObjects.videoName);
75
+ mediaElements = [
76
+ {
77
+ type: 'WebRtcEndpoint',
78
+ params: {}
79
+ }, {
80
+ type: 'RecorderEndpoint',
81
+ params: {
82
+ uri: file_url
83
+ }
84
+ }
85
+ ];
86
+ return pipeline.create(mediaElements, function(error, elements) {
87
+ if (error || !_this.broadcast.kurentoObjects.pipeline) {
88
+ return onBroadcastingError(error);
89
+ }
90
+ _this.broadcast.kurentoObjects.webRtcEndpoint = elements[0], _this.broadcast.kurentoObjects.recorder = elements[1];
91
+ kurentoRailsHelpers.onIceCandidate(_this.broadcast.kurentoObjects.webRtcEndpoint, _this.broadcast.kurentoObjects.webRtcPeer, onBroadcastingError);
92
+ return _this.broadcast.kurentoObjects.webRtcEndpoint.processOffer(offer, function(error, answer) {
93
+ if (error || !_this.broadcast.kurentoObjects.pipeline) {
94
+ return onBroadcastingError(error);
95
+ }
96
+ _this.broadcast.kurentoObjects.webRtcEndpoint.gatherCandidates(onBroadcastingError);
97
+ _this.broadcast.kurentoObjects.webRtcPeer.processAnswer(answer, onBroadcastingError);
98
+ return _this.broadcast.kurentoObjects.webRtcEndpoint.connect(_this.broadcast.kurentoObjects.recorder, function(error) {
99
+ if (error || !_this.broadcast.kurentoObjects.pipeline) {
100
+ return onBroadcastingError(error);
101
+ }
102
+ return _this.broadcast.kurentoObjects.recorder.record(function(error) {
103
+ var save_to_rails_failure, save_to_rails_success, streamToBroadcast;
104
+ if (error || !_this.broadcast.kurentoObjects.pipeline) {
105
+ return onBroadcastingError(error);
106
+ }
107
+ save_to_rails_success = function(stream) {
108
+ _this.broadcast.kurentoObjects.videoStreamId = stream.id;
109
+ if (_this.broadcast.kurentoObjects.currentCallback) {
110
+ return _this.broadcast.kurentoObjects.currentCallback(null, stream);
111
+ }
112
+ };
113
+ save_to_rails_failure = function(stream) {
114
+ if (_this.broadcast.kurentoObjects.currentCallback) {
115
+ return _this.broadcast.kurentoObjects.currentCallback("Failed to save the data to rails", stream);
116
+ }
117
+ };
118
+ streamToBroadcast = {
119
+ name: _this.broadcast.kurentoObjects.videoName,
120
+ pipeline: _this.broadcast.kurentoObjects.pipeline.id,
121
+ file_url: file_url,
122
+ sender_rtc: _this.broadcast.kurentoObjects.webRtcEndpoint.id,
123
+ streaming: true
124
+ };
125
+ return _this.rails_websocket_dispatcher.trigger('streams.broadcast', streamToBroadcast, save_to_rails_success, save_to_rails_failure);
126
+ });
127
+ });
128
+ });
129
+ });
130
+ });
131
+ };
132
+ })(this);
133
+ this.broadcast.broadcast = (function(_this) {
134
+ return function(videoName, videoElement, baseFileLocation, callback) {
135
+ var options;
136
+ if (baseFileLocation == null) {
137
+ baseFileLocation = "file:///kurento";
138
+ }
139
+ if (callback == null) {
140
+ callback = null;
141
+ }
142
+ _this.broadcast.kurentoObjects.currentCallback = callback;
143
+ _this.broadcast.kurentoObjects.baseFileLocation = baseFileLocation;
144
+ _this.broadcast.kurentoObjects.videoName = videoName;
145
+ if (videoElement === null || $(videoElement).prop("tagName").toLowerCase().trim() === !"video") {
146
+ return onBroadcastingError("You must pass in a valid video tag");
147
+ }
148
+ videoElement = $(videoElement)[0];
149
+ options = {
150
+ localVideo: videoElement
151
+ };
152
+ return _this.broadcast.kurentoObjects.webRtcPeer = kurentoUtils.WebRtcPeer.WebRtcPeerSendonly(options, function(error) {
153
+ if (error) {
154
+ return onBroadcastingError(error);
155
+ }
156
+ return this.generateOffer(onBroadcastingOffer);
157
+ });
158
+ };
159
+ })(this);
160
+ this.broadcast.stopBroadcasting = (function(_this) {
161
+ return function(callback) {
162
+ var failed_to_notify_rails, successfully_notified_rails;
163
+ if (callback == null) {
164
+ callback = null;
165
+ }
166
+ successfully_notified_rails = function(stream) {
167
+ _this.broadcast.kurentoObjects.videoStreamId = null;
168
+ if (callback) {
169
+ return callback();
170
+ }
171
+ };
172
+ failed_to_notify_rails = function(stream) {
173
+ console.log("Unable to update video stream status in rails");
174
+ if (callback) {
175
+ return callback("Unable to update video stream status in rails");
176
+ }
177
+ };
178
+ if (_this.broadcast.kurentoObjects.recorder) {
179
+ _this.broadcast.kurentoObjects.recorder.stop();
180
+ _this.broadcast.kurentoObjects.recorder = null;
181
+ }
182
+ if (_this.broadcast.kurentoObjects.webRtcEndpoint) {
183
+ _this.broadcast.kurentoObjects.webRtcEndpoint.release();
184
+ _this.broadcast.kurentoObjects.webRtcEndpoint = null;
185
+ }
186
+ if (_this.broadcast.kurentoObjects.currentCallback) {
187
+ _this.broadcast.kurentoObjects.currentCallback = null;
188
+ }
189
+ if (_this.broadcast.kurentoObjects.webRtcPeer) {
190
+ _this.broadcast.kurentoObjects.webRtcPeer.dispose();
191
+ _this.broadcast.kurentoObjects.webRtcPeer = null;
192
+ }
193
+ if (_this.broadcast.kurentoObjects.pipeline) {
194
+ _this.broadcast.kurentoObjects.pipeline.release();
195
+ _this.broadcast.kurentoObjects.pipeline = null;
196
+ }
197
+ if (_this.broadcast.kurentoObjects.videoStreamId) {
198
+ return _this.rails_websocket_dispatcher.trigger('streams.stop_broadcasting', '', successfully_notified_rails, failed_to_notify_rails);
199
+ } else {
200
+ if (callback) {
201
+ return callback();
202
+ }
203
+ }
204
+ };
205
+ })(this);
206
+
207
+ /* END BROADCASTING FUNCTIONS AND MEMBERS */
208
+
209
+ /* VIEWING FUNCTIONS AND MEMBERS */
210
+ this.view.live = {};
211
+ this.view.recorded = {};
212
+ this.view.live.kurentoObjects = {};
213
+ this.view.recorded.kurentoObjects = {};
214
+ this.view.live.activeStreams = (function(_this) {
215
+ return function(callback, searchParams) {
216
+ var error, success;
217
+ if (callback == null) {
218
+ callback = null;
219
+ }
220
+ if (searchParams == null) {
221
+ searchParams = {};
222
+ }
223
+ success = function(streams) {
224
+ if (callback) {
225
+ return callback(null, streams);
226
+ }
227
+ };
228
+ error = function(streams) {
229
+ if (callback) {
230
+ return callback("There was an error getting the streams", streams);
231
+ }
232
+ };
233
+ return _this.rails_websocket_dispatcher.trigger('streams.active_streams', searchParams, success, error);
234
+ };
235
+ })(this);
236
+ this.view.live.subscribeToStreams = (function(_this) {
237
+ return function(newStreamHandler, streamDeactivatedHandler) {
238
+ return _this.view.live.createChannel('video_streams', {
239
+ 'new': newStreamHandler,
240
+ 'remove': streamDeactivatedHandler
241
+ });
242
+ };
243
+ })(this);
244
+ this.view.live.createChannel = (function(_this) {
245
+ return function(channelName, events) {
246
+ var channel, eventHandler, eventName, results;
247
+ channel = _this.rails_websocket_dispatcher.subscribe(channelName);
248
+ results = [];
249
+ for (eventName in events) {
250
+ if (!hasProp.call(events, eventName)) continue;
251
+ eventHandler = events[eventName];
252
+ results.push(channel.bind(eventName, eventHandler));
253
+ }
254
+ return results;
255
+ };
256
+ })(this);
257
+ this.view.live.triggerChannelEvent = (function(_this) {
258
+ return function(channelName, eventName, objectToSend) {
259
+ var channel;
260
+ channel = _this.rails_websocket_dispatcher.subscribe(channelName);
261
+ return channel.trigger(eventName, objectToSend);
262
+ };
263
+ })(this);
264
+ this.view.live.onEndOfStream = (function(_this) {
265
+ return function(stream, endOfStreamHandler) {
266
+ var channel;
267
+ channel = _this.rails_websocket_dispatcher.subscribe("stream-" + stream.id);
268
+ return channel.bind('end-of-stream', function(updated_stream) {
269
+ _this.view.live.stopViewing();
270
+ return endOfStreamHandler(updated_stream);
271
+ });
272
+ };
273
+ })(this);
274
+ onLiveViewError = (function(_this) {
275
+ return function(error) {
276
+ if (error) {
277
+ console.log("Error!", error);
278
+ }
279
+ _this.view.live.stopViewing();
280
+ if (_this.view.live.kurentoObjects.callback) {
281
+ return _this.view.live.kurentoObjects.callback(error);
282
+ }
283
+ };
284
+ })(this);
285
+ onLiveViewOffer = (function(_this) {
286
+ return function(error, offer) {
287
+ var pipeline, presenterEndpoint, ref;
288
+ if (error) {
289
+ return onLiveViewError(error);
290
+ }
291
+ if (_this.view.live.kurentoObjects.pipeline && _this.view.live.kurentoObjects.presenterWebRtcEndpoint) {
292
+ ref = [_this.view.live.kurentoObjects.pipeline, _this.view.live.kurentoObjects.presenterWebRtcEndpoint], pipeline = ref[0], presenterEndpoint = ref[1];
293
+ return pipeline.create('WebRtcEndpoint', function(error, endpoint) {
294
+ if (error || !_this.view.live.kurentoObjects.pipeline) {
295
+ return onLiveViewError(error);
296
+ }
297
+ _this.view.live.kurentoObjects.viewerWebRtcEndpoint = endpoint;
298
+ kurentoRailsHelpers.onIceCandidate(endpoint, _this.view.live.kurentoObjects.webRtcPeer, function() {});
299
+ endpoint.on('OnIceCandidate', function(event) {
300
+ var candidate;
301
+ return candidate = kurentoClient.register.complexTypes.IceCandidate(event.candidate);
302
+ });
303
+ return endpoint.processOffer(offer, function(error, answer) {
304
+ if (error || !_this.view.live.kurentoObjects.pipeline) {
305
+ return onLiveViewError(error);
306
+ }
307
+ _this.view.live.kurentoObjects.webRtcPeer.processAnswer(answer, function(error) {
308
+ if (error) {
309
+ return onLiveViewError(error);
310
+ }
311
+ });
312
+ endpoint.gatherCandidates(function(error) {
313
+ if (error) {
314
+ return onLiveViewError(error);
315
+ }
316
+ });
317
+ return _this.view.live.kurentoObjects.presenterWebRtcEndpoint.connect(endpoint, function(error) {
318
+ if (error || !_this.view.live.kurentoObjects.pipeline) {
319
+ return onLiveViewError(error);
320
+ }
321
+ if (_this.view.live.kurentoObjects.callback) {
322
+ return _this.view.live.kurentoObjects.callback(null, "Successfully started stream!");
323
+ }
324
+ });
325
+ });
326
+ });
327
+ }
328
+ };
329
+ })(this);
330
+ this.view.live.startViewing = (function(_this) {
331
+ return function(stream, videoElement, callback) {
332
+ if (callback == null) {
333
+ callback = null;
334
+ }
335
+ _this.view.live.kurentoObjects.callback = callback;
336
+ if (videoElement === null || $(videoElement).prop("tagName").toLowerCase().trim() === !"video") {
337
+ return onLiveViewError("You must pass in a valid video tag");
338
+ }
339
+ videoElement = $(videoElement)[0];
340
+ return _this.kurento.getMediaobjectById(stream.sender_rtc, function(error, webRtcEndpoint) {
341
+ if (error) {
342
+ return onLiveViewError(error);
343
+ }
344
+ _this.view.live.kurentoObjects.presenterWebRtcEndpoint = webRtcEndpoint;
345
+ return _this.kurento.getMediaobjectById(stream.pipeline, function(error, pipeline) {
346
+ var options;
347
+ if (error || !_this.view.live.kurentoObjects.presenterWebRtcEndpoint) {
348
+ return onLiveViewError(error);
349
+ }
350
+ _this.view.live.kurentoObjects.pipeline = pipeline;
351
+ options = {
352
+ remoteVideo: videoElement
353
+ };
354
+ return _this.view.live.kurentoObjects.webRtcPeer = kurentoUtils.WebRtcPeer.WebRtcPeerRecvonly(options, function(error) {
355
+ if (error) {
356
+ return onLiveViewError(error);
357
+ }
358
+ return this.generateOffer(onLiveViewOffer);
359
+ });
360
+ });
361
+ });
362
+ };
363
+ })(this);
364
+ this.view.live.stopViewing = (function(_this) {
365
+ return function(callback) {
366
+ if (callback == null) {
367
+ callback = null;
368
+ }
369
+ if (_this.view.live.kurentoObjects.callback) {
370
+ _this.view.live.kurentoObjects.callback = null;
371
+ }
372
+ if (_this.view.live.kurentoObjects.viewerWebRtcEndpoint) {
373
+ _this.view.live.kurentoObjects.viewerWebRtcEndpoint.release();
374
+ _this.view.live.kurentoObjects.viewerWebRtcEndpoint = null;
375
+ }
376
+ if (_this.view.live.kurentoObjects.webRtcPeer) {
377
+ _this.view.live.kurentoObjects.webRtcPeer.dispose();
378
+ _this.view.live.kurentoObjects.webRtcPeer = null;
379
+ }
380
+ if (_this.view.live.kurentoObjects.pipeline) {
381
+ _this.view.live.kurentoObjects.pipeline = null;
382
+ }
383
+ if (_this.view.live.kurentoObjects.presenterWebRtcEndpoint) {
384
+ _this.view.live.kurentoObjects.presenterWebRtcEndpoint = null;
385
+ }
386
+ if (callback) {
387
+ return callback();
388
+ }
389
+ };
390
+ })(this);
391
+ this.view.recorded.availableStreams = (function(_this) {
392
+ return function(callback, searchParams) {
393
+ var error, success;
394
+ if (callback == null) {
395
+ callback = null;
396
+ }
397
+ if (searchParams == null) {
398
+ searchParams = {};
399
+ }
400
+ success = function(streams) {
401
+ if (callback) {
402
+ return callback(null, streams);
403
+ }
404
+ };
405
+ error = function(streams) {
406
+ if (callback) {
407
+ return callback("There was an error getting the streams", streams);
408
+ }
409
+ };
410
+ return _this.rails_websocket_dispatcher.trigger('streams.recorded_streams', searchParams, success, error);
411
+ };
412
+ })(this);
413
+ onRecordedError = (function(_this) {
414
+ return function(error) {
415
+ if (error) {
416
+ console.log("Error: ", error);
417
+ }
418
+ _this.view.recorded.stopViewing();
419
+ if (_this.view.recorded.kurentoObjects.callback) {
420
+ return _this.view.recorded.kurentoObjects.callback(error);
421
+ }
422
+ };
423
+ })(this);
424
+ onRecordedOffer = (function(_this) {
425
+ return function(error, offer) {
426
+ console.log("In the offer function");
427
+ if (error) {
428
+ onRecordedError(error);
429
+ }
430
+ return _this.kurento.create('MediaPipeline', function(error, pipeline) {
431
+ if (error) {
432
+ return onRecordedError(error);
433
+ }
434
+ _this.view.recorded.kurentoObjects.pipeline = pipeline;
435
+ return pipeline.create('WebRtcEndpoint', function(error, endpoint) {
436
+ var options;
437
+ if (error || !_this.view.recorded.kurentoObjects.pipeline) {
438
+ return onRecordedError(error);
439
+ }
440
+ _this.view.recorded.kurentoObjects.webRtcEndpoint = endpoint;
441
+ kurentoRailsHelpers.onIceCandidate(endpoint, _this.view.recorded.kurentoObjects.webRtcPeer, function() {});
442
+ endpoint.processOffer(offer, function(error, answer) {
443
+ if (error || !_this.view.recorded.kurentoObjects.pipeline) {
444
+ return onRecordedError(error);
445
+ }
446
+ endpoint.gatherCandidates(function() {});
447
+ return _this.view.recorded.kurentoObjects.webRtcPeer.processAnswer(answer);
448
+ });
449
+ options = {
450
+ uri: _this.view.recorded.kurentoObjects.fileUrl
451
+ };
452
+ return pipeline.create('PlayerEndpoint', options, function(error, player) {
453
+ if (error || !_this.view.recorded.kurentoObjects.pipeline) {
454
+ return onRecordedError(error);
455
+ }
456
+ player.on('EndOfStream', function(event) {
457
+ var channel;
458
+ channel = _this.rails_websocket_dispatcher.subscribe("recorded-stream-" + _this.view.recorded.kurentoObjects.streamId);
459
+ channel.trigger('end-of-stream', _this.view.recorded.kurentoObjects.streamId);
460
+ return _this.view.recorded.stopViewing();
461
+ });
462
+ return player.connect(endpoint, function(error) {
463
+ if (error || !_this.view.recorded.kurentoObjects.pipeline) {
464
+ return onRecordedError(error);
465
+ }
466
+ return player.play(function(error) {
467
+ if (error || !_this.view.recorded.kurentoObjects.pipeline) {
468
+ return onRecordedError(error);
469
+ }
470
+ if (_this.view.recorded.kurentoObjects.callback) {
471
+ return _this.view.recorded.kurentoObjects.callback();
472
+ }
473
+ });
474
+ });
475
+ });
476
+ });
477
+ });
478
+ };
479
+ })(this);
480
+ this.view.recorded.startViewing = (function(_this) {
481
+ return function(stream, videoElement, callback) {
482
+ var options;
483
+ if (callback == null) {
484
+ callback = null;
485
+ }
486
+ console.log("Stream", stream);
487
+ _this.view.recorded.kurentoObjects.fileUrl = stream.file_url;
488
+ _this.view.recorded.kurentoObjects.streamId = stream.id;
489
+ _this.view.recorded.kurentoObjects.videoElement = videoElement;
490
+ _this.view.recorded.kurentoObjects.callback = callback;
491
+ if (videoElement === null || $(videoElement).prop("tagName").toLowerCase().trim() === !"video") {
492
+ return onRecordedError("You must pass in a valid video tag");
493
+ }
494
+ videoElement = $(videoElement)[0];
495
+ options = {
496
+ remoteVideo: videoElement
497
+ };
498
+ return _this.view.recorded.kurentoObjects.webRtcPeer = kurentoUtils.WebRtcPeer.WebRtcPeerRecvonly(options, function(error) {
499
+ if (error) {
500
+ return onRecordedError(error);
501
+ }
502
+ console.log("About to generate an offer.");
503
+ return this.generateOffer(onRecordedOffer);
504
+ });
505
+ };
506
+ })(this);
507
+ this.view.recorded.stopViewing = (function(_this) {
508
+ return function(callback) {
509
+ if (callback == null) {
510
+ callback = null;
511
+ }
512
+ if (_this.view.recorded.kurentoObjects.fileUrl) {
513
+ _this.view.recorded.kurentoObjects.fileUrl = null;
514
+ }
515
+ if (_this.view.recorded.kurentoObjects.streamId) {
516
+ _this.view.recorded.kurentoObjects.streamId = null;
517
+ }
518
+ if (_this.view.recorded.kurentoObjects.callback) {
519
+ _this.view.recorded.kurentoObjects.callback = null;
520
+ }
521
+ if (_this.view.recorded.kurentoObjects.player) {
522
+ _this.view.recorded.kurentoObjects.player = null;
523
+ }
524
+ if (_this.view.recorded.kurentoObjects.videoElement) {
525
+ $(_this.view.recorded.kurentoObjects.videoElement).attr('src', '');
526
+ _this.view.recorded.kurentoObjects.videoElement = null;
527
+ }
528
+ if (_this.view.recorded.kurentoObjects.webRtcEndpoint) {
529
+ _this.view.recorded.kurentoObjects.webRtcEndpoint.release();
530
+ _this.view.recorded.kurentoObjects.webRtcEndpoint = null;
531
+ }
532
+ if (_this.view.recorded.kurentoObjects.pipeline) {
533
+ _this.view.recorded.kurentoObjects.pipeline.release();
534
+ _this.view.recorded.kurentoObjects.pipeline = null;
535
+ }
536
+ if (callback) {
537
+ return callback();
538
+ }
539
+ };
540
+ })(this);
541
+ this.view.recorded.onEndOfStream = (function(_this) {
542
+ return function(stream, endOfStreamHandler) {
543
+ var channel;
544
+ channel = _this.rails_websocket_dispatcher.subscribe("recorded-stream-" + stream.id);
545
+ return channel.bind('end-of-stream', function(streamId) {
546
+ return endOfStreamHandler(streamId);
547
+ });
548
+ };
549
+ })(this);
550
+ this.view.startViewing = (function(_this) {
551
+ return function(stream, videoElement, callback) {
552
+ var live, recorded;
553
+ if (callback == null) {
554
+ callback = null;
555
+ }
556
+ live = function() {
557
+ return _this.view.live.startViewing(stream, videoElement, callback);
558
+ };
559
+ recorded = function() {
560
+ return _this.view.recorded.startViewing(stream, videoElement, callback);
561
+ };
562
+ return _this.rails_websocket_dispatcher.trigger('streams.view', '', live, recorded);
563
+ };
564
+ })(this);
565
+ this.view.stopViewing = (function(_this) {
566
+ return function(callback) {
567
+ if (callback == null) {
568
+ callback = null;
569
+ }
570
+ _this.view.live.stopViewing(callback);
571
+ return _this.view.recorded.stopViewing(callback);
572
+ };
573
+ })(this);
574
+ this.view.onEndOfStream = (function(_this) {
575
+ return function(stream, endOfStreamHandler) {
576
+ var live, recorded;
577
+ live = function() {
578
+ return _this.view.live.onEndOfStream(stream, endOfStreamHandler);
579
+ };
580
+ recorded = function() {
581
+ return _this.view.recorded.onEndOfStream(stream, endOfStreamHandler);
582
+ };
583
+ return _this.rails_websocket_dispatcher.trigger('streams.view', '', live, recorded);
584
+ };
585
+ })(this);
586
+ this.view.currentlyViewing = (function(_this) {
587
+ return function(stream) {
588
+ if (stream == null) {
589
+ stream = null;
590
+ }
591
+ if (stream) {
592
+ if (_this.view.live.kurentoObjects.pipeline && _this.view.live.kurentoObjects.presenterWebRtcEndpoint) {
593
+ return _this.view.live.kurentoObjects.pipeline.id === stream.pipeline && _this.view.live.kurentoObjects.presenterWebRtcEndpoint.id === stream.sender_rtc;
594
+ } else if (_this.view.recorded.kurentoObjects.pipeline) {
595
+ return _this.view.recorded.kurentoObjects.pipeline.id === stream.pipeline;
596
+ } else {
597
+ return false;
598
+ }
599
+ }
600
+ return _this.view.live.kurentoObjects.pipeline || _this.view.recorded.kurentoObjects.pipeline;
601
+ };
602
+ })(this);
603
+
604
+ /* END VIEWING FUNCTIONS AND MEMBERS */
605
+
606
+ /* AND FINALLY, A UNIVERSAL PAGE UNLOAD HANDLER */
607
+ timeoutFunction = (function(_this) {
608
+ return function() {
609
+ return window.addEventListener('unload', function() {
610
+ _this.broadcast.stopBroadcasting();
611
+ _this.view.stopViewing();
612
+ if (_this.kurento) {
613
+ _this.kurento.close();
614
+ }
615
+ if (_this.rails_websocket_dispatcher) {
616
+ return _this.rails_websocket_dispatcher.disconnect();
617
+ }
618
+ });
619
+ };
620
+ })(this);
621
+ setTimeout(timeoutFunction, 2000);
622
+ return this;
623
+ }
624
+
625
+ return StreamingHelper;
626
+
627
+ })();
628
+
629
+ window.createStreamingHelper = (function(_this) {
630
+ return function(kurento_url, rails_url) {
631
+ return new StreamingHelper(kurento_url, rails_url);
632
+ };
633
+ })(this);
634
+
635
+ }).call(this);