forked from onsip/SIP.js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split src/environment.js into Node/browser versions
src/environment_browser.js: Use global variables instead of requiring modules. This undoes the effects of the following commits, removing ~1KB from the bundle size: 51003e3: Timers: require('timers') instead of directly using global 8baf989: LoggerFactory: require('console') instead of directly using global b69fef8: Utils.Promise = global.Promise || require('promiscuous'); src/environment.js: Export a Node-compatible environment by extending the browser environment with the modules listed above. Gruntfile.js: Tests polyfill Promise using promiscuous-browser.js
- Loading branch information
1 parent
9a2b089
commit 8a53889
Showing
6 changed files
with
47 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,7 @@ | |
"main": "src/index.js", | ||
"browser": { | ||
"./src/Grammar/index.js": "./src/Grammar/dist/Grammar.js", | ||
"promiscuous": "./src/polyfills/promiscuous.js", | ||
"console": "./src/polyfills/console.js" | ||
"./src/environment.js": "./src/environment_browser.js" | ||
}, | ||
"homepage": "http://sipjs.com", | ||
"author": "Will Mitchell <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,9 @@ | ||
function getPrefixedProperty (object, name) { | ||
if (object == null) { | ||
return; | ||
} | ||
var capitalizedName = name.charAt(0).toUpperCase() + name.slice(1); | ||
var prefixedNames = [name, 'webkit' + capitalizedName, 'moz' + capitalizedName]; | ||
for (var i in prefixedNames) { | ||
var property = object[prefixedNames[i]]; | ||
if (property) { | ||
return property.bind(object); | ||
} | ||
} | ||
} | ||
var extend = require('util')._extend; | ||
|
||
module.exports = { | ||
WebSocket: global.WebSocket, | ||
open: global.open, | ||
extend(exports, require('./environment_browser')); | ||
|
||
extend(exports, { | ||
Promise: global.Promise || require('promiscuous'), | ||
console: require('console'), | ||
timers: require('timers'), | ||
|
||
MediaStream: getPrefixedProperty(global, 'MediaStream'), | ||
getUserMedia: getPrefixedProperty(global.navigator, 'getUserMedia'), | ||
RTCPeerConnection: getPrefixedProperty(global, 'RTCPeerConnection'), | ||
RTCSessionDescription: getPrefixedProperty(global, 'RTCSessionDescription'), | ||
|
||
attachMediaStream: global.attachMediaStream, | ||
// these aren't prefixed, but some platforms don't have global.URL | ||
createObjectURL: getPrefixedProperty(global.URL, 'createObjectURL'), | ||
revokeObjectURL: getPrefixedProperty(global.URL, 'revokeObjectURL') | ||
}; | ||
timers: require('timers') | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
function getPrefixedProperty (object, name) { | ||
if (object == null) { | ||
return; | ||
} | ||
var capitalizedName = name.charAt(0).toUpperCase() + name.slice(1); | ||
var prefixedNames = [name, 'webkit' + capitalizedName, 'moz' + capitalizedName]; | ||
for (var i in prefixedNames) { | ||
var property = object[prefixedNames[i]]; | ||
if (property) { | ||
return property.bind(object); | ||
} | ||
} | ||
} | ||
|
||
module.exports = { | ||
WebSocket: global.WebSocket, | ||
open: global.open, | ||
Promise: global.Promise, | ||
timers: global, | ||
|
||
// Console is not defined in ECMAScript, so just in case... | ||
console: global.console || { | ||
debug: function () {}, | ||
log: function () {}, | ||
warn: function () {}, | ||
error: function () {} | ||
}, | ||
|
||
MediaStream: getPrefixedProperty(global, 'MediaStream'), | ||
getUserMedia: getPrefixedProperty(global.navigator, 'getUserMedia'), | ||
RTCPeerConnection: getPrefixedProperty(global, 'RTCPeerConnection'), | ||
RTCSessionDescription: getPrefixedProperty(global, 'RTCSessionDescription'), | ||
|
||
attachMediaStream: global.attachMediaStream, | ||
createObjectURL: global.URL && global.URL.createObjectURL, | ||
revokeObjectURL: global.URL && global.URL.revokeObjectURL | ||
}; |
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
src/polyfills/promiscuous.js → test/polyfills/promiscuous-browser.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.