voice-calls-baileys 1.0.5 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/demo.js CHANGED
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
@@ -34,12 +44,13 @@ async function connectToWhatsApp() {
34
44
  const sock = (0, baileys_1.default)({
35
45
  printQRInTerminal: true,
36
46
  auth: state,
37
- browser: baileys_1.Browsers.macOS('Desktop'),
47
+ browser: baileys_1.Browsers.windows("UWP"),
48
+ version: [2, 3000, 1031141796, 257538, 0],
38
49
  logger: (0, pino_1.default)({ level: "error" }),
39
50
  syncFullHistory: false,
40
51
  markOnlineOnConnect: false
41
52
  });
42
- (0, transport_model_1.useVoiceCallsBaileys)("your token", sock, "close", true);
53
+ (0, transport_model_1.useVoiceCallsBaileys)("<Your Wavoip Token>", sock, "<Your Software Name>", "close", true);
43
54
  sock.ev.on("creds.update", saveCreds);
44
55
  sock.ev.on('connection.update', (update) => {
45
56
  var _a, _b;
@@ -1,4 +1,4 @@
1
1
  import { Socket } from "socket.io-client";
2
2
  import { ClientToServerEvents, ServerToClientEvents } from "./transport.type";
3
3
  import { WAConnectionState, WASocket } from "baileys";
4
- export declare const useVoiceCallsBaileys: (wavoip_token: string, baileys_sock: WASocket, status?: WAConnectionState, logger?: boolean) => Promise<Socket<ServerToClientEvents, ClientToServerEvents>>;
4
+ export declare const useVoiceCallsBaileys: (wavoip_token: string, baileys_sock: WASocket, softwareBase: string, status?: WAConnectionState, logger?: boolean) => Promise<Socket<ServerToClientEvents, ClientToServerEvents>>;
@@ -3,154 +3,103 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useVoiceCallsBaileys = void 0;
4
4
  const socket_io_client_1 = require("socket.io-client");
5
5
  let baileys_connection_state = "close";
6
- const useVoiceCallsBaileys = async (wavoip_token, baileys_sock, status, logger) => {
7
- baileys_connection_state = status !== null && status !== void 0 ? status : "close";
6
+ const useVoiceCallsBaileys = async (wavoip_token, baileys_sock, softwareBase, status, logger) => {
8
7
  const socket = (0, socket_io_client_1.io)("https://devices.wavoip.com/baileys", {
9
8
  transports: ["websocket"],
10
- path: `/${wavoip_token}/websocket`,
11
- forceNew: true,
9
+ path: `/${wavoip_token}/websocket`
12
10
  });
13
11
  socket.on("connect", () => {
14
12
  if (logger)
15
- console.log("[*] - Wavoip connected", socket.id);
16
- socket.emit("init", baileys_sock.authState.creds.me, baileys_sock.authState.creds.account, baileys_connection_state);
13
+ console.log("[Wavoip] - Connected", socket.id);
14
+ socket.emit("init", baileys_sock.authState.creds.me, baileys_sock.authState.creds.account, status !== null && status !== void 0 ? status : "close", softwareBase);
17
15
  });
18
16
  socket.on("disconnect", () => {
19
17
  if (logger)
20
- console.log("[*] - Wavoip disconnect");
18
+ console.log("[Wavoip] - Disconnected");
21
19
  });
22
20
  socket.on("connect_error", (error) => {
23
- if (socket.active) {
24
- if (logger)
25
- console.log("[*] - Wavoip connection error temporary failure, the socket will automatically try to reconnect", error);
26
- }
27
- else {
28
- if (logger)
29
- console.log("[*] - Wavoip connection error", error.message);
30
- }
21
+ if (logger)
22
+ console.log("[Wavoip] - Connection lost");
31
23
  });
32
- socket.on("onWhatsApp", async (jid, callback) => {
33
- try {
34
- const response = await baileys_sock.onWhatsApp(jid);
35
- callback(response);
36
- if (logger)
37
- console.log("[*] Success on call onWhatsApp function", response, jid);
38
- }
39
- catch (error) {
40
- if (logger)
41
- console.error("[*] Error on call onWhatsApp function", error);
42
- }
24
+ socket.on("onWhatsApp", (jid, callback) => {
25
+ baileys_sock.onWhatsApp(jid)
26
+ .then((response) => callback(response))
27
+ .catch((error) => {
28
+ callback({ wavoipStatus: "error", result: error });
29
+ if (logger)
30
+ console.log("[Wavoip] - Failed to call onWhatsapp, error: ", error);
31
+ });
43
32
  });
44
33
  socket.on("profilePictureUrl", async (jid, type, timeoutMs, callback) => {
45
- try {
46
- const response = await baileys_sock.profilePictureUrl(jid, type, timeoutMs);
47
- callback(response);
34
+ baileys_sock.profilePictureUrl(jid, type, timeoutMs)
35
+ .then((response) => callback(response))
36
+ .catch((error) => {
37
+ callback({ wavoipStatus: "error", result: error });
48
38
  if (logger)
49
- console.log("[*] Success on call profilePictureUrl function", response);
50
- }
51
- catch (error) {
52
- if (logger)
53
- console.error("[*] Error on call profilePictureUrl function", error);
54
- }
39
+ console.log("[Wavoip] - Failed to call profilePictureUrl, error: ", error);
40
+ });
55
41
  });
56
42
  socket.on("assertSessions", async (jids, force, callback) => {
57
- try {
58
- const response = await baileys_sock.assertSessions(jids, force);
59
- callback(response);
60
- if (logger)
61
- console.log("[*] Success on call assertSessions function", response);
62
- }
63
- catch (error) {
43
+ baileys_sock.assertSessions(jids, force)
44
+ .then((response) => callback(response))
45
+ .catch((error) => {
46
+ callback({ wavoipStatus: "error", result: error });
64
47
  if (logger)
65
- console.error("[*] Error on call assertSessions function", error);
66
- }
48
+ console.log("[Wavoip] - Failed to call assertSessions, error: ", error);
49
+ });
67
50
  });
68
51
  socket.on("createParticipantNodes", async (jids, message, extraAttrs, callback) => {
69
- try {
70
- const response = await baileys_sock.createParticipantNodes(jids, message, extraAttrs);
71
- callback(response, true);
72
- if (logger)
73
- console.log("[*] Success on call createParticipantNodes function", response);
74
- }
75
- catch (error) {
52
+ baileys_sock.createParticipantNodes(jids, message, extraAttrs)
53
+ .then((response) => callback(response.nodes, response.shouldIncludeDeviceIdentity))
54
+ .catch((error) => {
55
+ callback({ wavoipStatus: "error", result: error });
76
56
  if (logger)
77
- console.error("[*] Error on call createParticipantNodes function", error);
78
- }
57
+ console.log("[Wavoip] - Failed to call createParticipantNodes, error: ", error);
58
+ });
79
59
  });
80
60
  socket.on("getUSyncDevices", async (jids, useCache, ignoreZeroDevices, callback) => {
81
- try {
82
- const response = await baileys_sock.getUSyncDevices(jids, useCache, ignoreZeroDevices);
83
- callback(response);
84
- if (logger)
85
- console.log("[*] Success on call getUSyncDevices function", response);
86
- }
87
- catch (error) {
61
+ baileys_sock.getUSyncDevices(jids, useCache, ignoreZeroDevices)
62
+ .then((response) => callback(response))
63
+ .catch((error) => {
64
+ callback({ wavoipStatus: "error", result: error });
88
65
  if (logger)
89
- console.error("[*] Error on call getUSyncDevices function", error);
90
- }
91
- });
92
- socket.on("generateMessageTag", async (callback) => {
93
- try {
94
- const response = await baileys_sock.generateMessageTag();
95
- callback(response);
96
- if (logger)
97
- console.log("[*] Success on call generateMessageTag function", response);
98
- }
99
- catch (error) {
100
- if (logger)
101
- console.error("[*] Error on call generateMessageTag function", error);
102
- }
66
+ console.log("[Wavoip] - Failed to call createParticipantNodes, error: ", error);
67
+ });
103
68
  });
69
+ socket.on("generateMessageTag", (callback) => callback(baileys_sock.generateMessageTag()));
104
70
  socket.on("sendNode", async (stanza, callback) => {
105
- try {
106
- const response = await baileys_sock.sendNode(stanza);
107
- callback(true);
71
+ baileys_sock.sendNode(stanza)
72
+ .then((response) => callback(true))
73
+ .catch((error) => {
74
+ callback({ wavoipStatus: "error", result: error });
108
75
  if (logger)
109
- console.log("[*] Success on call sendNode function", response);
110
- }
111
- catch (error) {
112
- if (logger)
113
- console.error("[*] Error on call sendNode function", error);
114
- }
76
+ console.log("[Wavoip] - Failed to call createParticipantNodes, error: ", error);
77
+ });
115
78
  });
116
79
  socket.on("signalRepository:decryptMessage", async (jid, type, ciphertext, callback) => {
117
- try {
118
- const response = await baileys_sock.signalRepository.decryptMessage({
119
- jid: jid,
120
- type: type,
121
- ciphertext: ciphertext,
122
- });
123
- callback(response);
124
- if (logger)
125
- console.log("[*] Success on call signalRepository:decryptMessage function", response);
126
- }
127
- catch (error) {
80
+ baileys_sock.signalRepository.decryptMessage({ jid: jid, type: type, ciphertext: ciphertext })
81
+ .then((response) => callback(response))
82
+ .catch((error) => {
83
+ callback({ wavoipStatus: "error", result: error });
128
84
  if (logger)
129
- console.error("[*] Error on call signalRepository:decryptMessage function", error);
130
- }
85
+ console.log("[Wavoip] - Failed to call decryptMessage, error: ", error);
86
+ });
131
87
  });
132
- // we only use this connection data to inform the webphone that the device is connected and creeds account to generate e2e whatsapp key for make call packets
133
88
  baileys_sock.ev.on("connection.update", (update) => {
134
89
  const { connection } = update;
135
90
  if (connection) {
136
- baileys_connection_state = connection;
137
- socket
138
- .timeout(5000)
139
- .emit("connection.update:status", baileys_sock.authState.creds.me, baileys_sock.authState.creds.account, connection);
91
+ console.log(connection);
92
+ socket.timeout(1000).emit("connection.update:status", baileys_sock.authState.creds.me, baileys_sock.authState.creds.account, connection);
140
93
  }
141
94
  if (update.qr) {
142
- socket.timeout(5000).emit("connection.update:qr", update.qr);
95
+ socket.timeout(1000).emit("connection.update:qr", update.qr);
143
96
  }
144
97
  });
145
98
  baileys_sock.ws.on("CB:call", (packet) => {
146
- if (logger)
147
- console.log("[*] Signling received");
148
- socket.volatile.timeout(5000).emit("CB:call", packet);
99
+ socket.volatile.timeout(1000).emit("CB:call", packet);
149
100
  });
150
101
  baileys_sock.ws.on("CB:ack,class:call", (packet) => {
151
- if (logger)
152
- console.log("[*] Signling ack received");
153
- socket.volatile.timeout(5000).emit("CB:ack,class:call", packet);
102
+ socket.volatile.timeout(1000).emit("CB:ack,class:call", packet);
154
103
  });
155
104
  return socket;
156
105
  };
@@ -11,28 +11,35 @@ export interface ServerToClientEvents {
11
11
  "signalRepository:decryptMessage": SignalRepositoryDecryptMessageType;
12
12
  }
13
13
  export interface ClientToServerEvents {
14
- "init": (me: Contact | undefined, account: proto.IADVSignedDeviceIdentity | undefined, status: WAConnectionState) => void;
14
+ "init": (me: Contact | undefined, account: proto.IADVSignedDeviceIdentity | undefined, status: WAConnectionState, softwareBase: string) => void;
15
15
  "CB:call": (packet: any) => void;
16
16
  "CB:ack,class:call": (packet: any) => void;
17
17
  "connection.update:status": (me: Contact | undefined, account: proto.IADVSignedDeviceIdentity | undefined, status: WAConnectionState) => void;
18
18
  "connection.update:qr": (qr: string) => void;
19
19
  }
20
+ export type FailedResponseType = {
21
+ wavoipStatus: string;
22
+ result: any;
23
+ };
20
24
  export type onWhatsAppType = (jid: string, callback: onWhatsAppCallback) => void;
21
25
  export type onWhatsAppCallback = (response: {
22
26
  exists: boolean;
23
27
  jid: string;
24
- }[]) => void;
28
+ }[] | FailedResponseType | undefined) => void;
25
29
  export type ProfilePictureUrlType = (jid: string, type: "image" | "preview", timeoutMs: number | undefined, callback: ProfilePictureUrlCallback) => void;
26
- export type ProfilePictureUrlCallback = (response: string | undefined) => void;
30
+ export type ProfilePictureUrlCallback = (response: string | FailedResponseType | undefined) => void;
27
31
  export type AssertSessionsType = (jids: string[], force: boolean, callback: AssertSessionsCallback) => void;
28
- export type AssertSessionsCallback = (response: boolean) => void;
32
+ export type AssertSessionsCallback = (response: boolean | FailedResponseType) => void;
29
33
  export type CreateParticipantNodesType = (jids: string[], message: any, extraAttrs: any, callback: CreateParticipantNodesCallback) => void;
30
- export type CreateParticipantNodesCallback = (nodes: any, shouldIncludeDeviceIdentity: boolean) => void;
34
+ export type CreateParticipantNodesCallback = {
35
+ (nodes: any, shouldIncludeDeviceIdentity: boolean): void;
36
+ (response: FailedResponseType): void;
37
+ };
31
38
  export type GetUSyncDevicesType = (jids: string[], useCache: boolean, ignoreZeroDevices: boolean, callback: GetUSyncDevicesTypeCallback) => void;
32
- export type GetUSyncDevicesTypeCallback = (jids: JidWithDevice[]) => void;
39
+ export type GetUSyncDevicesTypeCallback = (jids: JidWithDevice[] | FailedResponseType) => void;
33
40
  export type GenerateMessageTagType = (callback: GenerateMessageTagTypeCallback) => void;
34
- export type GenerateMessageTagTypeCallback = (response: string) => void;
41
+ export type GenerateMessageTagTypeCallback = (response: string | FailedResponseType) => void;
35
42
  export type SendNodeType = (stanza: BinaryNode, callback: SendNodeTypeCallback) => void;
36
- export type SendNodeTypeCallback = (response: boolean) => void;
43
+ export type SendNodeTypeCallback = (response: boolean | FailedResponseType) => void;
37
44
  export type SignalRepositoryDecryptMessageType = (jid: string, type: "pkmsg" | "msg", ciphertext: Buffer, callback: SignalRepositoryDecryptMessageCallback) => void;
38
- export type SignalRepositoryDecryptMessageCallback = (response: any) => void;
45
+ export type SignalRepositoryDecryptMessageCallback = (response: Uint8Array | FailedResponseType) => void;
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "voice-calls-baileys",
3
- "version": "1.0.5",
3
+ "version": "1.0.8",
4
4
  "description": "Integração de chamadas de voz a biblioteca baileys",
5
5
  "main": "lib/index.js",
6
- "types": "lib/index.d.ts",
6
+ "types": "lib/index.d.ts",
7
7
  "scripts": {
8
- "dev": "ts-node-dev --inspect --transpile-only --ignore-watch node_modules src/index.ts",
8
+ "dev": "ts-node-dev --inspect --transpile-only --ignore-watch node_modules src/demo.ts",
9
9
  "build": "tsc"
10
10
  },
11
11
  "author": "Wavoip",
@@ -17,7 +17,8 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@types/socket.io-client": "^3.0.0",
20
- "baileys": "^6.7.5",
20
+ "baileys": "^6.7.8",
21
+ "qrcode-terminal": "^0.12.0",
21
22
  "socket.io-client": "^4.7.5",
22
23
  "ts-node-dev": "^2.0.0"
23
24
  }
package/src/demo.ts CHANGED
@@ -9,13 +9,14 @@ async function connectToWhatsApp() {
9
9
  const sock = makeWASocket({
10
10
  printQRInTerminal: true,
11
11
  auth: state,
12
- browser: Browsers.macOS('Desktop'),
12
+ browser: Browsers.windows("UWP"),
13
+ version: [2, 3000, 1031141796, 257538, 0],
13
14
  logger: P({ level: "error" }),
14
15
  syncFullHistory: false,
15
16
  markOnlineOnConnect: false
16
17
  })
17
18
 
18
- useVoiceCallsBaileys("your token", sock, "close", true)
19
+ useVoiceCallsBaileys("<Your Wavoip Token>", sock, "<Your Software Name>", "close", true)
19
20
 
20
21
  sock.ev.on("creds.update", saveCreds);
21
22
 
@@ -4,236 +4,132 @@ import { ClientToServerEvents, ServerToClientEvents } from "./transport.type";
4
4
 
5
5
  import { ConnectionState, WAConnectionState, WASocket } from "baileys";
6
6
 
7
- import { Logger } from "pino";
8
-
9
7
  let baileys_connection_state: WAConnectionState = "close";
10
8
 
11
9
  export const useVoiceCallsBaileys = async (
12
10
  wavoip_token: string,
13
11
  baileys_sock: WASocket,
12
+ softwareBase: string,
14
13
  status?: WAConnectionState,
15
14
  logger?: boolean
16
15
  ) => {
17
- baileys_connection_state = status ?? "close";
18
-
19
16
  const socket: Socket<ServerToClientEvents, ClientToServerEvents> = io(
20
17
  "https://devices.wavoip.com/baileys",
21
18
  {
22
19
  transports: ["websocket"],
23
- path: `/${wavoip_token}/websocket`,
24
- forceNew: true,
20
+ path: `/${wavoip_token}/websocket`
25
21
  }
26
22
  );
27
23
 
28
24
  socket.on("connect", () => {
29
- if (logger) console.log("[*] - Wavoip connected", socket.id);
25
+ if (logger) console.log("[Wavoip] - Connected", socket.id);
30
26
 
31
27
  socket.emit(
32
- "init",
28
+ "init",
33
29
  baileys_sock.authState.creds.me,
34
- baileys_sock.authState.creds.account,
35
- baileys_connection_state
30
+ baileys_sock.authState.creds.account,
31
+ status ?? "close",
32
+ softwareBase
36
33
  );
37
34
  });
38
35
 
39
36
  socket.on("disconnect", () => {
40
- if (logger) console.log("[*] - Wavoip disconnect");
37
+ if (logger) console.log("[Wavoip] - Disconnected");
41
38
  });
42
39
 
43
40
  socket.on("connect_error", (error) => {
44
- if (socket.active) {
45
- if (logger)
46
- console.log(
47
- "[*] - Wavoip connection error temporary failure, the socket will automatically try to reconnect",
48
- error
49
- );
50
- } else {
51
- if (logger) console.log("[*] - Wavoip connection error", error.message);
52
- }
41
+ if (logger) console.log("[Wavoip] - Connection lost");
53
42
  });
54
43
 
55
- socket.on("onWhatsApp", async (jid, callback) => {
56
- try {
57
- const response = await baileys_sock.onWhatsApp(jid);
58
-
59
- callback(response);
60
-
61
- if (logger)
62
- console.log("[*] Success on call onWhatsApp function", response, jid);
63
- } catch (error) {
64
- if (logger) console.error("[*] Error on call onWhatsApp function", error);
65
- }
44
+ socket.on("onWhatsApp", (jid, callback) => {
45
+ baileys_sock.onWhatsApp(jid)
46
+ .then((response) => callback(response))
47
+ .catch((error) => {
48
+ callback({wavoipStatus: "error", result: error});
49
+ if (logger) console.log("[Wavoip] - Failed to call onWhatsapp, error: ", error)
50
+ });
66
51
  });
67
52
 
68
53
  socket.on("profilePictureUrl", async (jid, type, timeoutMs, callback) => {
69
- try {
70
- const response = await baileys_sock.profilePictureUrl(
71
- jid,
72
- type,
73
- timeoutMs
74
- );
75
-
76
- callback(response);
77
-
78
- if (logger)
79
- console.log("[*] Success on call profilePictureUrl function", response);
80
- } catch (error) {
81
- if (logger)
82
- console.error("[*] Error on call profilePictureUrl function", error);
83
- }
54
+ baileys_sock.profilePictureUrl(jid, type, timeoutMs)
55
+ .then((response) => callback(response))
56
+ .catch((error) => {
57
+ callback({wavoipStatus: "error", result: error});
58
+ if (logger) console.log("[Wavoip] - Failed to call profilePictureUrl, error: ", error)
59
+ });
84
60
  });
85
61
 
86
62
  socket.on("assertSessions", async (jids, force, callback) => {
87
- try {
88
- const response = await baileys_sock.assertSessions(jids, force);
89
-
90
- callback(response);
91
-
92
- if (logger)
93
- console.log("[*] Success on call assertSessions function", response);
94
- } catch (error) {
95
- if (logger)
96
- console.error("[*] Error on call assertSessions function", error);
97
- }
63
+ baileys_sock.assertSessions(jids, force)
64
+ .then((response) => callback(response))
65
+ .catch((error) => {
66
+ callback({wavoipStatus: "error", result: error});
67
+ if (logger) console.log("[Wavoip] - Failed to call assertSessions, error: ", error)
68
+ });
98
69
  });
99
70
 
100
- socket.on(
101
- "createParticipantNodes",
102
- async (jids, message, extraAttrs, callback) => {
103
- try {
104
- const response = await baileys_sock.createParticipantNodes(
105
- jids,
106
- message,
107
- extraAttrs
108
- );
109
-
110
- callback(response, true);
111
-
112
- if (logger)
113
- console.log(
114
- "[*] Success on call createParticipantNodes function",
115
- response
116
- );
117
- } catch (error) {
118
- if (logger)
119
- console.error(
120
- "[*] Error on call createParticipantNodes function",
121
- error
122
- );
123
- }
124
- }
125
- );
126
-
127
- socket.on(
128
- "getUSyncDevices",
129
- async (jids, useCache, ignoreZeroDevices, callback) => {
130
- try {
131
- const response = await baileys_sock.getUSyncDevices(
132
- jids,
133
- useCache,
134
- ignoreZeroDevices
135
- );
136
-
137
- callback(response);
138
-
139
- if (logger)
140
- console.log("[*] Success on call getUSyncDevices function", response);
141
- } catch (error) {
142
- if (logger)
143
- console.error("[*] Error on call getUSyncDevices function", error);
144
- }
145
- }
146
- );
147
-
148
- socket.on("generateMessageTag", async (callback) => {
149
- try {
150
- const response = await baileys_sock.generateMessageTag();
151
-
152
- callback(response);
153
-
154
- if (logger)
155
- console.log(
156
- "[*] Success on call generateMessageTag function",
157
- response
158
- );
159
- } catch (error) {
160
- if (logger)
161
- console.error("[*] Error on call generateMessageTag function", error);
162
- }
71
+ socket.on("createParticipantNodes", async (jids, message, extraAttrs, callback) => {
72
+ baileys_sock.createParticipantNodes(jids, message, extraAttrs)
73
+ .then((response) => callback(response.nodes, response.shouldIncludeDeviceIdentity))
74
+ .catch((error) => {
75
+ callback({wavoipStatus: "error", result: error});
76
+ if (logger) console.log("[Wavoip] - Failed to call createParticipantNodes, error: ", error)
77
+ });
163
78
  });
164
79
 
165
- socket.on("sendNode", async (stanza, callback) => {
166
- try {
167
- const response = await baileys_sock.sendNode(stanza);
80
+ socket.on("getUSyncDevices", async (jids, useCache, ignoreZeroDevices, callback) => {
81
+ baileys_sock.getUSyncDevices(jids, useCache, ignoreZeroDevices)
82
+ .then((response) => callback(response))
83
+ .catch((error) => {
84
+ callback({wavoipStatus: "error", result: error});
85
+ if (logger) console.log("[Wavoip] - Failed to call createParticipantNodes, error: ", error)
86
+ });
87
+ });
168
88
 
169
- callback(true);
89
+ socket.on("generateMessageTag", (callback) => callback(baileys_sock.generateMessageTag()));
170
90
 
171
- if (logger)
172
- console.log("[*] Success on call sendNode function", response);
173
- } catch (error) {
174
- if (logger) console.error("[*] Error on call sendNode function", error);
175
- }
91
+ socket.on("sendNode", async (stanza, callback) => {
92
+ baileys_sock.sendNode(stanza)
93
+ .then((response) => callback(true))
94
+ .catch((error) => {
95
+ callback({wavoipStatus: "error", result: error});
96
+ if (logger) console.log("[Wavoip] - Failed to call createParticipantNodes, error: ", error)
97
+ });
176
98
  });
177
99
 
178
- socket.on(
179
- "signalRepository:decryptMessage",
180
- async (jid, type, ciphertext, callback) => {
181
- try {
182
- const response = await baileys_sock.signalRepository.decryptMessage({
183
- jid: jid,
184
- type: type,
185
- ciphertext: ciphertext,
186
- });
187
-
188
- callback(response);
189
-
190
- if (logger)
191
- console.log(
192
- "[*] Success on call signalRepository:decryptMessage function",
193
- response
194
- );
195
- } catch (error) {
196
- if (logger)
197
- console.error(
198
- "[*] Error on call signalRepository:decryptMessage function",
199
- error
200
- );
201
- }
202
- }
203
- );
100
+ socket.on("signalRepository:decryptMessage", async (jid, type, ciphertext, callback) => {
101
+ baileys_sock.signalRepository.decryptMessage({jid: jid, type: type, ciphertext: ciphertext})
102
+ .then((response) => callback(response))
103
+ .catch((error) => {
104
+ callback({wavoipStatus: "error", result: error});
105
+ if (logger) console.log("[Wavoip] - Failed to call decryptMessage, error: ", error)
106
+ });
107
+ });
204
108
 
205
- // we only use this connection data to inform the webphone that the device is connected and creeds account to generate e2e whatsapp key for make call packets
206
- baileys_sock.ev.on(
207
- "connection.update",
208
- (update: Partial<ConnectionState>) => {
109
+ baileys_sock.ev.on("connection.update", (update: Partial<ConnectionState>) => {
209
110
  const { connection } = update;
210
111
 
211
112
  if (connection) {
212
- baileys_connection_state = connection;
213
- socket
214
- .timeout(5000)
215
- .emit(
216
- "connection.update:status",
217
- baileys_sock.authState.creds.me,
218
- baileys_sock.authState.creds.account,
219
- connection
220
- );
113
+ console.log(connection)
114
+ socket.timeout(1000).emit("connection.update:status",
115
+ baileys_sock.authState.creds.me,
116
+ baileys_sock.authState.creds.account,
117
+ connection
118
+ );
221
119
  }
222
120
 
223
121
  if (update.qr) {
224
- socket.timeout(5000).emit("connection.update:qr", update.qr);
122
+ socket.timeout(1000).emit("connection.update:qr", update.qr);
225
123
  }
226
124
  }
227
125
  );
228
126
 
229
127
  baileys_sock.ws.on("CB:call", (packet) => {
230
- if (logger) console.log("[*] Signling received");
231
- socket.volatile.timeout(5000).emit("CB:call", packet);
128
+ socket.volatile.timeout(1000).emit("CB:call", packet);
232
129
  });
233
130
 
234
131
  baileys_sock.ws.on("CB:ack,class:call", (packet) => {
235
- if (logger) console.log("[*] Signling ack received");
236
- socket.volatile.timeout(5000).emit("CB:ack,class:call", packet);
132
+ socket.volatile.timeout(1000).emit("CB:ack,class:call", packet);
237
133
  });
238
134
 
239
135
  return socket;
@@ -13,36 +13,41 @@ export interface ServerToClientEvents {
13
13
  }
14
14
 
15
15
  export interface ClientToServerEvents {
16
- "init": (me: Contact | undefined, account: proto.IADVSignedDeviceIdentity | undefined, status: WAConnectionState) => void;
16
+ "init": (me: Contact | undefined, account: proto.IADVSignedDeviceIdentity | undefined, status: WAConnectionState, softwareBase: string) => void;
17
17
  "CB:call": (packet: any) => void;
18
18
  "CB:ack,class:call": (packet: any) => void;
19
19
  "connection.update:status": (me: Contact | undefined, account: proto.IADVSignedDeviceIdentity | undefined, status: WAConnectionState) => void;
20
20
  "connection.update:qr": (qr: string) => void;
21
21
  }
22
22
 
23
+ export type FailedResponseType = {wavoipStatus: string, result: any};
24
+
23
25
  export type onWhatsAppType = (jid: string, callback: onWhatsAppCallback) => void;
24
26
  export type onWhatsAppCallback = (response: {
25
27
  exists: boolean;
26
28
  jid: string;
27
- }[]) => void;
29
+ }[] | FailedResponseType | undefined) => void;
28
30
 
29
31
  export type ProfilePictureUrlType = (jid: string, type: "image" | "preview", timeoutMs: number | undefined, callback: ProfilePictureUrlCallback) => void;
30
- export type ProfilePictureUrlCallback = (response: string | undefined) => void;
32
+ export type ProfilePictureUrlCallback = (response: string | FailedResponseType | undefined) => void;
31
33
 
32
34
  export type AssertSessionsType = (jids: string[], force: boolean, callback: AssertSessionsCallback) => void;
33
- export type AssertSessionsCallback = (response: boolean) => void;
35
+ export type AssertSessionsCallback = (response: boolean | FailedResponseType) => void;
34
36
 
35
37
  export type CreateParticipantNodesType = (jids: string[], message: any, extraAttrs: any, callback: CreateParticipantNodesCallback) => void;
36
- export type CreateParticipantNodesCallback = (nodes: any, shouldIncludeDeviceIdentity: boolean) => void;
38
+ export type CreateParticipantNodesCallback = {
39
+ (nodes: any, shouldIncludeDeviceIdentity: boolean): void;
40
+ (response: FailedResponseType): void;
41
+ }
37
42
 
38
43
  export type GetUSyncDevicesType = (jids: string[], useCache: boolean, ignoreZeroDevices: boolean, callback: GetUSyncDevicesTypeCallback) => void
39
- export type GetUSyncDevicesTypeCallback = (jids: JidWithDevice[]) => void;
44
+ export type GetUSyncDevicesTypeCallback = (jids: JidWithDevice[] | FailedResponseType) => void;
40
45
 
41
46
  export type GenerateMessageTagType = (callback: GenerateMessageTagTypeCallback) => void
42
- export type GenerateMessageTagTypeCallback = (response: string) => void;
47
+ export type GenerateMessageTagTypeCallback = (response: string | FailedResponseType) => void;
43
48
 
44
49
  export type SendNodeType = (stanza: BinaryNode, callback: SendNodeTypeCallback) => void
45
- export type SendNodeTypeCallback = (response: boolean) => void;
50
+ export type SendNodeTypeCallback = (response: boolean | FailedResponseType) => void;
46
51
 
47
52
  export type SignalRepositoryDecryptMessageType = (jid: string, type: "pkmsg" | "msg", ciphertext: Buffer, callback: SignalRepositoryDecryptMessageCallback) => void
48
- export type SignalRepositoryDecryptMessageCallback = (response: any) => void;
53
+ export type SignalRepositoryDecryptMessageCallback = (response: Uint8Array | FailedResponseType) => void;