通知未显示提供的图像

时间:2014-07-23 11:20:35

标签: javascript firefox-addon firefox-addon-sdk

我正在尝试使用通过套接字接收的图像作为arrayBuffer来显示通知。通知显示,但未提供图像。而是使用标准的firefox徽标/图标。任何帮助,将不胜感激。代码似乎没有任何错误地运行,或者更确切地说,在创建通知时没有抛出错误/堆栈跟踪打印。

以下是创建通知的代码:

ps_worker.port.on("notification", function(notification){
            //DISPLAY LINK TO USER
            var arrayBuffer_icon = notification.icon;
            var arrayBuffer_largeicon = notification.largeicon;

            var str = String.fromCharCode.apply(null,arrayBuffer_icon);
            var base64String = utils.btoa(str).replace(/.{76}(?=.)/g,'$&\n');
            var dataUri = "data:image/png;base64,"+ base64String;

            notifications.notify({
                    title: notification.app + ": " + notification.title,
                    text: notification["subject"] + "\n" + notification.content,
                    data: "did gyre and gimble in the wabe", // data is a string passed through to the on click listener
                    iconURL: dataUri,
                    onClick: function (data) {
                            console.log(data);
                    }
            });
    });

utils.btoa调用按照此处所述实现:https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Unit_testing

相关的服务器代码是(node.js):

function send_notification_to_socket(user, notification, target){
fs.readFile(notification.iconpath, function(err, buf){
        if(socketstore.get_socket_by_id(user)){
                socket = socketstore.get_socket_by_id(user);
                notification["icon"] = buf;
                socket.emit('notification', notification);
        }else{
                console.log("No socket for user " + user);
        }
});
}

关于我可能做错的任何想法?

0 个答案:

没有答案