- From: Tomoyuki Shimizu via GitHub <sysbot+gh@w3.org>
- Date: Wed, 23 May 2018 08:13:25 +0000
- To: public-secondscreen@w3.org
@Mathieu-R Those codes to handle connections seem confused. Basically, we can start a presentation by either of the following steps:
1. Create a presentation request and call `request.start()`
2. Set a presentation request to `navigator.presentation.defaultRequest` and **click a cast button or menu on the browser's GUI**
<img width="298" alt="screen shot 2018-05-23 at 16 37 56" src="https://user-images.githubusercontent.com/3643972/40410433-c8b0b65c-5ea8-11e8-8abe-928ec45afc26.png">
Then, a presentation connection will be passed via:
- the Promise returned by `request.start()`, in the case of 1.
- the `connectionavailable` event, in the case of 2.
So the following examples are my suggestion:
```js
if (!id) {
this.request.start();
} else {
this.reconnect(id);
}
```
These should be corrected like:
```js
let connection;
if (!id) {
connection = await this.request.start();
} else {
connection = await this.reconnect(id);
}
await this.setConnection(connection);
resolve();
```
And then,
```js
// wait until connection is available
// otherwise we would send data before connection is ready
navigator.presentation.defaultRequest.onconnectionavailable = async evt => {
await this.setConnection(evt.connection);
resolve();
}
```
These codes should be called in the constructor (after `navigator.presentation.defaultRequest = this.request;`), rather than in `cast()` method.
--
GitHub Notification of comment by tomoyukilabs
Please view or discuss this issue at https://github.com/w3c/presentation-api/issues/450#issuecomment-391260395 using your GitHub account
Received on Wednesday, 23 May 2018 08:13:30 UTC