I'm trying to communicate between my main Add-on SDK script, index.js, and a script in a page-worker created with sdk/page-worker. Unfortunately, I am having problems.
I am able to communicate from my main script to the page-worker: In the code below, I get an event from socket.on - console.log('new post') fires from the script in the page-worker. However, the main add-on script does not see the message that is sent from the page-worker.
HTML (worker.html):
<html lang="pl">
<head>
<meta charset="UTF-8">
<script src="https://cdn.socket.io/socket.io-1.3.5.js"></script>
<script type="text/javascript">
var socket = io.connect('http://192.168.0.21:8081');
socket.on('newPost', function(data) {
console.log("new post");
//to this everything works ok!!!!!!!!!!!!
self.port.emit('newPost', "");
});
</script>
</head>
<body>
</body>
</html>
to index.js file:
var buttons = require('sdk/ui/button/action');
var functions = require('./module.js');
var pageWorkers = require("sdk/page-worker");
var notifications = require('sdk/notifications');
var self = require("sdk/self");
functions.act.checkMsgsCount();
var pageWorker = pageWorkers.Page({
contentScriptWhen: "ready",
contentURL: self.data.url("worker.html")
});
pageWorker.port.on('newPost', function(data) {
console.log("sent newPost");
functions.act.newPostNotify();
});
buttons.ActionButton({
id: "main-bt",
label: "Start",
icon: {
"16" : "./icon-16.png",
"32" : "./icon-32.png",
"64" : "./icon-64.png"
},
onClick: functions.act.checkMsgsCount
});
Tools>Web developmentmenu) related to your inline script?