Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WebSocketSubject.d.ts 3.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { Subject, AnonymousSubject } from '../../Subject';
  2. import { Subscriber } from '../../Subscriber';
  3. import { Observable } from '../../Observable';
  4. import { Subscription } from '../../Subscription';
  5. import { Operator } from '../../Operator';
  6. import { Observer, NextObserver } from '../../types';
  7. export interface WebSocketSubjectConfig<T> {
  8. /** The url of the socket server to connect to */
  9. url: string;
  10. /** The protocol to use to connect */
  11. protocol?: string | Array<string>;
  12. /** @deprecated use {@link deserializer} */
  13. resultSelector?: (e: MessageEvent) => T;
  14. /**
  15. * A serializer used to create messages from passed values before the
  16. * messages are sent to the server. Defaults to JSON.stringify.
  17. */
  18. serializer?: (value: T) => WebSocketMessage;
  19. /**
  20. * A deserializer used for messages arriving on the socket from the
  21. * server. Defaults to JSON.parse.
  22. */
  23. deserializer?: (e: MessageEvent) => T;
  24. /**
  25. * An Observer that watches when open events occur on the underlying web socket.
  26. */
  27. openObserver?: NextObserver<Event>;
  28. /**
  29. * An Observer than watches when close events occur on the underlying webSocket
  30. */
  31. closeObserver?: NextObserver<CloseEvent>;
  32. /**
  33. * An Observer that watches when a close is about to occur due to
  34. * unsubscription.
  35. */
  36. closingObserver?: NextObserver<void>;
  37. /**
  38. * A WebSocket constructor to use. This is useful for situations like using a
  39. * WebSocket impl in Node (WebSocket is a DOM API), or for mocking a WebSocket
  40. * for testing purposes
  41. */
  42. WebSocketCtor?: {
  43. new (url: string, protocols?: string | string[]): WebSocket;
  44. };
  45. /** Sets the `binaryType` property of the underlying WebSocket. */
  46. binaryType?: 'blob' | 'arraybuffer';
  47. }
  48. export declare type WebSocketMessage = string | ArrayBuffer | Blob | ArrayBufferView;
  49. /**
  50. * We need this JSDoc comment for affecting ESDoc.
  51. * @extends {Ignored}
  52. * @hide true
  53. */
  54. export declare class WebSocketSubject<T> extends AnonymousSubject<T> {
  55. private _config;
  56. /** @deprecated This is an internal implementation detail, do not use. */
  57. _output: Subject<T>;
  58. private _socket;
  59. constructor(urlConfigOrSource: string | WebSocketSubjectConfig<T> | Observable<T>, destination?: Observer<T>);
  60. lift<R>(operator: Operator<T, R>): WebSocketSubject<R>;
  61. private _resetState;
  62. /**
  63. * Creates an {@link Observable}, that when subscribed to, sends a message,
  64. * defined by the `subMsg` function, to the server over the socket to begin a
  65. * subscription to data over that socket. Once data arrives, the
  66. * `messageFilter` argument will be used to select the appropriate data for
  67. * the resulting Observable. When teardown occurs, either due to
  68. * unsubscription, completion or error, a message defined by the `unsubMsg`
  69. * argument will be send to the server over the WebSocketSubject.
  70. *
  71. * @param subMsg A function to generate the subscription message to be sent to
  72. * the server. This will still be processed by the serializer in the
  73. * WebSocketSubject's config. (Which defaults to JSON serialization)
  74. * @param unsubMsg A function to generate the unsubscription message to be
  75. * sent to the server at teardown. This will still be processed by the
  76. * serializer in the WebSocketSubject's config.
  77. * @param messageFilter A predicate for selecting the appropriate messages
  78. * from the server for the output stream.
  79. */
  80. multiplex(subMsg: () => any, unsubMsg: () => any, messageFilter: (value: T) => boolean): Observable<any>;
  81. private _connectSocket;
  82. /** @deprecated This is an internal implementation detail, do not use. */
  83. _subscribe(subscriber: Subscriber<T>): Subscription;
  84. unsubscribe(): void;
  85. }