rxjs-websockets
Advanced tools
Comparing version 6.0.4 to 7.0.0-alpha.1
import { Observable } from 'rxjs'; | ||
export interface Connection { | ||
declare type WebSocketPayload = string | ArrayBuffer | Blob; | ||
export interface Connection<T extends WebSocketPayload = WebSocketPayload> { | ||
connectionStatus: Observable<number>; | ||
messages: Observable<string>; | ||
messages: Observable<T>; | ||
} | ||
export interface IWebSocket { | ||
close(): any; | ||
send(data: string | ArrayBuffer | Blob): any; | ||
send(data: WebSocketPayload): any; | ||
onopen: ((event: any) => any) | null; | ||
@@ -15,2 +16,3 @@ onclose: ((event: any) => any) | null; | ||
export declare type WebSocketFactory = (url: string, protocols?: string | string[]) => IWebSocket; | ||
export default function connect(url: string, input: Observable<string>, protocols?: string | string[], websocketFactory?: WebSocketFactory): Connection; | ||
export default function connect<T extends WebSocketPayload = WebSocketPayload>(url: string, input: Observable<WebSocketPayload>, protocols?: string | string[], websocketFactory?: WebSocketFactory): Connection<T>; | ||
export {}; |
{ | ||
"name": "rxjs-websockets", | ||
"version": "6.0.4", | ||
"version": "7.0.0-alpha.1", | ||
"description": "rxjs 5 websockets library, ideal for use with angular 2", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
import { Observable, Subscription, BehaviorSubject } from 'rxjs' | ||
export interface Connection { | ||
connectionStatus: Observable<number> | ||
messages: Observable<string> | ||
} | ||
interface EventWithReason { | ||
@@ -12,8 +7,2 @@ reason: string | ||
interface EventWithData { | ||
// TODO: should be | ||
// data: string | ArrayBuffer | Blob; | ||
data: string | ||
} | ||
interface EventWithMessage { | ||
@@ -23,5 +12,12 @@ message?: string | ||
type WebSocketPayload = string | ArrayBuffer | Blob | ||
export interface Connection<T extends WebSocketPayload = WebSocketPayload> { | ||
connectionStatus: Observable<number>, | ||
messages: Observable<T>, | ||
} | ||
export interface IWebSocket { | ||
close(): any | ||
send(data: string | ArrayBuffer | Blob): any | ||
send(data: WebSocketPayload): any | ||
@@ -43,11 +39,11 @@ // TypeScript doesn't seem to apply function bivariance on each property when | ||
export default function connect( | ||
export default function connect<T extends WebSocketPayload = WebSocketPayload>( | ||
url: string, | ||
input: Observable<string>, | ||
input: Observable<WebSocketPayload>, | ||
protocols: string | string[] = defaultProtocols, | ||
websocketFactory: WebSocketFactory = defaultWebsocketFactory, | ||
): Connection { | ||
): Connection<T> { | ||
const connectionStatus = new BehaviorSubject<number>(0) | ||
const messages = new Observable<string>(observer => { | ||
const messages = new Observable<T>(observer => { | ||
const socket = websocketFactory(url, protocols) | ||
@@ -75,3 +71,3 @@ let inputSubscription: Subscription | ||
socket.onmessage = (message: EventWithData) => { | ||
socket.onmessage = (message: { data: T }) => { | ||
observer.next(message.data) | ||
@@ -78,0 +74,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24967
14
134
319
2