Angular:RxStomp Watch、Configure、Activateメソッド

Nov 20 2020

Stompでは、次の方法を使用しました。

initUserEvents() {

this.stompService.startConnect().then(() => {
      this.stompService.done('init');

this.stompService.subsribe('/channel/login', res => {
      if (res.username !== this.username) {

        this.newConnectedAccounts.push(res.username);

現在、私はRxStompを使用していますが、これらの「置換」方法を使用する正しい方法を理解できません。

initUserEvents() {

this.stompService.configure();
    this.stompService.activate(){

    this.stompService.watch('/channel/login', res => {
      if (res.username !== this.username) {
        this.newConnectedAccounts.push(res.username);

私が得ているエラーは次のとおりです:TS2345:タイプ '(res:any)=> void'の引数はタイプ 'StompHeaders'のパラメーターに割り当てることができません。タイプ '(res:any)=> void'にインデックス署名がありません。

回答

JustinBertram Nov 20 2020 at 14:59

RxStompのドキュメントをご覧ください。それは言う:

主な違いは、操作をRxJSObservablesとして公開することです。たとえば、STOMPエンドポイントがサブスクライブされると、受信したすべてのメッセージをストリーミングするObservableが返されます。

beforeConnectを除いて、@ stomp / stompjsクライアントのすべてのコールバックに関連する機能はObservables / Subjects / BehaviorSubjectsとして公開されます。

つまり、watchメソッドにコールバックを渡さないということです。Observableメッセージの取得に使用できるを返します。

RxStomp APIはwatch、コールバックではなく、メソッドにヘッダーを渡すことを想定しています。それが具体的にあなたに言っている理由です:

TS2345: Argument of type '(res: any) => void' is not assignable to parameter of type 'StompHeaders'.