Created
December 29, 2017 14:32
-
-
Save kpavlovsky/e1329e718f9ea22a5e883e7301a1c6a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public start(url: string): void { | |
console.log("connecting to " + url); | |
let self = this; | |
this.url = url; | |
this.ws = Observable.webSocket(this.url); | |
this.socket = this.ws.subscribe({ | |
next: (data: MessageEvent) => { | |
if (data['type'] == 'welcome') { | |
self.opened.next(true); | |
} | |
this.message.next(data); | |
}, | |
error: () => { | |
console.log('failed to connect'); | |
self.opened.next(false); | |
this.message.next({ type: 'closed' }); | |
self.socket.unsubscribe(); | |
// setTimeout( () => { | |
// self.start( self.url ); | |
// }, 1000 ); | |
}, | |
complete: () => { | |
console.log('Connection to server terminated'); | |
this.message.next({ type: 'closed' }); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment