Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- * Connects to a websocket server.
- * @param {string} url The url of the WS Server
- * @param {string} channel The channel to subscribe
- * @return {boolean} connection status
- */
- public connect(url: string, channel: string): boolean {
- console.group('WebSocketService: Welcome to the connect function.');
- console.log('Connects to', url);
- console.log('Channel is', channel);
- let _self = this;
- let socket = new SockJS(url);
- _self.wsClient = Stomp.over(socket);
- _self.wsClient.connect({}, function(frame) {
- _self.setConnected(true);
- console.log('Connected: ', frame);
- _self.wsClient.subscribe(channel, function(greeting) {
- console.log(greeting);
- _self.subjects[channel].next(greeting);
- });
- });
- console.groupEnd();
- return true;
- }
- private test2(){
- let username : string = 'admin';
- let password : string = 'pass';
- let headers = new Headers();
- headers.append("Authorization", "Basic " + btoa(username + ":" + password));
- headers.append("Content-Type", "application/x-www-form-urlencoded");
- console.log('Test beginnt');
- return this._http.get('http://localhost:8080/gs-guide-websocket', {headers: headers}).map(res=> console.log(res))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement