Advertisement
Guest User

Untitled

a guest
Nov 2nd, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. * Connects to a websocket server.
  2. * @param {string} url The url of the WS Server
  3. * @param {string} channel The channel to subscribe
  4. * @return {boolean} connection status
  5. */
  6. public connect(url: string, channel: string): boolean {
  7. console.group('WebSocketService: Welcome to the connect function.');
  8. console.log('Connects to', url);
  9. console.log('Channel is', channel);
  10. let _self = this;
  11. let socket = new SockJS(url);
  12.  
  13. _self.wsClient = Stomp.over(socket);
  14.  
  15. _self.wsClient.connect({}, function(frame) {
  16. _self.setConnected(true);
  17. console.log('Connected: ', frame);
  18. _self.wsClient.subscribe(channel, function(greeting) {
  19. console.log(greeting);
  20. _self.subjects[channel].next(greeting);
  21. });
  22. });
  23. console.groupEnd();
  24. return true;
  25. }
  26.  
  27. private test2(){
  28. let username : string = 'admin';
  29. let password : string = 'pass';
  30. let headers = new Headers();
  31. headers.append("Authorization", "Basic " + btoa(username + ":" + password));
  32. headers.append("Content-Type", "application/x-www-form-urlencoded");
  33. console.log('Test beginnt');
  34. return this._http.get('http://localhost:8080/gs-guide-websocket', {headers: headers}).map(res=> console.log(res))
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement