Skip to content
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

Stomp object in stomp.service.ts (Line 84) is empty #1

Closed
cmhampton1021 opened this issue May 13, 2016 · 3 comments
Closed

Stomp object in stomp.service.ts (Line 84) is empty #1

cmhampton1021 opened this issue May 13, 2016 · 3 comments
Assignees

Comments

@cmhampton1021
Copy link

Hello,

I am trying to implement this library, and when I try to create the client object, nothing happens.

this.client = Stomp.client( scheme + '://' + this.config.host + ':' + this.config.port + '/stomp/websocket' );

I see that 'Stomp' is declared on line 10, but it does not get assigned a value that I can see. I'm sure I'm missing something silly.

Thanks

@sjmf sjmf self-assigned this May 13, 2016
@sjmf
Copy link
Owner

sjmf commented May 13, 2016

Hi,
The Stomp object gets pulled into the global namespace in index.html, from the javascript library pulled in from npm. The declaration on line 10 of stomp.service.ts doesn't do much more than stop the typescript compiler complaining about the missing definition, so that the STOMP service can go ahead and use it.

It's a little while since I wrote that code, so looking back at it I'm wondering why I didn't just import it from modules/stompjs.d.ts where it does get defined and exported- that might be clearer? i.e. on line 9 have:

import { Client, Message, Stomp } from 'stompjs';

I'll see if that works in the morning, if you don't get to it before me :)

@sjmf sjmf closed this as completed in 0e511d2 May 14, 2016
@sjmf
Copy link
Owner

sjmf commented May 14, 2016

@cmhampton1021 I took a look- thanks for the heads up! Does this fix the problem you were having?

Without the definition on L10 at all, we get an error from the typescript compiler:

app/services/stomp.service.ts(83,23): error TS2304: Cannot find name 'Stomp'.

Moving it into the import from 'stompjs' confuses SystemJS, which attempts to load the module from http://localhost:3000/stompjs and gets back index.html...

"SyntaxError: expected expression, got '<'
    Evaluating http://localhost:3000/stompjs
    Error loading http://localhost:3000/dist/boot.js"

So that's probably why I defined it by hand. But, of course, that's the wrong way of doing it! The right way would be to add a SystemJS mapping in index.html and import it (as above) on line 9.

map: {
  stompjs: 'node_modules/stompjs/lib/stomp.min.js' 
}

I've pushed this change in commit 0e511d2. :)

@cmhampton1021
Copy link
Author

@sjmf That did the trick, thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants