Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Commit 9274db9

Browse files
aapzuhpihkala
authored andcommitted
Add a hack to make streamr-client work with Webpack
* client has its own ws now. examples fixed * think (again) that I fixed the modularization issues * added comments to describe changes
1 parent 4a23c7a commit 9274db9

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

streamr-client.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
"use strict";
22

33
(function() {
4-
5-
var debug
6-
if (typeof module !== 'undefined') {
7-
debug = require('debug')('StreamrClient')
8-
} else {
9-
debug = (window.debug ? window.debug('StreamrClient') : function() {
10-
if (window.consoleLoggingEnabled)
11-
console.log.apply(console, arguments)
12-
})
13-
}
144

15-
var WebSocket
16-
if (typeof module !== 'undefined') {
17-
WebSocket = require('ws')
18-
} else {
19-
WebSocket = window.WebSocket
20-
}
21-
5+
/* <---
6+
Checking of the environment must be done with ternary operator instead of if-clause because of (possible) usage in Webpack.
7+
With if-clause, Webpack forces the code to use require, also in browser.
8+
Now it just works, in browser, in Node.js and in browser with Webpack. */
9+
var debug = (typeof window !== 'undefined' && window.debug) ? window.debug('StreamrClient') : // If in browser and window.debug exists
10+
(typeof require !== 'undefined' ? require('debug')('StreamrClient') : // Else if in node
11+
function() { // Else use mock
12+
if (window.consoleLoggingEnabled)
13+
console.log.apply(console, arguments)
14+
})
15+
16+
var WebSocket = typeof window !== 'undefined' ? window.WebSocket : require('ws')
17+
/* ---> */
18+
2219
var BYE_KEY = "_bye"
2320

2421
function extend() {

0 commit comments

Comments
 (0)