【问题标题】:Group Chat with Signalr. How to send to specific users?与 Signalr 群聊。如何发送给特定用户?
【发布时间】:2016-09-27 12:48:27
【问题描述】:

这些是我在数据库中添加的表。

Database table 1

Database table 2

    //Group Chat Hub
    public void GroupChatSend(string name, string message)
    {
        //AddMessageinCacheWallChat(name, message);
        Clients.All.addNewMessageToGroupPage(name, message);
    }

与 // JavaScript

var GroupChat = function () {
    // Reference the auto-generated proxy for the hub.  
    var chat = $.connection.chatHub;

    // Create a function that the hub can call back to display messages.
    chat.client.addNewMessageToGroupPage = function (name, message) {
        // Add the message to the page. 
        $('#discussionGroupChat').append('<li><strong>' + htmlEncode(name)
            + '</strong>: ' + htmlEncode(message) + '</li>');
    };
    // Set initial focus to message input box.  
    $('#messageGroupChat').focus();
    // Start the connection.
    $.connection.hub.start().done(function () {
        var name = $('#userName').val();
        chat.server.connectWallChat(name);
        $('#sendmessageGroupChat').click(function () {
            // Call the Send method on the hub. 
            chat.server.groupChatSend(name, $('#messageGroupChat').val());
            // Clear text box and reset focus for next comment. 
            $('#messageGroupChat').val('').focus();
        });
    });
    // This optional function html-encodes messages for display in the page.
    function htmlEncode(value) {
        var encodedValue = $('<div />').text(value).html();
        return encodedValue;

    }

}

我怎样才能只向群组发送消息。还有带有 id、用户名等的成员表。我没有使用owin

【问题讨论】:

    标签: .net model-view-controller signalr


    【解决方案1】:

    Clients.Group(groupName).[应在该组上调用的方法](name, message);

    http://www.asp.net/signalr/overview/guide-to-the-api/working-with-groups

    【讨论】:

      猜你喜欢
      • 2015-05-14
      • 1970-01-01
      • 2020-02-26
      • 2015-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多