Is there a way to exclude a Client from a Clients.method call in SignalR?

混江龙づ霸主 提交于 2019-12-04 11:45:55

javascript code:

<script type="text/javascript">
    $(document).ready(function () {
        var test = $.connection.test;
        $("#btnTest").click(function () {
            test.testMethod();
        });
        test.show = function (text, guid) {
            if (guid != test.guid) //notify all clients except the caller
                alert(text);
        };
        $.connection.hub.start(function () { test.start(); });
    });
</script>

Class :

public class Test : Hub
{
    public void Start()
    {
        Caller.guid = Guid.NewGuid();
    }

    public void TestMethod()
    {
        Clients.show("test", Caller.guid);
    }
}

If you want to exclude the caller from the call to the client side method you can use:

Clients.Others.clientSideMethod();

There is also Clients.AllExcept(...) that allows excluding certain people.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!