Skip to content

Commit

Permalink
Merge pull request #1344 from exokitxr/payment-request
Browse files Browse the repository at this point in the history
Payment Request API
  • Loading branch information
Avaer Kazmer authored Jul 30, 2019
2 parents fa36152 + 494136b commit 8c518b0
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/DOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -2228,6 +2228,19 @@ class HTMLIFrameElement extends HTMLSrcableElement {
event,
});
},
onpaymentrequest(event) {
if (window.listeners('paymentrequest').length > 0) {
window.dispatchEvent(new CustomEvent('paymentrequest', {
detail: event,
}));
} else {
parentPort.postMessage({
method: 'emit',
type: 'paymentRequest',
event,
});
}
},
});
this.contentWindow.document = this.contentDocument;

Expand Down
27 changes: 27 additions & 0 deletions src/Window.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,32 @@ class CustomElementRegistry {
}
}

class PaymentRequest {
constructor(methodData, details, options) {
this.methodData = methodData;
this.details = details;
this.options = options;
}

async show() {
const {methodData, details, options} = this;

const listeners = window.listeners('paymentrequest');
if (listeners.length > 0) {
parentPort.postMessage({
method: 'paymentRequest',
event: {
methodData,
details,
options,
},
});
} else {
throw new Error('no payment request handler');
}
}
}

class MonitorManager {
getList() {
return nativeWindow.getMonitors();
Expand Down Expand Up @@ -856,6 +882,7 @@ const _makeRequestAnimationFrame = window => (fn, priority = 0) => {
window.StereoPannerNode = StereoPannerNode;
window.createImageBitmap = createImageBitmap;
window.Worker = Worker;
window.PaymentRequest = PaymentRequest;
window.requestAnimationFrame = _makeRequestAnimationFrame(window);
window.cancelAnimationFrame = id => {
const index = rafCbs.findIndex(r => r && r[symbols.idSymbol] === id);
Expand Down
3 changes: 3 additions & 0 deletions src/WindowVm.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ const _makeWindow = (options = {}, handlers = {}) => {
window.on('hapticPulse', e => {
options.onhapticpulse && options.onhapticpulse(e);
});
window.on('paymentRequest', e => {
options.onpaymentrequest && options.onpaymentrequest(e);
});
window.on('error', err => {
console.warn(err.stack);
});
Expand Down
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,9 @@ const handleHapticPulse = ({index, value, duration}) => {
// TODO: handle the other HMD cases...
}
};
const handlePaymentRequest = () => {
throw new Error('no payment request handler');
};

const _startTopRenderLoop = () => {
const timestamps = {
Expand Down Expand Up @@ -1485,6 +1488,7 @@ const _start = () => {
onnavigate: _onnavigate,
onrequest: handleRequest,
onhapticpulse: handleHapticPulse,
onpaymentrequest: handlePaymentRequest,
});
};
_onnavigate(u);
Expand All @@ -1509,6 +1513,7 @@ const _start = () => {
onnavigate: _onnavigate,
onrequest: handleRequest,
onhapticpulse: handleHapticPulse,
onpaymentrequest: handlePaymentRequest,
});

const prompt = '[x] ';
Expand Down

0 comments on commit 8c518b0

Please sign in to comment.