Get started with microsoft-signalr CDN

Apache-2.0 licensed

Microsoft SignalR is a library for real-time, bidirectional communication between server and client applications.

Tags:
  • signalr
  • websocket

Stable version

Copied!

How to start using microsoft-signalr CDN


<!DOCTYPE html>
<html>
<head>
    <title>Get started with microsoft-signalr CDN - cdnhub.io</title>
    <script src="https://cdn.jsdelivr.net/npm/@aspnet/signalr@8.0.0/dist/signalr.min.js"></script>
    <script>
        const connection = new signalR.HubConnectionBuilder()
            .withUrl("/signalr")
            .build();

        connection.on("ReceiveMessage", (message) => {
            const messagesList = document.getElementById("messagesList");
            messagesList.innerHTML += `<li>${message}</li>`;
        });

        connection.start().catch((err) => {
            return console.error(err.toString());
        });

        function sendMessage(message) {
            connection.invoke("SendMessage", message).catch((err) => {
                return console.error(err.toString());
            });
        }

        document.getElementById("sendButton").addEventListener("click", () => {
            const user = document.getElementById("user").value;
            const message = document.getElementById("message").value;
            sendMessage(`${user}: ${message}`);
            document.getElementById("message").value = "";
        });
    </script>
</head>
<body>
    <div>
        <input id="user" type="text" placeholder="Your name" />
        <input id="message" type="text" placeholder="Type a message and press Enter" />
        <button id="sendButton">Send</button>
    </div>
    <ul id="messagesList"></ul>
    <script src="https://cdn.cdnhub.io/microsoft-signalr/8.0.0/signalr.min.js"></script>
</body>
</html>
Copied!
Copied!

All versions

3.0.0 3.0.0-preview9.19424.4 3.0.0-rc1.19457.4 3.0.1 3.0.3 3.1.0 3.1.0-preview1.19508.20 3.1.0-preview2.19528.8 3.1.0-preview3.19555.2 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.20 3.1.21 3.1.22 3.1.23 3.1.24 3.1.25 3.1.26 3.1.27 3.1.28 3.1.29 3.1.3 3.1.30 3.1.31 3.1.6 3.1.7 3.1.8 3.1.9 5.0.0 5.0.0-preview.1.20124.5 5.0.0-preview.2.20167.3 5.0.0-preview.3.20215.14 5.0.0-preview.4.20257.10 5.0.0-preview.5.20279.2 5.0.0-preview.6.20312.15 5.0.0-preview.7.20365.19 5.0.0-preview.8.20414.8 5.0.0-rc.1.20451.17 5.0.0-rc.2.20475.17 5.0.1 5.0.10 5.0.11 5.0.12 5.0.13 5.0.14 5.0.15 5.0.16 5.0.17 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.0.9 6.0.0 6.0.0-preview.1.21103.6 6.0.0-preview.2.21154.6 6.0.0-preview.3.21201.13 6.0.0-preview.4.21253.5 6.0.0-preview.5.21301.17 6.0.0-preview.6.21355.2 6.0.0-preview.7.21378.6 6.0.0-rc.1.21452.15 6.0.0-rc.2.21480.10 6.0.1 6.0.10 6.0.11 6.0.13 6.0.14 6.0.15 6.0.16 6.0.18 6.0.2 6.0.20 6.0.21 6.0.22 6.0.23 6.0.25 6.0.3 6.0.4 6.0.5 6.0.6 6.0.7 6.0.8 6.0.9 7.0.0 7.0.0-preview.1.22109.13 7.0.0-preview.2.22153.2 7.0.0-preview.3.22178.4 7.0.0-preview.4.22251.1 7.0.0-preview.5.22303.8 7.0.0-preview.6.22330.3 7.0.0-preview.7.22376.6 7.0.0-rc.1.22427.2 7.0.0-rc.2.22476.2 7.0.10 7.0.11 7.0.12 7.0.14 7.0.2 7.0.3 7.0.4 7.0.5 7.0.7 7.0.9 *** 8.0.0 8.0.0-preview.1.23112.2 8.0.0-preview.2.23153.2 8.0.0-preview.3.23177.8 8.0.0-preview.4.23260.4 8.0.0-preview.5.23302.2 8.0.0-preview.6.23329.11 8.0.0-preview.7.23375.9 8.0.0-rc.1.23421.29 8.0.0-rc.2.23480.2