Search code examples
javascriptms-officeoffice-jsoffice-addinsoffice-app

Communication of two taskpanes


I am making an Office add-in which has two ribbon buttons. Each button is linked to a different TaskpaneId, and clicking on each button opens a different taskpane:

<bt:Urls>
    <bt:Url id="Contoso.Taskpane1.Url" DefaultValue="https://localhost:3000/addin/page1" />
    <bt:Url id="Contoso.Taskpane2.Url" DefaultValue="https://localhost:3000/addin/page2" />
</bt:Urls>

Now, I want to realise some communication between these two pages. For example, after some manipulations on page1, I want page2 to be automatically refreshed (to reload data from server or localStorage). As a result, when we click on page2, it is already up-to-date. At the moment, it is not systematically updated, and to refresh page2, we have to click on its ribbon button.

https://localhost:3000/ is built with mean-stack, so the pages use angularjs and have a server behind. One way of communication of two pages is to via server: page1 sends a message by socket.io to the server, and then the server emits a message by socket.io to page2. It is a little bit tedious.

Does anyone know if JavaScript API for Office has already any easy (and cross-platform) way to permit of such a communication between 2 taskpanes?

PS: using StorageEvent of localStorage is not a good idea, because it does not seem to work in Excel for Mac or for Windows.


Solution

  • There is no great solution at the moment. For Script Lab, we use local storage and a timer to check a time stamp a couple times a second on platforms/browsers that don't support events (IE 11). The problem with local storage isn't so much the need for timers, but rather that you can't really scope it to just a particular set of task panes. Instead, it ends up impacting task panes on other documents as well. For script lab, we decided to live with that behavior, instead of spending the energy on a server-based communication (I assume you mean socket.io or similar?)