{"action":"created","issue":{"url":"https://api.github.com/repos/w3c/wake-lock/issues/55","labels_url":"https://api.github.com/repos/w3c/wake-lock/issues/55/labels{/name}","comments_url":"https://api.github.com/repos/w3c/wake-lock/issues/55/comments","events_url":"https://api.github.com/repos/w3c/wake-lock/issues/55/events","html_url":"https://github.com/w3c/wake-lock/issues/55","id":94990995,"number":55,"title":"Current API not friendly to components","user":{"login":"sicking","id":1831914,"avatar_url":"https://avatars.githubusercontent.com/u/1831914?v=3","gravatar_id":"","url":"https://api.github.com/users/sicking","html_url":"https://github.com/sicking","followers_url":"https://api.github.com/users/sicking/followers","following_url":"https://api.github.com/users/sicking/following{/other_user}","gists_url":"https://api.github.com/users/sicking/gists{/gist_id}","starred_url":"https://api.github.com/users/sicking/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sicking/subscriptions","organizations_url":"https://api.github.com/users/sicking/orgs","repos_url":"https://api.github.com/users/sicking/repos","events_url":"https://api.github.com/users/sicking/events{/privacy}","received_events_url":"https://api.github.com/users/sicking/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-07-14T16:58:22Z","updated_at":"2015-07-16T07:38:06Z","closed_at":null,"body":"My impression is that the main consumer of the API is video playing websites. I.e. holding the screen awake while a video is playing.\r\n\r\nHowever more often than not video playing is done through a library. Either in order to provide fallback to flash, or in order to provide a customized player UI, or both.\r\n\r\nHowever the current API doesn't seem very friendly to such a library. The library could simply set `keepScreenAwake=true` when playing starts, and `keepScreenAwake=false` when playing ends. However that might result in the lock getting released too early if something else on the page also wants to hold the lock alive. For example if another video is playing.\r\n\r\nThis, or at least a similar, concern was brought up earlier against the spec. At that time the response was that the library could be written such that it takes a callback, and then calls that callback in order to grab/release a screen lock. The main page could then take care of coordination if multiple components on the page attempts to grab a lock at once.\r\n\r\nThis doesn't seem like a particularly good solution though. It means that API isn't a good fit for what is likely the main use case of this API, video-playing through a library. While a workaround is possible, it is fairly awkward and clearly a workaround.\r\n\r\nConcretely, it would likely either mean that adoption of the API is significantly slowed down since it requires both video playing libraries and webpages using those libraries to adopt the API. But more likely is that pages will simply ignore the problem of multiple components grabbing the lock at once, leading to buggy pages where the lock gets released too early, which will result in a bad experience for users.\r\n\r\nInstead I suggest we adopt an API like\r\n\r\n`screen.keepAwakeUntil(promise);`\r\n\r\n(Feel free to bikeshed the name, or put it on a different object)\r\n\r\nwhich would keep the screen kept awake until the promise is resolved. This function could be called any number of times and only once the last promise is resolved is the screen lock released. This way the video player library can release its screen lock without worrying about bad interactions with other components on the same page, and without having to change its API towards the embedding page.\r\n\r\nThis approach also has the advantage of tying into promise infrastructure, which likely will mean that many times the page doesn't have to remember to explicitly release the lock, but can instead just grab an existing promise."},"comment":{"url":"https://api.github.com/repos/w3c/wake-lock/issues/comments/121862814","html_url":"https://github.com/w3c/wake-lock/issues/55#issuecomment-121862814","issue_url":"https://api.github.com/repos/w3c/wake-lock/issues/55","id":121862814,"user":{"login":"marcoscaceres","id":870154,"avatar_url":"https://avatars.githubusercontent.com/u/870154?v=3","gravatar_id":"","url":"https://api.github.com/users/marcoscaceres","html_url":"https://github.com/marcoscaceres","followers_url":"https://api.github.com/users/marcoscaceres/followers","following_url":"https://api.github.com/users/marcoscaceres/following{/other_user}","gists_url":"https://api.github.com/users/marcoscaceres/gists{/gist_id}","starred_url":"https://api.github.com/users/marcoscaceres/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcoscaceres/subscriptions","organizations_url":"https://api.github.com/users/marcoscaceres/orgs","repos_url":"https://api.github.com/users/marcoscaceres/repos","events_url":"https://api.github.com/users/marcoscaceres/events{/privacy}","received_events_url":"https://api.github.com/users/marcoscaceres/received_events","type":"User","site_admin":false},"created_at":"2015-07-16T07:38:06Z","updated_at":"2015-07-16T07:38:06Z","body":"I also agree that this approach is better. "}}