当前位置: 首页>>代码示例>>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;未经允许,请勿转载。