Skip to content

Commit 80493fe

Browse files
author
ionut.stan
committed
Electron browser mode fixes.
1 parent 743105e commit 80493fe

File tree

7 files changed

+27
-22
lines changed

7 files changed

+27
-22
lines changed

builds/browser/es5/jsonrpc.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

builds/browser/es5/jsonrpc.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

builds/browser/es7/jsonrpc.min.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,12 @@ module.exports = class Server extends EventEmitter {
987987

988988
if (incomingRequest.isNotification) {} else {
989989
httpResponse.setHeader("Content-Type", "application/json");
990-
httpResponse.write(incomingRequest.callResultSerialized);
990+
991+
if (typeof incomingRequest.callResultSerialized === "object") {
992+
httpResponse.write(JSON.stringify(incomingRequest.callResultSerialized, undefined, "\t"));
993+
} else {
994+
httpResponse.write(incomingRequest.callResultSerialized);
995+
}
991996
}
992997
} catch (error) {
993998
httpResponse.statusCode = 500;
@@ -8724,7 +8729,7 @@ let electron = null;
87248729
if (process && process.versions["electron"]) {
87258730
electron = __webpack_require__(39);
87268731

8727-
if ((window || self) && !electron && typeof (window || self).require === "function") {
8732+
if (!electron && (window || self) && typeof (window || self).require === "function") {
87288733
electron = (window || self).require("electron");
87298734
}
87308735
}
@@ -8808,7 +8813,7 @@ module.exports = class BidirectionalElectronIPCRouter extends JSONRPC.RouterBase
88088813

88098814
const nConnectionID = ++this._nConnectionIDCounter;
88108815

8811-
const strChannel = "jsonrpc_winid_" + electron.remote.getCurrentWindow().id;
8816+
const strChannel = "jsonrpc_winid_" + (window || self).require("electron").remote.getCurrentWindow().id;
88128817

88138818
const objSession = {
88148819
browserWindow: null,
@@ -8821,7 +8826,7 @@ module.exports = class BidirectionalElectronIPCRouter extends JSONRPC.RouterBase
88218826

88228827
this._objSessions[nConnectionID] = objSession;
88238828

8824-
electron.ipcRenderer.on(strChannel, async (event, objJSONRPCRequest) => {
8829+
(window || self).require("electron").ipcRenderer.on(strChannel, async (event, objJSONRPCRequest) => {
88258830
await this._routeMessage(objJSONRPCRequest, objSession, strChannel);
88268831
});
88278832

@@ -8926,7 +8931,7 @@ module.exports = class BidirectionalElectronIPCRouter extends JSONRPC.RouterBase
89268931
if (browserWindow) {
89278932
browserWindow.webContents.send(strChannel, incomingRequest.callResultToBeSerialized);
89288933
} else {
8929-
electron.ipcRenderer.send(strChannel, incomingRequest.callResultToBeSerialized);
8934+
(window || self).require("electron").ipcRenderer.send(strChannel, incomingRequest.callResultToBeSerialized);
89308935
}
89318936
}
89328937
} else if (objMessage.hasOwnProperty("result") || objMessage.hasOwnProperty("error")) {
@@ -10135,7 +10140,7 @@ module.exports = class DebugLogger extends JSONRPC.ClientPluginBase {
1013510140
if (process && process.versions["electron"]) {
1013610141
electron = __webpack_require__(39);
1013710142

10138-
if ((window || self) && !electron && typeof (window || self).require === "function") {
10143+
if (!electron && (window || self) && typeof (window || self).require === "function") {
1013910144
electron = (window || self).require("electron");
1014010145
}
1014110146
}
@@ -10155,7 +10160,7 @@ module.exports = class ElectronIPCTransport extends JSONRPC.ClientPluginBase {
1015510160
this._bBidirectionalMode = !!bBidirectionalMode;
1015610161
this._browserWindow = browserWindow;
1015710162

10158-
this._strChannel = "jsonrpc_winid_" + (browserWindow ? browserWindow.id : electron.remote.getCurrentWindow().id);
10163+
this._strChannel = "jsonrpc_winid_" + (browserWindow ? browserWindow.id : (window || self).require("electron").remote.getCurrentWindow().id);
1015910164

1016010165
this._setupIPCTransport();
1016110166
}
@@ -10214,7 +10219,7 @@ module.exports = class ElectronIPCTransport extends JSONRPC.ClientPluginBase {
1021410219
if (this.browserWindow) {
1021510220
this.browserWindow.webContents.send(this.channel, outgoingRequest.requestObject);
1021610221
} else {
10217-
electron.ipcRenderer.send(this.channel, outgoingRequest.requestObject);
10222+
(window || self).require("electron").ipcRenderer.send(this.channel, outgoingRequest.requestObject);
1021810223
}
1021910224

1022010225
if (outgoingRequest.isNotification) {} else {
@@ -10244,7 +10249,7 @@ module.exports = class ElectronIPCTransport extends JSONRPC.ClientPluginBase {
1024410249
_setupIPCTransport() {
1024510250
if (!this.browserWindow) {
1024610251
if (!this._bBidirectionalMode) {
10247-
electron.ipcRenderer.on(this._strChannel, async (event, objJSONRPCRequest) => {
10252+
(window || self).require("electron").ipcRenderer.on(this._strChannel, async (event, objJSONRPCRequest) => {
1024810253
await this.processResponse(objJSONRPCRequest);
1024910254
});
1025010255
}

builds/browser/es7/jsonrpc.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "jsonrpc-bidirectional",
33
"description": "Bidirectional JSONRPC over web sockets or HTTP with extensive plugin support.",
4-
"version": "6.4.3",
4+
"version": "6.4.9",
55
"scripts": {
66
"build": "node build.js",
77
"test": "node --expose-gc --max-old-space-size=1024 tests/main.js",

src/BidirectionalElectronIPC.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if(process && process.versions["electron"])
88
electron = require("electron");
99

1010
// Browser environment
11-
if((window || self) && !electron && typeof (window || self).require === "function")
11+
if(!electron && (window || self) && typeof (window || self).require === "function")
1212
{
1313
electron = (window || self).require("electron");
1414
}
@@ -145,7 +145,7 @@ class BidirectionalElectronIPCRouter extends JSONRPC.RouterBase
145145

146146
const nConnectionID = ++this._nConnectionIDCounter;
147147

148-
const strChannel = "jsonrpc_winid_" + electron.remote.getCurrentWindow().id;
148+
const strChannel = "jsonrpc_winid_" + (window || self).require("electron").remote.getCurrentWindow().id;
149149

150150
const objSession = {
151151
browserWindow: null,
@@ -158,7 +158,7 @@ class BidirectionalElectronIPCRouter extends JSONRPC.RouterBase
158158

159159
this._objSessions[nConnectionID] = objSession;
160160

161-
electron.ipcRenderer.on(
161+
(window || self).require("electron").ipcRenderer.on(
162162
strChannel,
163163
async (event, objJSONRPCRequest) => {
164164
await this._routeMessage(objJSONRPCRequest, objSession, strChannel);
@@ -312,7 +312,7 @@ class BidirectionalElectronIPCRouter extends JSONRPC.RouterBase
312312
}
313313
else
314314
{
315-
electron.ipcRenderer.send(strChannel, incomingRequest.callResultToBeSerialized);
315+
(window || self).require("electron").ipcRenderer.send(strChannel, incomingRequest.callResultToBeSerialized);
316316
}
317317
}
318318
}

src/Plugins/Client/ElectronIPCTransport.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if(process && process.versions["electron"])
66
electron = require("electron");
77

88
// Browser environment
9-
if((window || self) && !electron && typeof (window || self).require === "function")
9+
if(!electron && (window || self) && typeof (window || self).require === "function")
1010
{
1111
electron = (window || self).require("electron");
1212
}
@@ -43,7 +43,7 @@ class ElectronIPCTransport extends JSONRPC.ClientPluginBase
4343
this._bBidirectionalMode = !!bBidirectionalMode;
4444
this._browserWindow = browserWindow;
4545

46-
this._strChannel = "jsonrpc_winid_" + (browserWindow ? browserWindow.id : electron.remote.getCurrentWindow().id);
46+
this._strChannel = "jsonrpc_winid_" + (browserWindow ? browserWindow.id : (window || self).require("electron").remote.getCurrentWindow().id);
4747

4848
this._setupIPCTransport();
4949
}
@@ -168,7 +168,7 @@ class ElectronIPCTransport extends JSONRPC.ClientPluginBase
168168
}
169169
else
170170
{
171-
electron.ipcRenderer.send(this.channel, outgoingRequest.requestObject);
171+
(window || self).require("electron").ipcRenderer.send(this.channel, outgoingRequest.requestObject);
172172
}
173173

174174

@@ -225,7 +225,7 @@ class ElectronIPCTransport extends JSONRPC.ClientPluginBase
225225
{
226226
if(!this._bBidirectionalMode)
227227
{
228-
electron.ipcRenderer.on(
228+
(window || self).require("electron").ipcRenderer.on(
229229
this._strChannel,
230230
async (event, objJSONRPCRequest) => {
231231
await this.processResponse(objJSONRPCRequest);

0 commit comments

Comments
 (0)