當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Subscriber.create方法代碼示例

本文整理匯總了TypeScript中rxjs/Subscriber.Subscriber.create方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Subscriber.create方法的具體用法?TypeScript Subscriber.create怎麽用?TypeScript Subscriber.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rxjs/Subscriber.Subscriber的用法示例。


在下文中一共展示了Subscriber.create方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: watchProduct

  watchProduct(productId: number): Observable<any> {
    let openSubscriber = Subscriber.create(
      () => this.webSocket.send({productId: productId}));

    return this.webSocket.createObservableSocket('ws://localhost:8000', openSubscriber)
      .map(message => JSON.parse(message));
  }
開發者ID:JavaPantry,項目名稱:MockStoreApp,代碼行數:7,代碼來源:bid-service.ts

示例2: constructor

    constructor (url: string, protocol: string, openObserver?: Observer<Event>, closingObserver?: Observer<CloseEvent>) {
	    super();

	    this.url = url;
	    this.openObserver = openObserver;
	    this.closingObserver = closingObserver;
	    if (!WebSocket) { throw new TypeError('WebSocket not implemented in your runtime.'); }
	    this.websocket = new WebSocket(url);
	    var that = this;
	    var superNext = super.next;
	    var superError = super.error;
	    var superComplete = super.complete;

	    this.websocket.onopen = function (event) {
	        openObserver.next(event);
	        that.websocket.send("aaaa");
	    };
	    this.websocket.onclose = function (event) {
	        closingObserver.next(event);
	    };
	    this.websocket.onmessage = function (event) {
	    	try {
	            superNext.call(that, event.data);
	        } catch (e) {
	        	var errorEvent :ErrorEvent = new ErrorEvent(e);
	        	errorEvent.message = "Invalid event structure.";
	        	errorEvent.error = e;
	        	superError.call(that, errorEvent);
	        }
	    };
	    this.websocket.onerror = function (event) {
	        superError.call(that, event);
	    };
	    
	    this.destination = Subscriber.create(
	    	(message: string) => {
	    		this.websocket.send(message);
	    	},
	        (error: any) => {
	            console.log("WebSocket error: " + error);
	            this.websocket.close(1011, "Error processing client data stream.");
	            var errorEvent :ErrorEvent = new ErrorEvent(error);
	        	errorEvent.message = "Error processing client data stream.";
	        	errorEvent.error = error;
	        	superError.call(that, errorEvent);
	        }, //CloseEvent.code = Internal Error
	        () => {
	        	console.log("WebSocket closing"); 
	        	this.websocket.close(1011, "Error processing client data stream.");
	        	var closeEvent :CloseEvent = new CloseEvent();
	        	closeEvent.code = 1000; //CLOSE_NORMAL
	        	closeEvent.reason = "WS connection closed by client.";
	        	closeEvent.wasClean = true;
	        	this.closingObserver.next(closeEvent);
	        }
	    );
	}
開發者ID:kodido,項目名稱:low-latency-high-throughput,代碼行數:57,代碼來源:ipt_rx_websocket.ts

示例3: constructor

  constructor(url: string, protocol: string,
              openObserver?: Observer<Event>,
              closingObserver?: Observer<WebsocketCloseEvent>) {
    super();

    this.url = url;
    this.openObserver = openObserver;
    this.closingObserver = closingObserver;

    if (!WebSocket) { throw new TypeError('WebSocket not implemented in your runtime.'); }
    this.websocket = new WebSocket(this.url);

    this.websocket.onopen = (event) => {
      this.openObserver.next(event);
      this.openObserver.complete();
    };
    this.websocket.onclose = (event) => {
      this.closingObserver.next(event);
      this.closingObserver.complete();
    };
    this.websocket.onmessage =
      (event) => {
        try {
          super.next(event.data);
        } catch (e) {
          super.error(e);
        }
      };
    this.websocket.onerror = (event) => {
      super.error(event);
    };

    this.serverDestination = Subscriber.create(
      (message: string) => {
        this.websocket.send(message);
      },
      (error: any) => {
        console.log('WebSocket error: ', error);
        this.websocket.close(4011, 'Error processing client data stream.');
        let errorEvent: WebsocketErrorEvent = new WebsocketErrorEvent();
        errorEvent.message = 'Error processing client data stream.';
        errorEvent.error = error;
        super.error(errorEvent);
      },
      () => {
        console.log('WebSocket closing');
        this.websocket.close(1000, 'WS connection closed by client.');
        let closeEvent: WebsocketCloseEvent = new WebsocketCloseEvent();
        closeEvent.code = 1000; // CLOSE_NORMAL
        closeEvent.reason = 'WS connection closed by client.';
        closeEvent.wasClean = true;
        this.closingObserver.next(closeEvent);
        this.closingObserver.complete();
      }
    );
  }
開發者ID:iproduct,項目名稱:jprime-demo,代碼行數:56,代碼來源:iptpi-websocket-subject.ts

示例4: constructor

 constructor() {
   super('ws://' + window.location.host + '/ws', null,
     Subscriber.create(event => console.log('socket open')),
     Subscriber.create(event => console.log('socket is about to close'))
   );
 }
開發者ID:iproduct,項目名稱:jprime-demo,代碼行數:6,代碼來源:iptpi-websocket.service.ts


注:本文中的rxjs/Subscriber.Subscriber.create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。