播放通道在生产时自动断开连接

时间:2013-06-29 00:25:59

标签: python google-app-engine flask

在制作时,我一打开一个带有javascript的频道,就会在一秒后断开连接。 devserver上的一切都非常好用。回调适用于服务器,但不适用于客户端。我们正在使用flask,backbone,requirejs和sourcemap。

客户代码:

window.channel = new goog.appengine.Channel(window.PLAY_SETTINGS.CHANNEL_TOKEN);
window.gae_websocket = window.channel.open({
  onopen: function() {
    return console.log('onopen');
  },
  onclose: function() {
    return console.log('onclose');
  },
  onerror: function() {
    return console.log('onerror');
  },
  onmessage: function() {
    return console.log('onmessage');
  }
});

服务器代码:

class Connection(ndb.Model):
    user_key = ndb.KeyProperty()
    scope = ndb.IntegerProperty(indexed=True, choices=range(0, 2))
    target_key = ndb.KeyProperty(indexed=True)  # Event ou debate
    channel_id = ndb.StringProperty(indexed=True)

    @staticmethod
    def open_channel():
        channel_id = str(uuid4())
        channel_token = channel.create_channel(client_id=channel_id, duration_minutes=480)
        return channel_token, channel_id

来自appengine生产控制台的日志。 screenshot from appengine prodcution console

客户端回调(js)不起作用。这些是创建日志的服务器回调:

@app.route('/_ah/channel/disconnected/', methods=['POST'])
def channel_disconnection():
    client_id = request.form.get('from')
    ndb.delete_multi(Connection.query(Connection.channel_id == client_id).fetch(keys_only=True))
    logging.info("Channel closed : %s" % client_id)
    return make_response('ok', '200')


@app.route('/_ah/channel/connected/', methods=['POST'])
def channel_connection():
    client_id = request.form.get('from')
    logging.info("Channel open : %s" % client_id)
    return make_response('ok', '200')

0 个答案:

没有答案
相关问题