Skip to content

Instantly share code, notes, and snippets.

@jangnezda
jangnezda / VxConnector.js
Created July 23, 2013 21:13
A small component handling connections to the server. Note that there is no actual connecting code -> that is handled by clients. This is more like a manager that handles reconnects, reconnect schedule and edge cases like computer waking up from sleep.
var voxioConnector = (function() {
var clients = [],
clientTimeout = 15000, // 15 seconds
clientTimeoutId,
clientState = { DISCONNECTED: "disconnected", CONNECTED: "connected", CONNECTING: "connecting" },
currentClientIndex = -1,
active = false;
function handleError(e) {
console.log(e);
@jangnezda
jangnezda / main.js
Last active December 8, 2021 17:02
How to capture requests from <iframe> in Electron window
/*
* By default, the Electron (or underlying Chrome instance, to be more precise) will not allow
* javascript communication between parent window and an <iframe>. Which makes it hard to cover
* scenarios when you want to do something after an action has been performed inside the <iframe>.
* This example shows how to react on web reqest from within <iframe>.
*
* The 'onBeforeRequest' listener is documented here:
* http://electron.atom.io/docs/api/session/#webrequestonbeforerequestfilter-listener
*/
@jangnezda
jangnezda / main.js
Created October 12, 2016 11:44
How to load an external URL in <iframe> using Electron
/*
* By default, Electron (well, underlying Chrome browser) will reject loading external URLs
* to an <iframe>. To circumvent this limitation, we can manipulate response headers from any
* http request and feed them to the Electron window.
*
* The 'onHeadersReceived' listener is documented here:
* http://electron.atom.io/docs/api/session/#webrequestonheadersreceivedfilter-listener
*/
app.on('ready', () => {