W3C home > Mailing lists > Public > public-secondscreen@w3.org > June 2015

Re: [presentation-api] Specify behavior when multiple controlling pages are connected to the session

From: Anton Vayvod via GitHub <sysbot+gh@w3.org>
Date: Fri, 05 Jun 2015 18:19:12 +0000
To: public-secondscreen@w3.org
Message-ID: <issue_comment.created-109386548-1433528351-sysbot+gh@w3.org>
How about the following spec change for the multiple connections? It's
 based on the assumption that only one controller can connect to the 
presentation page at a time. If the page is slow handling each 
controller, the UA can simply queue them and resolve the next call to 
```getNextController``` when needed.

partial interface NavigatorPresentation {
    Promise<PresentationSession> getNextController();  // replaces 

Then a simple presentation page supporting one controller would need 
to write something like this:


var handleController = function(controller) {
    controller.onstatechange = function(e) {
        if (e.state == "connected") {
            controller.onmessage = function(e) {
                showMessage("Received message " + e.msg);
        } else if (e.state == "disconnected") {
            // wait for the controller to connect back
        } else if (e.state == "terminated") {
            // nothing to do, the page is being closed, for the sake 
of completeness

And code for the page supporting multiple controllers would look like 

// controllers
var mControllers = [];
// maximum number of controllers to join the presentation

// announce that the page is ready to become a presentation and 
receive its first controller
// assume that only one controller can start the presentation or 
connect to it at the time

var handleControllerAdded = function(controller) {
    showMessage("Controller added: " + controller.id);
    // assert controller.state == "connecting";
    controller.onstatechange = function(e) {
        if (e.state == "connected") {
        } else if (e.state == "disconnected" || e.state == 
"terminated") {

var handleControllerConnection = function(controller) {
    if (mControllers.empty()) {
    controller.onmessage = function(e) {
        showMessage("Received message " + e.msg + " from " + this.id);
    if (mControllers.length < MAX_CONTROLLERS) {

var handleControllerDisconnection = function(controller) {
    if (mControllers.empty()) {
    } else if (mControllers.length < MAX_CONTROLLERS) {

var setUp = function() {
    showMessage("The presentation is connected");

var shutDown = function() {
    showMessage("No controllers, please connect.");

The semantic of the method is as following:

1. If there's no active connection and no pending promise returned by 
```getNextController()``` - the page is not ready to become a 
presentation yet (relevant to issue #32).
2. If there's no active connection but a promise returned by 
```getNextController()``` is pending, the page designates itself as a 
presentation page and is ready to accept controllers connecting 
(relevant to issue #32  too).
3. If there's an active connection but no pending promise returned by 
```getNextController()``` (meaning one or more 
```getNextController()``` promises have resolved before, at least one 
of the controllers is in the connected state, the page doesn't want 
more controllers), the presentation can't be connected to anymore and 
can be replaced when something else starts a presentation to the same 
screen (or starting the presentation can be rejected by the UA that 
tried to connect).
4. If there's an active connection and a promise pending from a 
previous ```getNextController()```, the page expects more controllers 
to join and the promise will be resolved as soon as another controller
 joins the presentation.

GitHub Notif of comment by avayvod
Received on Friday, 5 June 2015 18:19:14 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:18:56 UTC