How to use the @microsoft/signalr.HttpTransportType function in @microsoft/signalr

To help you get started, we’ve selected a few @microsoft/signalr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AndriySvyryd / UnicornHack / src / UnicornHack.Web / ClientApp / src / components / Game.tsx View on Github external
constructor(props: IGameProps) {
        super(props);

        const location = document.location || new Location();
        const connection = new signalR.HubConnectionBuilder()
            .withUrl(`${location.origin}/gameHub`,
                { transport: signalR.HttpTransportType.WebSockets, skipNegotiation: true })
            .configureLogging(signalR.LogLevel.Information)
            .withAutomaticReconnect()
            .withHubProtocol(new MessagePackHubProtocol())
            .build();

        connection.onclose = e => {
            if (e) {
              this.addError(`Connection closed with error: "${(e || '')}"`);
            } else {
                this.addMessage(MessageType.Info, 'Disconnected');
            }
        };

        connection.onreconnecting((e) => {
          this.addMessage(MessageType.Info, `Connection lost ("${e}"). Reconnecting.`);
        });