sockjs as a direct dependency, by default this will be replaced with wsclientMode: 'ws', by defaultsockjs themselves, then set clientMode: require.resolve('sockjs') if they want to support older browsers with dicey websocket support.If we do that require method to allow sockjs as a clientMode then if the user wanted to make their own server implementation they would need to implement in the same way as the sockjs API, specifically the parts the Dev Server uses (they would need a createServer method, event listeners, etc.). We could also alter this API slightly as we like and create adapters for essential servers like sockjs. Then we can make an adapter for ws and simply implement it as the default in that way. (Should this be called serverMode instead since it is the server implementation?)
We need a similar method for the client. I'm not sure how to do this best so that the user can pass their implementation into the Node server. Maybe I am missing an easier way. My thoughts are:
Tasks to complete for client/server refactor:
Server
serverMode option which takes a string for existing/default implementations, or a class (extending some class like BaseServer) which the user would have to implement themselvesClient
clientMode option, again takes a string for existing/default implementations or a class that the user implementsExtra
Edit
ws server should go with ws client)@Loonride LGTM @evilebottnawi thoughts?
LGTM, we can introduce serverMode and clientMode as experimental to allow us do breaking changes without major release
Don't forget about CLI refactor
/cc @Loonride friendly ping, what is status of ws?
@evilebottnawi Once https://github.com/webpack/webpack-dev-server/pull/2090 is merged, ws mode will work by doing:
{
serverMode: 'ws',
clientMode: 'ws'
}
Then what remains is:
ws mode default on next branch (Should be an easy switch)ws)serverMode and clientMode implementations){
serverMode: 'ws',
clientMode: 'ws'
}
For do you think about union this options to one,
Why?
@evilebottnawi Good idea, maybe we should use a different name like socketMode or transportMode though?
agree, transportMode sounds good, in theory transport can be not socket
/cc @hiroppy what do you think about name?
I like this schema:)
transportMode: {
server: 'ws',
client: 'ws'
}
@Loonride yep, let's rename mode to transportMode, we can't save compatibility because it is experimental
Done and ws is default for v4
Most helpful comment
Tasks to complete for client/server refactor:
Server
serverModeoption which takes a string for existing/default implementations, or a class (extending some class like BaseServer) which the user would have to implement themselvesClient
clientModeoption, again takes a string for existing/default implementations or a class that the user implementsExtra
Edit
wsserver should go withwsclient)