OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 var mediaRouter; | 5 var mediaRouter; |
6 | 6 |
7 define('media_router_bindings', [ | 7 define('media_router_bindings', [ |
8 'mojo/public/js/bindings', | 8 'mojo/public/js/bindings', |
9 'mojo/public/js/core', | 9 'mojo/public/js/core', |
10 'content/public/renderer/frame_service_registry', | 10 'content/public/renderer/frame_service_registry', |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
405 * @param {string} reason | 405 * @param {string} reason |
406 * @param {string} message | 406 * @param {string} message |
407 */ | 407 */ |
408 MediaRouter.prototype.onPresentationConnectionClosed = | 408 MediaRouter.prototype.onPresentationConnectionClosed = |
409 function(routeId, reason, message) { | 409 function(routeId, reason, message) { |
410 this.service_.onPresentationConnectionClosed( | 410 this.service_.onPresentationConnectionClosed( |
411 routeId, presentationConnectionCloseReasonToMojo_(reason), message); | 411 routeId, presentationConnectionCloseReasonToMojo_(reason), message); |
412 }; | 412 }; |
413 | 413 |
414 /** | 414 /** |
415 * @param {string} routeId | |
416 * @param {!Array<!RouteMessage>} mesages | |
417 */ | |
418 MediaRouter.prototype.onRouteMessagesReceived = function(routeId, messages) { | |
419 this.service_.onRouteMessagesReceived( | |
420 routeId, messages.map(messageToMojo_)); | |
421 }; | |
422 | |
423 /** | |
415 * Object containing callbacks set by the provider manager. | 424 * Object containing callbacks set by the provider manager. |
416 * | 425 * |
417 * @constructor | 426 * @constructor |
418 * @struct | 427 * @struct |
419 */ | 428 */ |
420 function MediaRouterHandlers() { | 429 function MediaRouterHandlers() { |
421 /** | 430 /** |
422 * @type {function(!string, !string, !string, !string, !number)} | 431 * @type {function(!string, !string, !string, !string, !number)} |
423 */ | 432 */ |
424 this.createRoute = null; | 433 this.createRoute = null; |
(...skipping 22 matching lines...) Expand all Loading... | |
447 * @type {function(string, string): Promise} | 456 * @type {function(string, string): Promise} |
448 */ | 457 */ |
449 this.sendRouteMessage = null; | 458 this.sendRouteMessage = null; |
450 | 459 |
451 /** | 460 /** |
452 * @type {function(string, Uint8Array): Promise} | 461 * @type {function(string, Uint8Array): Promise} |
453 */ | 462 */ |
454 this.sendRouteBinaryMessage = null; | 463 this.sendRouteBinaryMessage = null; |
455 | 464 |
456 /** | 465 /** |
466 * TODO(imcheng): Remove in M55. | |
apacible
2016/07/07 15:57:44
I'm likely missing context here -- what's special
imcheng
2016/07/07 18:00:58
My intention is for this patch to make it to M53.
| |
457 * @type {function(string): | 467 * @type {function(string): |
458 * Promise.<{messages: Array.<RouteMessage>, error: boolean}>} | 468 * Promise.<{messages: Array.<RouteMessage>, error: boolean}>} |
459 */ | 469 */ |
460 this.listenForRouteMessages = null; | 470 this.listenForRouteMessages = null; |
461 | 471 |
462 /** | 472 /** |
463 * @type {function(string)} | 473 * @type {function(string)} |
464 */ | 474 */ |
475 this.startlisteningForRouteMessages = null; | |
476 | |
477 /** | |
478 * @type {function(string)} | |
479 */ | |
465 this.stopListeningForRouteMessages = null; | 480 this.stopListeningForRouteMessages = null; |
466 | 481 |
467 /** | 482 /** |
468 * @type {function(string)} | 483 * @type {function(string)} |
469 */ | 484 */ |
470 this.detachRoute = null; | 485 this.detachRoute = null; |
471 | 486 |
472 /** | 487 /** |
473 * @type {function()} | 488 * @type {function()} |
474 */ | 489 */ |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
530 * | 545 * |
531 * @param {!MediaRouterHandlers} handlers | 546 * @param {!MediaRouterHandlers} handlers |
532 */ | 547 */ |
533 MediaRouteProvider.prototype.setHandlers = function(handlers) { | 548 MediaRouteProvider.prototype.setHandlers = function(handlers) { |
534 this.handlers_ = handlers; | 549 this.handlers_ = handlers; |
535 var requiredHandlers = [ | 550 var requiredHandlers = [ |
536 'stopObservingMediaRoutes', | 551 'stopObservingMediaRoutes', |
537 'startObservingMediaRoutes', | 552 'startObservingMediaRoutes', |
538 'sendRouteMessage', | 553 'sendRouteMessage', |
539 'sendRouteBinaryMessage', | 554 'sendRouteBinaryMessage', |
540 'listenForRouteMessages', | 555 'startListeningForRouteMessages', |
541 'stopListeningForRouteMessages', | 556 'stopListeningForRouteMessages', |
542 'detachRoute', | 557 'detachRoute', |
543 'terminateRoute', | 558 'terminateRoute', |
544 'joinRoute', | 559 'joinRoute', |
545 'createRoute', | 560 'createRoute', |
546 'stopObservingMediaSinks', | 561 'stopObservingMediaSinks', |
547 'startObservingMediaRoutes', | 562 'startObservingMediaRoutes', |
548 'connectRouteByRouteId', | 563 'connectRouteByRouteId', |
549 'enableMdnsDiscovery', | 564 'enableMdnsDiscovery', |
550 'updateMediaSinks', | 565 'updateMediaSinks', |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
708 routeId, data) { | 723 routeId, data) { |
709 return this.handlers_.sendRouteBinaryMessage(routeId, data) | 724 return this.handlers_.sendRouteBinaryMessage(routeId, data) |
710 .then(function() { | 725 .then(function() { |
711 return {'sent': true}; | 726 return {'sent': true}; |
712 }, function() { | 727 }, function() { |
713 return {'sent': false}; | 728 return {'sent': false}; |
714 }); | 729 }); |
715 }; | 730 }; |
716 | 731 |
717 /** | 732 /** |
718 * Listen for next batch of messages from one of the routeIds. | 733 * Listen for messages from a route. |
719 * @param {!string} routeId | 734 * @param {!string} routeId |
720 * @return {!Promise.<{messages: Array.<RouteMessage>, error: boolean}>} | |
721 * Resolved with a list of messages, and a boolean indicating if an error | |
722 * occurred. | |
723 */ | 735 */ |
724 MediaRouteProvider.prototype.listenForRouteMessages = function(routeId) { | 736 MediaRouteProvider.prototype.startListeningForRouteMessages = function( |
725 return this.handlers_.listenForRouteMessages(routeId) | 737 routeId) { |
738 if (this.handlers_.startListeningForRouteMessages) { | |
739 this.handlers_.startListeningForRouteMessages(routeId); | |
740 } else { | |
741 // Old API. | |
742 this.listenForRouteMessagesOld(routeId); | |
743 } | |
744 }; | |
745 | |
746 | |
747 /** | |
748 * A hack to adapt new MR messaging API to old extension messaging API. | |
749 * TODO(imcheng): Remove in M55. | |
750 * @param {!string} routeId | |
751 */ | |
752 MediaRouteProvider.prototype.listenForRouteMessagesOld = function(routeId) { | |
753 this.handlers_.listenForRouteMessages(routeId) | |
726 .then(function(messages) { | 754 .then(function(messages) { |
727 return {'messages': messages.map(messageToMojo_), 'error': false}; | 755 // If messages is empty, then stopListeningForRouteMessages has been |
728 }, function() { | 756 // called. We don't need to send it back to MR. |
729 return {'messages': [], 'error': true}; | 757 if (messages.length > 0) { |
730 }); | 758 // Send the messages back to MR, and listen for next batch of |
759 // messages. | |
760 this.mediaRouter_.onRouteMessagesReceived(routeId, messages); | |
761 this.listenForRouteMessagesOld(routeId); | |
762 } | |
763 }.bind(this), function() { | |
764 // Ignore rejections. | |
765 }.bind(this)); | |
731 }; | 766 }; |
732 | 767 |
733 /** | 768 /** |
734 * If there is an outstanding |listenForRouteMessages| promise for | |
735 * |routeId|, resolve that promise with an empty array. | |
736 * @param {!string} routeId | 769 * @param {!string} routeId |
737 */ | 770 */ |
738 MediaRouteProvider.prototype.stopListeningForRouteMessages = function( | 771 MediaRouteProvider.prototype.stopListeningForRouteMessages = function( |
739 routeId) { | 772 routeId) { |
740 return this.handlers_.stopListeningForRouteMessages(routeId); | 773 this.handlers_.stopListeningForRouteMessages(routeId); |
741 }; | 774 }; |
742 | 775 |
743 /** | 776 /** |
744 * Indicates that the presentation connection that was connected to |routeId| | 777 * Indicates that the presentation connection that was connected to |routeId| |
745 * is no longer connected to it. | 778 * is no longer connected to it. |
746 * @param {!string} routeId | 779 * @param {!string} routeId |
747 */ | 780 */ |
748 MediaRouteProvider.prototype.detachRoute = function( | 781 MediaRouteProvider.prototype.detachRoute = function( |
749 routeId) { | 782 routeId) { |
750 this.handlers_.detachRoute(routeId); | 783 this.handlers_.detachRoute(routeId); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
810 }; | 843 }; |
811 | 844 |
812 mediaRouter = new MediaRouter(connector.bindHandleToProxy( | 845 mediaRouter = new MediaRouter(connector.bindHandleToProxy( |
813 serviceProvider.connectToService( | 846 serviceProvider.connectToService( |
814 mediaRouterMojom.MediaRouter.name), | 847 mediaRouterMojom.MediaRouter.name), |
815 mediaRouterMojom.MediaRouter)); | 848 mediaRouterMojom.MediaRouter)); |
816 | 849 |
817 return mediaRouter; | 850 return mediaRouter; |
818 }); | 851 }); |
819 | 852 |
OLD | NEW |