lahsivjar / react-stomp

React websocket component for STOMP protocol over SockJs
https://www.npmjs.com/package/react-stomp
MIT License
135 stars 41 forks source link

headers are ignored #53

Closed fil512 closed 6 years ago

fil512 commented 6 years ago

I need my server to know who is connecting. But react-stomp appears to be ignoring the "headers" parameter.

render() { const wsSourceUrl = window.location.protocol + '//' + window.location.host + '/ws'; const myHeaders = { login: "test" }

return (
  <div>
    <SockJsClient
      url={wsSourceUrl}
      headers={myHeaders}
      topics={['/topic/public']}
      onMessage={this.onMessageReceive}
      onConnect={this.onConnect}
      onDisconnect={this.onDisconnect}
      ref={client => {
        this.clientRef = client;
      }}
      debug
    />

In browser devtools, outbound websocket message recorded as:

["CONNECT\naccept-version:1.1,1.0\nheart-beat:10000,10000\n\n\u0000"]

And on server, received connect message is:

StompHeaderAccessor [headers={simpMessageType=CONNECT_ACK, simpConnectMessage=GenericMessage [payload=byte[0], headers={simpMessageType=CONNECT, stompCommand=CONNECT, nativeHeaders={accept-version=[1.1,1.0], heart-beat=[10000,10000]}, simpSessionAttributes={}, simpHeartbeat=[J@55060fb8, simpSessionId=xgbl4eog}], simpSessionId=xgbl4eog}]

lahsivjar commented 6 years ago

@fil512 Please provide more information about the version of react-stomp you are using. I am not able to reproduce this error with the latest version 3.3.0

react-header
fil512 commented 6 years ago

Thanks for the quick reply!

I am running 3.3.0. I wonder if another package is interfering?

Here's my package.json:

{ "name": "wgr-server", "version": "0.0.0", "description": "Description for wgrServer", "private": true, "license": "UNLICENSED", "cacheDirectories": [ "node_modules" ], "dependencies": { "@fortawesome/fontawesome-svg-core": "1.2.0", "@fortawesome/free-solid-svg-icons": "5.1.0", "@fortawesome/react-fontawesome": "0.1.0", "availity-reactstrap-validation": "2.0.2", "axios": "0.18.0", "bootstrap": "4.1.1", "loaders.css": "0.1.2", "lodash": "4.17.10", "moment": "2.22.2", "react": "16.4.1", "react-addons-css-transition-group": "16.0.0-alpha.3", "react-addons-transition-group": "16.0.0-alpha.3", "react-dom": "16.4.1", "react-hot-loader": "3.1.1", "react-jhipster": "0.5.3", "react-loadable": "5.4.0", "react-redux": "5.0.7", "react-redux-loading-bar": "4.0.5", "react-router-dom": "4.3.1", "react-stomp": "3.3.0", "react-talk": "1.0.0", "react-toastify": "4.1.0", "react-transition-group": "2.4.0", "reactstrap": "6.2.0", "redux": "4.0.0", "redux-devtools": "3.4.1", "redux-devtools-dock-monitor": "1.1.3", "redux-devtools-log-monitor": "1.4.0", "redux-promise-middleware": "5.1.1", "redux-thunk": "2.3.0", "tslib": "1.9.3", "uuid": "3.3.2" }, "devDependencies": { "@types/jest": "23.1.3", "@types/lodash": "4.14.110", "@types/node": "10.5.1", "@types/react": "16.4.6", "@types/react-dom": "16.0.6", "@types/react-redux": "6.0.3", "@types/react-router-dom": "4.2.7", "@types/redux": "3.6.31", "@types/webpack-env": "1.13.6", "browser-sync": "2.24.5", "browser-sync-webpack-plugin": "2.2.2", "cache-loader": "1.2.2", "copy-webpack-plugin": "4.5.2", "core-js": "2.5.7", "cross-env": "5.2.0", "css-loader": "0.28.11", "enzyme": "3.3.0", "enzyme-adapter-react-16": "1.1.1", "file-loader": "1.1.11", "fork-ts-checker-webpack-plugin": "0.4.2", "friendly-errors-webpack-plugin": "1.7.0", "generator-jhipster": "5.0.2", "html-webpack-plugin": "3.2.0", "http-proxy-middleware": "0.18.0", "husky": "0.14.3", "identity-obj-proxy": "3.0.0", "image-webpack-loader": "4.3.1", "jest": "23.2.0", "jest-sonar-reporter": "2.0.0", "json-loader": "0.5.7", "lint-staged": "7.2.0", "mini-css-extract-plugin": "0.4.1", "moment-locales-webpack-plugin": "1.0.7", "optimize-css-assets-webpack-plugin": "4.0.3", "prettier": "1.13.7", "react-infinite-scroller": "1.2.0", "redux-mock-store": "1.5.3", "rimraf": "2.6.2", "simple-progress-webpack-plugin": "1.1.2", "sinon": "6.0.1", "source-map-loader": "0.2.3", "sourcemap-istanbul-instrumenter-loader": "0.2.0", "stripcomment-loader": "0.1.0", "style-loader": "0.21.0", "swagger-ui": "2.2.10", "thread-loader": "1.1.5", "to-string-loader": "1.1.5", "ts-jest": "23.0.0", "ts-loader": "4.4.2", "tslint": "5.10.0", "tslint-config-prettier": "1.13.0", "tslint-eslint-rules": "5.3.1", "tslint-loader": "3.6.0", "tslint-react": "3.6.0", "typescript": "2.9.2", "uglifyjs-webpack-plugin": "1.2.7", "webpack": "4.14.0", "webpack-cli": "3.0.8", "webpack-dev-server": "3.1.4", "webpack-merge": "4.1.3", "webpack-notifier": "1.6.0", "workbox-webpack-plugin": "3.3.1", "write-file-webpack-plugin": "4.3.2" }, "resolutions": { "@types/react": "16.4.6" }, "engines": { "node": ">=8.9.0", "yarn": ">=1.3.2" }, "lint-staged": { "src//*.{ts,tsx,css,scss}": [ "prettier --write", "git add" ] }, "scripts": { "precommit": "lint-staged", "prettier:format": "yarn prettier --write 'src/*/.{ts,tsx,css,scss}'", "lint": "tslint --project tsconfig.json -e 'node_modules/'", "lint:fix": "yarn run lint --fix", "cleanup": "rimraf build/www", "start": "yarn run webpack:dev", "test": "yarn run lint && jest --coverage --logHeapUsage -w=2 --config src/test/javascript/jest.conf.js", "test:watch": "yarn test --watch", "webpack:dev": "yarn run webpack-dev-server --config webpack/webpack.dev.js --inline --port=9060 --env.stats=minimal", "webpack:dev-verbose": "yarn run webpack-dev-server --config webpack/webpack.dev.js --inline --port=9060 --profile --progress --env.stats=normal", "webpack:build:main": "yarn run webpack --config webpack/webpack.dev.js --env.stats=normal", "webpack:build": "yarn run cleanup && yarn run webpack:build:main", "webpack:prod:main": "yarn run webpack --config webpack/webpack.prod.js --profile", "webpack:prod": "yarn run cleanup && yarn run webpack:prod:main", "webpack:test": "yarn run test", "webpack-dev-server": "node --max_old_space_size=4096 node_modules/webpack-dev-server/bin/webpack-dev-server.js", "webpack": "node --max_old_space_size=4096 node_modules/webpack/bin/webpack.js" }, "jestSonar": { "reportPath": "build/test-results/jest", "reportFile": "TESTS-results.xml" } }

fil512 commented 6 years ago

I found the problem. I wasn't running the code I was changing.

yarn start runs on 9000 and gradle bootRun runs on 8080. Stomp needs to be on same port as gradle bootRun so I was testing on 8080 but that wasn't picking up my code changes as I saved them the way yarn start does.

Thanks again for the quick response and sorry for the false alarm.

lahsivjar commented 6 years ago

Great to know that