Skip to content

Commit

Permalink
feat: Add WPP.conn.refreshQR function
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Feb 28, 2022
1 parent 1f6aba6 commit edae1c0
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/conn/events/registerMainLoadedEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { eventEmitter } from '../eventEmitter';
webpack.onInjected(register);

function register() {
Cmd.on('all', console.log);
const trigger = async () => {
eventEmitter.emit('main_loaded');
};
Expand Down
2 changes: 1 addition & 1 deletion src/conn/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ export { isIdle } from './isIdle';
export { isMainLoaded } from './isMainLoaded';
export { isMultiDevice } from './isMultiDevice';
export { logout } from './logout';
export { poke } from './poke';
export { refreshQR } from './refreshQR';
export { setMultiDevice } from './setMultiDevice';
21 changes: 0 additions & 21 deletions src/conn/functions/poke.ts

This file was deleted.

44 changes: 44 additions & 0 deletions src/conn/functions/refreshQR.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*!
* 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 { Cmd, Socket } from '../../whatsapp';
import { AuthCode } from '..';
import { eventEmitter } from '../eventEmitter';
import { isAuthenticated, isMultiDevice } from '.';

/**
* Refresh the current QRCode when is waiting for scan and return the current code
*
* For legacy: It will wait for next code
* For multidevice: It will generate a new one
*
* @example
* ```javascript
* await WPP.conn.refreshQR();
* ```
*/
export async function refreshQR(): Promise<AuthCode | null> {
if (isAuthenticated()) {
return null;
}

if (isMultiDevice()) {
Cmd.refreshQR();
} else {
Socket.poke();
}
return await eventEmitter.once('auth_code_change');
}

0 comments on commit edae1c0

Please sign in to comment.