客户端功能不会调用

问题描述 投票:0回答:1

升级signalR和.NET版本后,我遇到了很多困难。以前我有1.XX版本,现在我有2.4.0信号R版本。

这个问题与 - https://github.com/SignalR/SignalR/issues/4339直接相关

但升级后信号R不起作用。

现在的问题是客户端功能无法调用。

我刚试过这个:Signalr doesn't call client side functions

并根据正确的答案修复它:

在$ .connection.hub.start之前的init中调用_subscribe方法。

后来我对这个问题进行了更深入的研究,并在我的signalr.js下面添加了console.log

connection.socket.onmessage = function (event) {
    var data;

    try {
        console.log(event.data);
        data = connection._parseResponse(event.data);
    }
    catch (error) {
        transportLogic.handleParseFailure(connection, event.data, error, onFailed, event);
        console.log("socket error" + event.data);
        return;
    }

    if (data) {
        transportLogic.processMessages(connection, data, onSuccess);
    }
};

每个人加入会议后 - >会议开始并要求投票(这个地方我们应该叫signalR)

从投票询问人一方我看到这样的控制台日志:

普通用户(投票人控制台日志如下所示:

这是来自Firefox - 另一个用户:

我认为它已经触发了 - 集线器'NotificationHub'上的客户端集线器事件'sendOnlineMeetingVoteRequest'。

它已经达到了服务器端功能,但问题是它永远不会碰到这部分代码:

notificationHub.client.sendOnlineMeetingVoteRequest = function (token, meetingId, meetingVoteId) {
    debugger;
    if (token == '@Model.Organization' && '@Model.MeetingId' == meetingId) {
        ShowMeetingOnlineMeetingVotePopup(meetingId, meetingVoteId);
    }
};

我经历了http://localhost:33852/signalr/hubs

/*!
 * ASP.NET SignalR JavaScript Library v2.3.0-rtm
 * http://signalr.net/
 *
 * Copyright (c) .NET Foundation. All rights reserved.
 * Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
 *
 */

/// <reference path="..\..\SignalR.Client.JS\Scripts\jquery-1.6.4.js" />
/// <reference path="jquery.signalR.js" />
(function ($, window, undefined) {
    /// <param name="$" type="jQuery" />
    "use strict";

    if (typeof ($.signalR) !== "function") {
        throw new Error("SignalR: SignalR is not loaded. Please ensure jquery.signalR-x.js is referenced before ~/signalr/js.");
    }

    var signalR = $.signalR;

    function makeProxyCallback(hub, callback) {
        return function () {
            // Call the client hub method
            callback.apply(hub, $.makeArray(arguments));
        };
    }

    function registerHubProxies(instance, shouldSubscribe) {
        var key, hub, memberKey, memberValue, subscriptionMethod;

        for (key in instance) {
            if (instance.hasOwnProperty(key)) {
                hub = instance[key];

                if (!(hub.hubName)) {
                    // Not a client hub
                    continue;
                }

                if (shouldSubscribe) {
                    // We want to subscribe to the hub events
                    subscriptionMethod = hub.on;
                } else {
                    // We want to unsubscribe from the hub events
                    subscriptionMethod = hub.off;
                }

                // Loop through all members on the hub and find client hub functions to subscribe/unsubscribe
                for (memberKey in hub.client) {
                    if (hub.client.hasOwnProperty(memberKey)) {
                        memberValue = hub.client[memberKey];

                        if (!$.isFunction(memberValue)) {
                            // Not a client hub function
                            continue;
                        }

                        // Use the actual user-provided callback as the "identity" value for the registration.
                        subscriptionMethod.call(hub, memberKey, makeProxyCallback(hub, memberValue), memberValue);
                    }
                }
            }
        }
    }

    $.hubConnection.prototype.createHubProxies = function () {
        var proxies = {};
        this.starting(function () {
            // Register the hub proxies as subscribed
            // (instance, shouldSubscribe)
            registerHubProxies(proxies, true);

            this._registerSubscribedHubs();
        }).disconnected(function () {
            // Unsubscribe all hub proxies when we "disconnect".  This is to ensure that we do not re-add functional call backs.
            // (instance, shouldSubscribe)
            registerHubProxies(proxies, false);
        });

        proxies['NotificationHub'] = this.createHubProxy('NotificationHub'); 
        proxies['NotificationHub'].client = { };
        proxies['NotificationHub'].server = {

            sendMeetingStartMessage: function (token, meetingId) {
                return proxies['NotificationHub'].invoke.apply(proxies['NotificationHub'], $.merge(["sendMeetingStartMessage"], $.makeArray(arguments)));
             },

            sendMeetingStopMessage: function (token, meetingId) {
                return proxies['NotificationHub'].invoke.apply(proxies['NotificationHub'], $.merge(["sendMeetingStopMessage"], $.makeArray(arguments)));
             },

            sendMeetingTreeRefreshRequest: function (token, meetingId) {
                return proxies['NotificationHub'].invoke.apply(proxies['NotificationHub'], $.merge(["sendMeetingTreeRefreshRequest"], $.makeArray(arguments)));
             },

            sendMessage: function (token, meetingId, agendaGroupItemId, motionId) {
                return proxies['NotificationHub'].invoke.apply(proxies['NotificationHub'], $.merge(["sendMessage"], $.makeArray(arguments)));
             },

            sendOnlineMeetingVoteCloseRequest: function (token, meetingId, meetingVoteId) {
                return proxies['NotificationHub'].invoke.apply(proxies['NotificationHub'], $.merge(["sendOnlineMeetingVoteCloseRequest"], $.makeArray(arguments)));
             },

            sendOnlineMeetingVoteRequest: function (token, meetingId, meetingVoteId) {
                return proxies['NotificationHub'].invoke.apply(proxies['NotificationHub'], $.merge(["sendOnlineMeetingVoteRequest"], $.makeArray(arguments)));
             },

            sendOnlineVoteCloseRequest: function (token, meetingId, agendaGroupItemId, motionId) {
                return proxies['NotificationHub'].invoke.apply(proxies['NotificationHub'], $.merge(["sendOnlineVoteCloseRequest"], $.makeArray(arguments)));
             },


            sendOnlineVoteRequest: function (token, meetingId, agendaGroupItemId, motionId) {
                return proxies['NotificationHub'].invoke.apply(proxies['NotificationHub'], $.merge(["sendOnlineVoteRequest"], $.makeArray(arguments)));
             },


            sendOnlineVoteResult: function (token, meetingId, agendaGroupItemId, motionId, selectedVotingOptionId) {
                return proxies['NotificationHub'].invoke.apply(proxies['NotificationHub'], $.merge(["sendOnlineVoteResult"], $.makeArray(arguments)));
             }
        };

        return proxies;
    };

    signalR.hub = $.hubConnection("/signalr", { useDefaultPath: false });
    $.extend(signalR, signalR.hub.createHubProxies());

}(window.jQuery, window));

所以我也没有发现任何错误。尽管如此,我无法弄清楚为什么会发生这种情况,但我经历了使用signalR 2.0.3.0版本的示例项目

我去参考并注意到这个参考--Microsoft.AspNet.SignalR.Owin不包含在我下载的示例项目中。

我进一步调查并发现了这个:

'以下方法或属性之间的调用不明确'如果未删除对Microsoft.AspNet.SignalR.Owin的引用,则会发生此错误。该软件包已弃用;必须删除引用,并且必须卸载1.x版本的SelfHost软件包。 (https://docs.microsoft.com/en-us/aspnet/signalr/overview/releases/upgrading-signalr-1x-projects-to-20

我需要删除吗?在我的网络配置中,没有这样的代码。

asp.net-mvc asp.net-mvc-5 signalr signalr-hub signalr.client
1个回答
0
投票

我只是简单地从另一个地方调用这个功能 - 关于我们页面。只添加相关的脚本和功能。从那个地方来看,它奏效了。

之后,我更改了一些脚本并解决了这个问题。

主要的是我没有得到任何错误或任何东西。事情看起来一直很有效。但由于某些脚本放置,它不起作用。

© www.soinside.com 2019 - 2024. All rights reserved.