-
Notifications
You must be signed in to change notification settings - Fork 32
Workaound: ng2-stompjs over SockJS in Angular 6 #70
Comments
Please see: https://stomp-js.github.io/ng2-stompjs/additional-documentation/sock-js.html A sample at: https://github.com/stomp-js/ng4-stompjs-demo/tree/sockjs (branch sockjs) |
Thank you very much. |
Has this been confirmed to work with Angular 6? When following the documentation example I get a runtime error whilst connecting to the SockJS endpoint:
|
The Angular 6 version of this library has only been released yesterday, so, I am doubtful if anyone has used in production at all. I can be reasonably sure that no one would have used it with SockJS and Angular 6 by now 😄 Before I dig deeper, are you using 6.0.0 of this library (released yesterday)? |
Yes, I am! I am trying to use it for a prototype application where I have no control over how the backend works, but it seems it's not functioning with Angular 6 sadly. If it's too much work I'll just downgrade to Angular 5, but it'd be nice to use all the new features from 6 while building something new. |
I can confirm that I am able to reproduce the issue. It seems to be reported here: sockjs/sockjs-client#401 Not sure it would be an easy solution till the underlying thing gets fixed. @wsloth if your underlying broker supports Websockets (which in all likelihood it should), you can use that instead of going through the SockJS emulation layer. Any particular reason you need SockJS? |
I see, it doesn't seem like an easy fix. I'm working on something of a code exercise where I have full control over the frontend, but none over the backend, so that is a bit of a shame. I'll see if I can downgrade to Angular 5, or for the sake of making something beautiful ditch the SockJS protocol. |
Just curious what advantage are you getting with SockJS in comparison to standard WebSocket? |
Nothing really, it's just that the backend has already been made and SockJS was decided for the messaging protocol. If it were up to me, I'd be using standard WebSockets 😉 |
I am always getting surprised people choosing SockJS instead of WebSockets which would internally use WebSockets anyway. Using SockJS does limit some of the functionality of this library as well. So far most number of tickets on this project relate to SockJS issues 😄 |
I can confirm that ng2-stompjs over SockJS is working with Angular 6. |
Not sure if that would work - in your index.html file, in the header try adding the following: <script type="application/javascript">
var global = window;
</script> I am unable to test it myself though |
@srjovanovic your issue may be linked to something else. Will you be able to share a sample repository that shows StompJS working with Angular6 and also your issue. |
@kum-deepak I've made more test with Angular 5, and I can confirm that my issue has nothing with Angular 6. |
After upgrade angular and ng2-stompjs I have the same error:
And following your link https://stomp-js.github.io/ng2-stompjs/additional-documentation/sock-js.html |
@srjovanovic Can you show me an example of stompjs working with angular 6? or maybe your code? |
@lippomano Service: @Injectable()
}` |
Relevant package versions: |
@srjovanovic I have a configuration like you but if I use P.s. If I use for example an url like |
As you can see from my code, I'm using newSockJS(serverUrl), for dev env I use serverUrl=https://localhost:9000/ |
@srjovanovic @kum-deepak just tried with the example in angular 6 ng6-example and I follow this way with sockJS And I still have the same error, I can't understand how you don't have error |
It is definitely not working for me 😃. Copying from my earlier comments: The underlying issue is in SockJS and the way Angular 6 is trying to bundle the code. It is reported here: sockjs/sockjs-client#401. Not sure it would be an easy solution till the underlying thing gets fixed. Not sure if it would work. In your index.html file, in the header try adding the following: <script type="application/javascript">
var global = window;
</script> Be warned 😄, test your application, this may have unintended side effects. A better solution, if you can, switch to standard Websockets. |
@kum-deepak thanks for your feedback, what type of side effects? |
Generally Now the risk part, |
It's working, but I have to test it more accurately. |
Getting the below error in browser after updating to angular 6 @kum-deepak thanks for your feedback, It does the workaround for me. Is there anything with the compatible dependency for angular 6 to fix it ? |
@satyendra-123 unfortunately the issue can only be fixed either by Angular team or by SockJS team. |
I fixed it for with adding this line:
to angular-clis |
@kum-deepak Your workaround-fix works for me for raw SockJS connection: <script type="application/javascript"> var global = window; </script>I will next try using the stomp protocol over it, and will update you soon. FYI:
/ △ \ | '_ \ / Angular CLI: 6.0.7 Package Version@angular-devkit/architect 0.6.7 [vagrant@london-node-230 ~]$ |
@kum-deepak Your workaround-fix works. <script type="application/javascript"> var global = window; </script> |
Typically the CONNECTED frame (in response to CONNECT frame from the client) from broker returns a Which broker are you using? This is not an error, this value is not used other than reporting it in log. It should not impact your usage. |
@kum-deepak Is there any way now to convert the protocol to http instead of wss. I am getting "global is not defined" |
If the URL supported by your broker starts with You can not interchange If the broker only supports http, then follow #70 (comment) as a workaround for "global is not defined" |
Getting the below error in browser in angular 9 @kum-deepak seems like still the error is not fixed by angular or sockJS team , is there any better solution without using this (window as any).global = window; |
@goldy12103, this is not fixable by the Angular team. It would need fixing by the SockJS team. |
Is there any better solution without using this (window as any).global = window; ??? |
Please scan this thread. There are other solutions, however, all of those lead to the same thing. |
Thanks Anyway !! |
Based on your setup, you might get error similar to following:
The actual issue can be solved by SockJs team, see: #70 (comment).
Please see #70 (comment) and #70 (comment) for possible workarounds.
The text was updated successfully, but these errors were encountered: