E
E
Enkei12021-01-29 21:26:30
1C-Bitrix
Enkei1, 2021-01-29 21:26:30

How to link an application to Bitrix via push and pull?

Hello. There is a built-in self-written application built into the boxed version of Bitrix. The goal is to connect all open pages with our application through the Bitrix event handler. Those. when pressing a button in the application, for all users who have this application open, display the conditional 'Hello World' in the console.
In short, register an event, subscribe, and learn how to catch events from Bitrix. Is it possible to do this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2021-01-29
Madzhugin @Suntechnic

Here's how it works for me:
A user subscribes to events associated with the $dctList['UUID'] object: We send a notification to all users when an event occurs associated with the object with the identifier $list_uuid
\CPullWatch::Add($UserID, $dctList['UUID']);

\CPullWatch::AddToStack($list_uuid,
        Array(
          'module_id' => 'list',
          'command' => 'exchange',
          'params' => [
              'provocative' => $dctData['head']['UID'],
              'list_uuid'=> $list_uuid
            ]
        )
      );

module loading:
BX.loadScript('/bitrix/js/pull/protobuf/protobuf.js', ()=>{
          BX.loadScript('/bitrix/js/pull/protobuf/model.js', ()=>{
              BX.loadScript('/bitrix/js/rest/client/rest.client.js', ()=>{
                  BX.loadScript('/bitrix/js/pull/client/pull.client.js',()=>{APP.bitrixreinit._pullinit()});
                });
            });
        });

Subscribe to events in the _pullinit method:
// подписываемся на события P&P
    BX.addCustomEvent("onPullEvent", function(module_id,command,params) {
      
      if (APP.getConfigParam('uid') == params.provocative) {
        //if ('production' != APP.getConfigParam('mode')) console.log('собственное событие пропущено');
        return;
      }
      if ('exchange' == command) {
        APP.exchange({basis: 'pull', context: params});
      }
    });

    BX.addCustomEvent("onPullStatus", function(status) {
      if ('online' != APP.$store.state.status.push_and_pull
          && 'online' == status) {
        // не онлайн сменился на онлайн
        //let last_sync_time = APP.$store.state.db.sync.last.time.client || 0
        //let now_time = Date.now()/1000
        //if (now_time - last_sync_time < 30) {
        //	
        //} else {
        //	
        //}
        APP.exchange({basis: 'reconnect'});
      }
      APP.$store.commit("updateStatus",{key:'push_and_pull',data:status})
    });
    
    BX.PULL.start();

A
Alexey Emelyanov, 2021-01-29
@babarun

Those. when pressing a button in the application, for all users who have this application open, display the conditional 'Hello World' in the console.
It is possible , but it is better to implement it yourself through web sockets or a matrix.
There is a built-in self-written application
60145d9295cdd858871488.jpeg
You already decide whether the built-in Bitrix application or self-written?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question