-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose Sockjs server/client #1662
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
|
||
/* global __resourceQuery WorkerGlobalScope self */ | ||
|
||
function listen(callback, eventName = 'custom') { | ||
const type = `webpack${eventName}`; | ||
|
||
function handle(message) { | ||
if (message.data == null || message.data.type !== type) return; | ||
callback(message.data); | ||
} | ||
|
||
self.addEventListener('message', handle); | ||
|
||
return function unsubscribe() { | ||
self.removeEventListener('message', handle); | ||
}; | ||
} | ||
|
||
module.exports = listen; |
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,21 @@ | ||
'use strict'; | ||
|
||
/* global WorkerGlobalScope self */ | ||
|
||
function sendWebpackDevServer(data) { | ||
if ( | ||
typeof self !== 'undefined' && | ||
(typeof WorkerGlobalScope === 'undefined' || | ||
!(self instanceof WorkerGlobalScope)) | ||
) { | ||
self.postMessage( | ||
{ | ||
type: 'sendWebpackDevServer', | ||
data: JSON.stringify(data), | ||
}, | ||
'*' | ||
); | ||
} | ||
} | ||
|
||
module.exports = sendWebpackDevServer; |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Advanced SockJS use | ||
|
||
You can now extend the functionality of the SockJS with your custom needs. | ||
|
||
To run this example, run this command in your console or terminal: | ||
|
||
```console | ||
npm run webpack-dev-server -- --advanced-sockjs | ||
``` | ||
|
||
## What Should Happen | ||
|
||
When you visit http://localhost:8080/ then it will automatically send any javascript errors to the webpack-dev-server. | ||
|
||
If you have opened http://localhost:8080/devtools and do keystrokes while you have http://localhost:8080/ running you will see your keystrokes on that page. |
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,29 @@ | ||
'use strict'; | ||
|
||
const target = document.querySelector('#target'); | ||
|
||
target.innerHTML = ` | ||
Open <a href="/devtools" target="_blank">devtools</a> in a new window | ||
<div id="keypressed"></div> | ||
`; | ||
|
||
if (process.env.NODE_ENV === 'development') { | ||
// Simple example to send uncaught error to webpack-dev-server for logging | ||
const send = require('../../../client/send'); // eslint-disable-line global-require | ||
window.addEventListener('error', (error) => | ||
send({ | ||
type: 'log', | ||
data: error.message, | ||
}) | ||
); | ||
|
||
// Simple example of outputting of keystrokes from devtools on screen | ||
const listen = require('../../../client/listen'); // eslint-disable-line global-require | ||
listen((message) => { | ||
if (message.data.type === 'keypress') { | ||
document.querySelector('#keypressed').innerHTML += message.data.data; | ||
} | ||
}); | ||
} | ||
|
||
throw new Error('Hello world'); |
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,14 @@ | ||
'use strict'; | ||
|
||
const send = require('../../../client/send'); | ||
|
||
const target = document.querySelector('#target'); | ||
|
||
target.innerHTML = `Click anywhere on this page and then do some keystrokes`; | ||
|
||
document.addEventListener('keypress', (event) => | ||
send({ | ||
type: 'keypress', | ||
data: String.fromCharCode(event.which), | ||
}) | ||
); |
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 @@ | ||
'use strict'; | ||
|
||
const { setup } = require('../../util'); | ||
|
||
const appConfig = setup({ | ||
name: 'Your app', | ||
entry: './app.js', | ||
}); | ||
Object.assign(appConfig.output, { | ||
publicPath: '/', | ||
}); | ||
|
||
const devToolsConfig = setup({ | ||
name: 'Your custom devTools', | ||
entry: './devTools.js', | ||
devServer: { | ||
before: function before(app, server) { | ||
server.subscribeClientData(({ message }) => { | ||
switch (message.type) { | ||
case 'log': | ||
return console.log(message.data); | ||
case 'keypress': | ||
return server.sockWrite(server.sockets, 'custom', message); | ||
default: | ||
} | ||
}); | ||
}, | ||
}, | ||
}); | ||
Object.assign(devToolsConfig.output, { | ||
path: `${devToolsConfig.output.path}/devtools`, | ||
publicPath: '/devtools', | ||
}); | ||
|
||
module.exports = function createConfigs(env, argv) { | ||
return [].concat(argv.mode === 'production' ? [] : devToolsConfig, appConfig); | ||
}; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Breaking change for multi compiler compilation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never remove messages, because you can have two/three/four clients, and some clients can have delay
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you mean? If you lose connection and reconnect you probably don't want to resend all messages again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added the message queue for messages that are sent before the connection is fully established or else you will get an error from sockjs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@EloB open two or three browsers and tests how it works, we already do same before and remove this, because it is break situation when you have more then one client (some client can disconnect and connect again)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That
initSocket
looks really weird in the first place because it's not pure and does side effects onsock
in a recursive fashion.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@evilebottnawi Maybe we could rewrite that
initSocket
to be pure instead?