Skip to content

Commit

Permalink
Merge pull request ReactiveX#2357 from Podlas29/web-socket-binary-type
Browse files Browse the repository at this point in the history
feat(webSocket): Add binaryType to config object
  • Loading branch information
jayphelps authored Feb 14, 2017
2 parents 7b38d19 + 86acbd1 commit e8f8153
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
15 changes: 15 additions & 0 deletions spec/observables/dom/webSocket-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,20 @@ describe('Observable.webSocket', () => {
subject.unsubscribe();
});

it('should take a binaryType and set it properly on the web socket', () => {
const subject = Observable.webSocket({
url: 'ws://mysocket',
binaryType: 'blob'
});

subject.subscribe();

const socket = MockWebSocket.lastSocket;
expect(socket.binaryType).to.equal('blob');

subject.unsubscribe();
});

it('should take a resultSelector', () => {
const results = [];

Expand Down Expand Up @@ -632,6 +646,7 @@ class MockWebSocket {
readyState: number = 0;
closeCode: any;
closeReason: any;
binaryType?: string;

constructor(public url: string, public protocol: string) {
MockWebSocket.sockets.push(this);
Expand Down
5 changes: 5 additions & 0 deletions src/observable/dom/WebSocketSubject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface WebSocketSubjectConfig {
closeObserver?: NextObserver<CloseEvent>;
closingObserver?: NextObserver<void>;
WebSocketCtor?: { new(url: string, protocol?: string|Array<string>): WebSocket };
binaryType?: 'blob' | 'arraybuffer';
}

/**
Expand All @@ -34,6 +35,7 @@ export class WebSocketSubject<T> extends AnonymousSubject<T> {
closeObserver: NextObserver<CloseEvent>;
closingObserver: NextObserver<void>;
WebSocketCtor: { new(url: string, protocol?: string|Array<string>): WebSocket };
binaryType?: 'blob' | 'arraybuffer';

private _output: Subject<T>;

Expand Down Expand Up @@ -159,6 +161,9 @@ export class WebSocketSubject<T> extends AnonymousSubject<T> {
new WebSocketCtor(this.url, this.protocol) :
new WebSocketCtor(this.url);
this.socket = socket;
if (this.binaryType) {
this.socket.binaryType = this.binaryType;
}
} catch (e) {
observer.error(e);
return;
Expand Down

0 comments on commit e8f8153

Please sign in to comment.