Skip to content

Commit

Permalink
refactor: Renamed State to Socket
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Feb 27, 2022
1 parent b3f331b commit c2da66d
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/conn/eventEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface EventTypes {
auth_code_change: AuthCode | null;
logout: undefined;
qrcode_idle: undefined;
require_auth: undefined;
}

export const eventEmitter = new Emittery<EventTypes, EventTypes>({
Expand Down
4 changes: 2 additions & 2 deletions src/conn/events/registerQRCodeIdleEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import Debug from 'debug';

import * as webpack from '../../webpack';
import { State } from '../../whatsapp';
import { Socket } from '../../whatsapp';
import { isIdle } from '..';
import { eventEmitter } from '../eventEmitter';

Expand All @@ -33,7 +33,7 @@ function registerQRCodeIdleEvent() {
}
};
trigger();
State.on('change:state', trigger);
Socket.on('change:state', trigger);

debug('idle event registered');
}
4 changes: 2 additions & 2 deletions src/conn/functions/isIdle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

import { State } from '../../whatsapp';
import { Socket } from '../../whatsapp';
import { SOCKET_STATE } from '../../whatsapp/enums/SOCKET_STATE';

export function isIdle(): boolean {
return State.state === SOCKET_STATE.UNPAIRED_IDLE;
return Socket.state === SOCKET_STATE.UNPAIRED_IDLE;
}
4 changes: 2 additions & 2 deletions src/conn/functions/logout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

import { Cmd, State } from '../../whatsapp';
import { Cmd, Socket } from '../../whatsapp';

export async function logout(): Promise<boolean> {
State.logout();
Socket.logout();

await new Promise((resolve) => {
Cmd.once('logout', resolve);
Expand Down
4 changes: 2 additions & 2 deletions src/conn/functions/poke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

import { State } from '../../whatsapp';
import { Socket } from '../../whatsapp';

export function poke(): void {
State.poke();
Socket.poke();
}
6 changes: 3 additions & 3 deletions src/whatsapp/misc/State.ts → src/whatsapp/misc/Socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
*/

import { exportModule } from '../exportModule';
import { StateModel } from '../models';
import { SocketModel } from '../models';

/** @whatsapp 65044 */
export declare const State: StateModel;
export declare const Socket: SocketModel;

exportModule(
exports,
{ State: (m) => m.Socket || m.default },
{ Socket: (m) => m.Socket || m.default },
(m) => m.Socket?.initConn || m.default?.initConn
);
2 changes: 1 addition & 1 deletion src/whatsapp/misc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export * from './MediaUtils';
export * from './MsgKey';
export * from './MsgLoadState';
export * from './OpaqueData';
export * from './State';
export * from './Socket';
export * from './UserPrefs';
export * from './VCard';
export * from './Wap';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ interface Session {
interface Derived {}

/** @whatsapp 65044 */
export declare interface StateModel
export declare interface SocketModel
extends ModelProxy<Props, Session, Derived> {}

/** @whatsapp 65044 */
export declare class StateModel extends Model {
export declare class SocketModel extends Model {
constructor(
proterties?: ModelPropertiesContructor<StateModel>,
proterties?: ModelPropertiesContructor<SocketModel>,
options?: ModelOptions
);

Expand Down Expand Up @@ -130,6 +130,6 @@ export declare class StateModel extends Model {

exportModule(
exports,
{ StateModel: (m) => m.Socket?.constructor || m.default?.constructor },
{ Socket: (m) => m.Socket?.constructor || m.default?.constructor },
(m) => m.Socket?.initConn || m.default?.initConn
);

0 comments on commit c2da66d

Please sign in to comment.