-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
69 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -204,33 +204,44 @@ xmpp.on("offline", () => { | |
Starts the connection. Attempts to reconnect will automatically happen if it cannot connect or gets disconnected. | ||
|
||
```js | ||
xmpp.start().catch(console.error); | ||
xmpp.on("online", (address) => { | ||
console.log("online", address.toString()); | ||
}); | ||
await xmpp.start(); | ||
``` | ||
|
||
Returns a promise that resolves if the first attempt succeed or rejects if the first attempt fails. | ||
|
||
### stop | ||
|
||
Stops the connection and prevent any further auto reconnect/retry. | ||
Stops the connection and prevent any further auto reconnect. | ||
|
||
```js | ||
xmpp.stop().catch(console.error); | ||
xmpp.on("offline", () => { | ||
console.log("offline"); | ||
}); | ||
await xmpp.stop(); | ||
``` | ||
|
||
Returns a promise that resolves once the stream closes and the socket disconnects. | ||
|
||
### disconnect | ||
|
||
Like [`stop`](#stop) but will not prevent auto reconnect. | ||
|
||
```js | ||
xmpp.on("disconnect", () => { | ||
console.log("disconnect"); | ||
}); | ||
await xmpp.disconnect(); | ||
``` | ||
|
||
### send | ||
|
||
Sends a stanza. | ||
|
||
```js | ||
xmpp.send(xml("presence")).catch(console.error); | ||
await xmpp.send(xml("presence")); | ||
``` | ||
|
||
Returns a promise that resolves once the stanza is serialized and written to the socket or rejects if any of those fails. | ||
|
@@ -247,7 +258,7 @@ const recipients = ["[email protected]", "[email protected]"]; | |
const stanzas = recipients.map((address) => | ||
xml("message", { to: address, type: "chat" }, xml("body", null, message)), | ||
); | ||
xmpp.sendMany(stanzas).catch(console.error); | ||
await xmpp.sendMany(stanzas); | ||
``` | ||
|
||
Returns a promise that resolves once all the stanzas have been sent. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,23 +170,34 @@ xmpp.on("offline", () => { | |
Starts the connection. Attempts to reconnect will automatically happen if it cannot connect or gets disconnected. | ||
|
||
```js | ||
xmpp.start().catch(console.error); | ||
xmpp.on("online", (address) => { | ||
console.log("online", address.toString()); | ||
}); | ||
await xmpp.start(); | ||
``` | ||
|
||
Returns a promise that resolves if the first attempt succeed or rejects if the first attempt fails. | ||
|
||
### stop | ||
|
||
Stops the connection and prevent any further auto reconnect/retry. | ||
Stops the connection and prevent any further auto reconnect. | ||
|
||
```js | ||
xmpp.stop().catch(console.error); | ||
xmpp.on("offline", () => { | ||
console.log("offline"); | ||
}); | ||
await xmpp.stop(); | ||
``` | ||
|
||
### disconnect | ||
|
||
Like [`stop`](#stop) but will not prevent auto reconnect. | ||
|
||
```js | ||
xmpp.on("disconnect", () => { | ||
console.log("disconnect"); | ||
}); | ||
await xmpp.disconnect(); | ||
``` | ||
|
||
Returns a promise that resolves once the stream closes and the socket disconnects. | ||
|
@@ -196,7 +207,7 @@ Returns a promise that resolves once the stream closes and the socket disconnect | |
Sends a stanza. | ||
|
||
```js | ||
xmpp.send(xml("presence")).catch(console.error); | ||
await xmpp.send(xml("presence")); | ||
``` | ||
|
||
Returns a promise that resolves once the stanza is serialized and written to the socket or rejects if any of those fails. | ||
|
@@ -213,7 +224,7 @@ const recipients = ["[email protected]", "[email protected]"]; | |
const stanzas = recipients.map((address) => | ||
xml("message", { to: address, type: "chat" }, xml("body", null, message)), | ||
); | ||
xmpp.sendMany(stanzas).catch(console.error); | ||
await xmpp.sendMany(stanzas); | ||
``` | ||
|
||
Returns a promise that resolves once all the stanzas have been sent. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
import Connection from "../index.js"; | ||
import { EventEmitter } from "@xmpp/events"; | ||
|
||
test("calls _reset and _status", () => { | ||
test("calls _detachSocket and _status", () => { | ||
expect.assertions(3); | ||
const conn = new Connection(); | ||
const sock = new EventEmitter(); | ||
conn._attachSocket(sock); | ||
|
||
const evt = {}; | ||
conn._status = (status, { clean, event }) => { | ||
conn._status = (status, { clean, reason }) => { | ||
expect(clean).toBe(false); | ||
expect(event).toBe(evt); | ||
expect(reason).toBe(evt); | ||
}; | ||
|
||
const spy_reset = jest.spyOn(conn, "_reset"); | ||
const spy_detachSocket = jest.spyOn(conn, "_detachSocket"); | ||
|
||
sock.emit("close", true, evt); | ||
|
||
expect(spy_reset).toHaveBeenCalled(); | ||
expect(spy_detachSocket).toHaveBeenCalled(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.