Re: [EME] Exposing key status to applications

On 9/26/14, 10:49 AM, Mark Watson wrote:
> Personally, I would think a simple API that would achieve this would
> look like a Key ID -> Status map that can be synchronously accessed,
> with events when it changes. So, if session is my MediaKeySession, I
> would be able to do things like
>
> var mykeystatus = session.keys[ myKeyId ];
>
> and
>
> for ( keyId in session.keys ) { ... }

I assume myKeyId is some kinda arbitrary string, right?

The best way to do that, as of today's thinking on API design, is to 
create an interface that mimics the ES Map API but doesn't provide any 
of the mutation methods.

That would give you things like:

   var mykeystatus = session.keys.get(myKeyId)

and

   for (keyId of session.keys.keys())  // loops over key ids

and

   for (keyStatus of session.keys.values()) // loops over key statuses

The fact that two very different things are being called "keys" here is 
a bit annoying, I agree.  :(

You can certainly do this all with Web IDL, though it's a pretty manual 
process to define things like keys() and values().  There are some 
proposals to doing it somewhat automagically via dedicated "make this 
look like a Map" IDL syntax, but nothing concrete there yet.

The reason to do it that way instead of using direct JS property access 
as you proposed is that this will prevent issues like name collisions 
with various builtin stuff (like methods on the object itself).

Whether this sort of API is best for solving your initial problem, I 
can't tell you, but if it is it's quite possible to create.

-Boris

Received on Friday, 26 September 2014 15:55:22 UTC