R
R
Roman Basharin2016-12-28 05:10:30
PHP
Roman Basharin, 2016-12-28 05:10:30

What logic of work in Socket.io with several tabs is more logical?

Greetings colleagues, I have already read 3 dozen pages, but have not found a more or less correct solution in my opinion.
Incoming data:
NGINX web server
All logic is written in PHP
nodejs + socket.io I use to work with web sockets
The project is a self-written CRM system.
The task looks like this:
1) Each manager is assigned a specific order with the specified customer phone number. When a call arrives at the PBX, I catch the caller's number with PHP, determine what kind of order it is and which manager it belongs to.
2. As it should be) JSON with this information flies to socket.io, it in turn passes the information to the browser, where the manager immediately opens a new tab with this order.
2. As it is now (dev mode) - if the manager has 3 tabs open, then 3 new tabs will be opened automatically with this order. If 15 is open, and managers sometimes do this when calling, then 15 will open additionally.
How can I implement this, but this is some kind of crutch option.
1) When you first log in to socket-io, info about the manager is loaded where the key will be its PHPSESSID. Then, each time the page is opened, it will not be necessary to foreach the entire array, but it will be enough to check whether there are already users['current PHPSESSID'] in the array.
2) But here another problem arises. Every time we need to determine which manager to send a message to, we will have to run through the loop and check the manager_id that came from php with those connected at the second level of nesting.
3) How to make it so that only 1 tab opens per request? Each time a client connects to socket.io, write to one of the "properties" of the current manager what last page he went to, and check location.path + location.search with what is in the browser's address bar. Why a crutch? Because the query string can be 200 characters, or even under 800, and line-by-line comparison is completely out of topic.
Maybe there is already a solution for this problem? What that "socket.io of the smoker" turns out.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Kislenko, 2016-12-28
@Hellek

I would solve the problem on the client, you need to implement "communication" between the tabs and always check that only one tab holds the connection to the socket server.
Further, if a person switches tabs, then only the active tab connects to the socket server, all other tabs terminate the connection. If a person has gone to a third-party resource, then only the last active tab will have a connection.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question