Impossible to lock sockjs version
See original GitHub issueVersion: 7.3.2
Environment:
- Operating system: Android
- Browser: AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
- Node.js: 10.15.2
I’m seeing the following in the console:
E/browser ( 2462): Console: Uncaught Error: Incompatible SockJS! Main site
uses: "1.3.0", the iframe: "1.1.4". https://cdn.jsdelivr.net/sockjs/1/sockjs.min.js:2
If I understand the flow correctly, this is what happens:
- on this device/browser combination, SockJS tries various transport strategies and eventually picks the
iframe
- it requests the iframe from the server
- in https://github.com/sockjs/sockjs-node/blob/4c9f3009be13962b0785138ccdf527c5abe925f6/lib/iframe.js, the server generates the iframe, embedding the
sockjs_url
argument so the iframe knows where it has to load the library from - here: https://github.com/primus/primus/blob/bfc3f3180aeebe0c45019b8ec86b260935011e52/transformers/sockjs/server.js#L43 primus does not specify a
sockjs_url
, so - at https://github.com/sockjs/sockjs-node/blob/e2369c3d02c7e285ecbac409f3a4d0c8b72c39d3/lib/server.js#L31, sockjs picks the latest from jsdelivr as default
Unfortunately that means that sockjs client updates my happen at any time on end users’ devices, with no way for the developer to first test them.
I fixed this (perhaps simplistically) in https://github.com/sockjs/sockjs-node/blob/e2369c3d02c7e285ecbac409f3a4d0c8b72c39d3/lib/server.js#L31 by changing:
this.service = sockjs.createServer();
Into:
const SOCKJS_CLIENT_VERSION = require('sockjs-client/package.json').version
this.service = sockjs.createServer({
sockjs_url: 'https://cdn.jsdelivr.net/npm/sockjs-client@' + SOCKJS_CLIENT_VERSION + '/dist/sockjs.min.js'
});
If that sounds like a good approach, I’ll prepare a PR.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Trouble with sockjs or dependencies in Angular - Stack Overflow
SockJS SockJSClient initSocket (anonymous) . ... in package-lock.json the dependencia seems right "sockjs": { "version": "0.3.19", ...
Read more >sockjs/sockjs-node: WebSocket emulation - Node.js server
Any SockJS server complying with 0.3 protocol does support a raw WebSocket url. The raw WebSocket url for the test server looks like:...
Read more >where is sockjs-client@1.6.0: defined? : r/reactjs - Reddit
Try looking through the package lock file. ... sockjs-client@^1.5.0: version "1.5.2" resolved ... Seems impossible to get a React job.
Read more >SockJS - Centrifugo
SockJS is a polyfill browser library which provides HTTP-based fallback transports in case when it's not possible to establish Websocket connection.
Read more >26. WebSocket Support - Spring
This is why Spring provides fallback options that emulate the WebSocket API as close as possible based on the SockJS protocol (version 0.3.3)....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
…and on third look, it seems that everything will go right by itself when the following change in
sockjs-node
gets released: https://github.com/sockjs/sockjs-node/commit/dc5a3d9ce809ed5e692bc1a5159546aa4824ee31Currently, it’s the link
https://cdn.jsdelivr.net/sockjs/1/sockjs.min.js
that keeps resolving to sockjs-client 1.1.4 even whensockjs-node
expects 1.3.0. The commit above changes the CDN link tohttps://cdn.jsdelivr.net/npm/sockjs-client@1/dist/sockjs.min.js
which correctly resolves tosockjs-client
1.3.0.Pinging @brycekahle … any chance for a release?
Thank you @brycekahle. I’m closing as there is a workaround until a new release is cut.