次の方法で共有


WebPubSubEventHandler class

受信 CloudEvents メッセージを処理するハンドラー

コンストラクター

WebPubSubEventHandler(string, WebPubSubEventHandlerOptions)

受信 CloudEvents メッセージを処理するための WebPubSubEventHandler のインスタンスを作成します。

使用例:

import { WebPubSubEventHandler } from "@azure/web-pubsub-express";

const endpoint = "https://xxxx.webpubsubdev.azure.com";
const handler = new WebPubSubEventHandler("chat", {
  handleConnect: (req, res) => {
    console.log(JSON.stringify(req));
    return {};
  },
  onConnected: (req) => {
    console.log(JSON.stringify(req));
  },
  handleUserEvent: (req, res) => {
    console.log(JSON.stringify(req));
    res.success("Hey " + req.data, req.dataType);
  },
  allowedEndpoints: [endpoint],
});

プロパティ

path

CloudEvents ハンドラーがリッスンするパス

メソッド

getMiddleware()

CloudEvents 要求を処理するミドルウェアを取得する

コンストラクターの詳細

WebPubSubEventHandler(string, WebPubSubEventHandlerOptions)

受信 CloudEvents メッセージを処理するための WebPubSubEventHandler のインスタンスを作成します。

使用例:

import { WebPubSubEventHandler } from "@azure/web-pubsub-express";

const endpoint = "https://xxxx.webpubsubdev.azure.com";
const handler = new WebPubSubEventHandler("chat", {
  handleConnect: (req, res) => {
    console.log(JSON.stringify(req));
    return {};
  },
  onConnected: (req) => {
    console.log(JSON.stringify(req));
  },
  handleUserEvent: (req, res) => {
    console.log(JSON.stringify(req));
    res.success("Hey " + req.data, req.dataType);
  },
  allowedEndpoints: [endpoint],
});
new WebPubSubEventHandler(hub: string, options?: WebPubSubEventHandlerOptions)

パラメーター

hub

string

リッスンするハブの名前

options
WebPubSubEventHandlerOptions

イベント ハンドラーを構成するためのオプション

プロパティの詳細

path

CloudEvents ハンドラーがリッスンするパス

path: string

プロパティ値

string

メソッドの詳細

getMiddleware()

CloudEvents 要求を処理するミドルウェアを取得する

function getMiddleware(): RequestHandler

戻り値

RequestHandler