3 weeks ago - last edited 3 weeks ago
Hi,
I have that requirement to open only a single Websocket connection per client per application.
I want to use the sap.ui.core.ws.SapPcpWebSocket implementation in UI5. But I have the issue that everytime the application opens in a new tab/window a new Websocket connection is opened. I can see multiple connections inside T-Code SMICM.
What I've tried:
I found that SharedWorker - Web APIs | MDN (mozilla.org) could be a solution, but I can't manage to run the Websocket code inside the SharedWorker API.
Component.js
var resourceUrl = sap.ui.require.toUrl("worker.js");
const worker = new SharedWorker(resourceUrl);
//or this
//const worker = new SharedWorker("worker.js");
worker.js (file exists right next to Component.js):
const ws = new sap.ui.core.ws.SapPcpWebSocket(`ws${location.protocol === "https:" ? "s" : ""}://${location.host}/sap/bc/apc/sap/z_apc`);
ws.onmessage = ({ data }) => {
};
onconnect = e => {
};
Whenever I want to run the SharedWorker constructur, I am getting this error:
Is there maybe another approach to prevent UI5 to open multiple Websocket connections?
Any suggestions would be helpful.
You have to provide the module path to toUrl method.
var resourceUrl = sap.ui.require.toUrl(module_path + "/worker.js");
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
78 | |
9 | |
9 | |
7 | |
7 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.