Skip to content

Commit

Permalink
feat: Added conn.online event (#1085)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed May 3, 2023
1 parent 5ce90e8 commit 36415a0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/conn/events/eventTypes.ts
Expand Up @@ -74,6 +74,22 @@ export interface ConnEventTypes {
* ```
*/
'conn.needs_update': undefined;

/**
* Triggered when the online change to online or offline
*
* @example
* ```javascript
* WPP.on('conn.online', (online) => {
* if (online) {
* console.log('You are online');
* } else {
* console.log('You are offline');
* }
* });
* ```
*/
'conn.online': boolean;
'conn.qrcode_idle': undefined;
'conn.require_auth': undefined;
}
1 change: 1 addition & 0 deletions src/conn/events/index.ts
Expand Up @@ -21,5 +21,6 @@ import './registerMainInit';
import './registerMainLoadedEvent';
import './registerMainReadyEvent';
import './registerNeedsUpdateEvent';
import './registerOnlineEvent';
import './registerQRCodeIdleEvent';
import './registerRequireAuthEvent';
30 changes: 30 additions & 0 deletions src/conn/events/registerOnlineEvent.ts
@@ -0,0 +1,30 @@
/*!
* Copyright 2021 WPPConnect Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { internalEv } from '../../eventEmitter';
import * as webpack from '../../webpack';
import { NetworkStatus, NetworkStatusModel } from '../../whatsapp';

webpack.onInjected(register);

function register() {
NetworkStatus.on(
'change:online',
(model: NetworkStatusModel, online: boolean) => {
internalEv.emit('conn.online', online);
}
);
}

0 comments on commit 36415a0

Please sign in to comment.