Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show MediaKeyMessageEvent.messageType #27

Closed
xhwang-chromium opened this issue Dec 2, 2021 · 4 comments · Fixed by #32
Closed

Show MediaKeyMessageEvent.messageType #27

xhwang-chromium opened this issue Dec 2, 2021 · 4 comments · Fixed by #32
Assignees
Labels
status: archived Archived and locked; will not be updated type: bug Something isn't working correctly

Comments

@xhwang-chromium
Copy link
Contributor

Currently MediaKeyMessageEvent is displayed as MediaKeySession message event where only the message is shown. It'd be great to also see the MediaKeyMessageEvent.messageType, e.g. license-request or license-renewal.

See the screenshot below for the current behavior:

Capture

@joeyparrish
Copy link
Member

I'm not sure why that's not showing. I'll take a look.

@joeyparrish joeyparrish added the type: bug Something isn't working correctly label Dec 13, 2021
@joeyparrish joeyparrish self-assigned this Dec 13, 2021
@joeyparrish
Copy link
Member

Where we hook in the formatter, we're using a spread operator to copy all the fields of the original to the formatted version:

    // You can't (and shouldn't, to avoid breaking the app) modify the event
    // object here.  So clone it, and replace the message field of that.
    log.event = {
      // The spread operator reads the fields and values (shallow clone) of the
      // object named here.
      ...log.event,
      // This overrides on of those fields with a new value.
      message: formatEmeRequest(log.event.message),
    };

It's not working, though. Only isTrusted gets copied by the spread operator.

@joeyparrish
Copy link
Member

It appears that the difference is in "own" properties. The spread operator seems to only copy an object's "own" properties, and this object's only "own" property is isTrusted.

orig
MediaKeyMessageEvent {isTrusted: true, messageType: 'license-request', message: ArrayBuffer(2), type: 'message', target: MediaKeySession, …}

{...orig}
{isTrusted: true}

Object.keys(orig)
['isTrusted']

JSON.stringify(orig)
'{"isTrusted":true}'

a = []; for (k in orig) { a.push(k); }; a;
(25) ['isTrusted', 'messageType', 'message', 'type', 'target', 'currentTarget', 'eventPhase', 'bubbles', 'cancelable', 'defaultPrevented', 'composed', 'timeStamp', 'srcElement', 'returnValue', 'cancelBubble', 'path', 'NONE', 'CAPTURING_PHASE', 'AT_TARGET', 'BUBBLING_PHASE', 'composedPath', 'initEvent', 'preventDefault', 'stopImmediatePropagation', 'stopPropagation']

for (k in orig) { if (orig.hasOwnProperty(k)) console.log(k); }
isTrusted

@joeyparrish
Copy link
Member

Object.assign has the same drawback as the spread operator and Object.keys:

Object.assign({}, orig)
{isTrusted: true}

Thinking about "own" properties, though, it seems I can just filter out the properties inherited from Event:

for (k in orig) { if (!Event.prototype.hasOwnProperty(k)) console.log(k); }
isTrusted
messageType
message

I should be able to write a custom cloning method for Event objects to ensure the copy has everything it should.

@github-actions github-actions bot added the status: archived Archived and locked; will not be updated label Feb 24, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: archived Archived and locked; will not be updated type: bug Something isn't working correctly
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants