11import { Injectable } from '@angular/core' ;
2- import { Observable } from 'rxjs/Observable' ;
3- import { Subject } from 'rxjs/Subject' ;
2+ import { Observable , Subject } from 'rxjs' ;
43
54export class $WebSocket {
65
@@ -43,17 +42,17 @@ export class $WebSocket {
4342 private errorMessages : Subject < any > ;
4443 private internalConnectionState : number ;
4544
46- constructor ( private url : string ,
47- private protocols ?: Array < string > ,
48- private config ?: WebSocketConfig ,
49- private binaryType ?: BinaryType )
45+ constructor ( private url : string ,
46+ private protocols ?: Array < string > ,
47+ private config ?: WebSocketConfig ,
48+ private binaryType ?: BinaryType )
5049 {
5150 let match = new RegExp ( 'wss?:\/\/' ) . test ( url ) ;
5251 if ( ! match ) {
5352 throw new Error ( 'Invalid url provided' ) ;
5453 }
5554 this . config = Object . assign ( { initialTimeout : 500 , maxTimeout : 300000 , reconnectIfNotNormalClose : false } , config ) ;
56- this . binaryType = binaryType || " blob" ;
55+ this . binaryType = binaryType || ' blob' ;
5756 this . dataStream = new Subject ( ) ;
5857 this . errorMessages = new Subject ( ) ;
5958 this . connect ( true ) ;
@@ -64,7 +63,7 @@ export class $WebSocket {
6463 let self = this ;
6564 if ( force || ! this . socket || this . socket . readyState !== this . readyStateConstants . OPEN ) {
6665 self . socket = this . protocols ? new WebSocket ( this . url , this . protocols ) : new WebSocket ( this . url ) ;
67- self . socket . binaryType = self . binaryType . toString ( ) ;
66+ self . socket . binaryType = self . binaryType ;
6867
6968 self . socket . onopen = ( ev : Event ) => {
7069 // console.log('onOpen: ', ev);
@@ -169,15 +168,15 @@ export class $WebSocket {
169168 * @returns {any }
170169 */
171170 send ( data : any , mode ?: WebSocketSendMode , binary ?: boolean ) : any {
172- switch ( typeof mode !== " undefined" ? mode : this . send4Mode ) {
171+ switch ( typeof mode !== ' undefined' ? mode : this . send4Mode ) {
173172 case WebSocketSendMode . Direct :
174173 return this . send4Direct ( data , binary ) ;
175174 case WebSocketSendMode . Promise :
176175 return this . send4Promise ( data , binary ) ;
177176 case WebSocketSendMode . Observable :
178177 return this . send4Observable ( data , binary ) ;
179178 default :
180- throw Error ( " WebSocketSendMode Error." ) ;
179+ throw Error ( ' WebSocketSendMode Error.' ) ;
181180 }
182181 }
183182
0 commit comments