【问题标题】:Generating exception sending data from JS web client using the Pusher library使用 Pusher 库从 JS Web 客户端生成异常发送数据
【发布时间】:2014-01-29 17:18:32
【问题描述】:

我是 Pusher 的新手,目前在尝试从简单的 JS Web 客户端发送数据时遇到错误,我试图弄清楚这是代码错误还是浏览器问题(我怀疑是浏览器问题)。发生的情况是,我使用一个简单的 Perl 脚本通过 Pusher 服务将文本消息发送到在 FireFox 23.0.1 中运行的 Web 客户端。消息被正确接收(是的!)但是当我尝试发送返回消息时,我在“pusher.min.js(第 65 行)”处收到“未捕获的异常:[object Object]”错误,其中出现了 Pusher 库代码它试图创建一个 Flash 对象...

uncaught exception: [object Object]
...try{return Boolean(new ActiveXObject("ShockwaveFlash.ShockwaveFlash"))}catch(a){...

代码是来自 Pusher 网站的一些 JS 演示的轻微变化...

<!DOCTYPE html>
<head>
  <title>Pusher Test</title>
  <script src="http://js.pusher.com/2.1/pusher.min.js" type="text/javascript"></script>
  <script type="text/javascript">
    // Enable pusher logging - don't include this in production
    Pusher.log = function(message) {
        if (window.console && window.console.log) {
            window.console.log(message);
        } //end if
    }; //end function

    var channelName='test_channel';
    var eventName='status_update';

    var pusher = new Pusher( [AppID removed] );
    var channel = pusher.subscribe(channelName);
    var callback = function(data) {
        // add comment into page
        alert(data);
        console.log(data);
        var triggered = channel.trigger(channelName, {data:"hello yourself"});
    }; //end callback

    pusher.bind(eventName, callback);
  </script>
</head>

Flash(版本 11.8.800.168)已安装并启用。

代码是正确的还是我在做一些愚蠢的事情?如果代码正确,有人知道我如何解决这个问题吗?

【问题讨论】:

  • 你是怎么解决的?

标签: javascript websocket client-side pusher


【解决方案1】:

只需将 status_update 更改为 client-status_update。

客户端事件必须以 client- 为前缀。带有任何其他前缀的事件将被 Pusher 服务器拒绝,发送到客户端未订阅的频道的事件也将被拒绝。

http://pusher.com/docs/client_api_guide/client_events

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-08
    相关资源
    最近更新 更多