仅限iframe

时间:2016-07-22 20:26:34

标签: pubnub

当我的页面+ javascript代码在iframe中运行时,我得到一个空的错误对象{},试图订阅一个频道。直接加载时工作正常。两种情况下的通道名称都相同。有什么想法吗?

以下是代码:

(function(){
    function PubSub(app,subscribe_key,channel_postfix){
        this._app = app;
        this._subscribeKey = subscribe_key;
        this._channelPostfix = channel_postfix;
        this._pubnub = PUBNUB({subscribe_key: this._subscribeKey,ssl: true});
        var test = this._pubnub;
        var test2 = test;
    };

    global.PubSub = PubSub; // global class 
    PubSub.prototype.subscribe_reactions = function (session_id){
        var self = this;
        var channel = ("reactions." + session_id);
        if (this._channelPostfix) { channel = ("" + channel + "." + (this._channelPostfix)) };
        return this._pubnub.subscribe({
            channel: channel,
            message: function(data) {
                // console.log(JSON.stringify(data))
                return self._app.transform_and_load_data().got_reaction(data);
            },
            error: function(error) { return window.alert(("Error subscribing to reactions: " + JSON.stringify(error) + " on channel " + channel + ".")); }
        });
    };

    PubSub.prototype.subscribe_foci = function (session_id){
        var self = this;
        var channel = ("foci." + session_id);
        if (this._channelPostfix) { channel = ("" + channel + "." + (this._channelPostfix)) };
        return this._pubnub.subscribe({
            channel: channel,
            message: function(data) {
                // console.log(data)
                return self._app.transform_and_load_data().got_focus_point(data);
            },
            error: function(error) { return window.alert(("Error subscribing to foci: " + JSON.stringify(error) + " on channel " + channel + ".")); }
        });
    };
    return PubSub;

})()

0 个答案:

没有答案