有没有办法可以将数据传递给客户端ActionCable通道的disconnect方法?我需要当前用户的ID,以便我可以关闭他们的在线状态指示器。我已经尝试并阅读了我在ActionCable上可以找到的所有内容,但我不明白如何将数据传递给接收以外的方法。
Live.appearance = Live.cable.subscriptions.create('AppearanceChannel', {
// need to pass the user's ID here:
disconnected: function(data) {
var userId = data['appearances'][0];
var appearanceContainer = $('.user-status-indicator').filter('#' + userId);
appearanceContainer.remove();
},
received: function(data) {
var userId = data['appearances'][0];
var appearanceContainer = $('.appearance-label').filter('#' + userId);
appearanceContainer.append('<div class="user-status-indicator" id="${userId}"></div>');
}
});