12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- import { Strophe } from 'strophe.js';
-
- import Listenable from '../util/Listenable';
-
- /* eslint-disable no-empty-function */
-
- /**
- * Mock {@link ChatRoom}.
- */
- export class MockChatRoom {
- /**
- * {@link ChatRoom.addPresenceListener}.
- */
- addPresenceListener() {
- }
- }
-
- /**
- * Mock Strophe connection.
- */
- export class MockStropheConnection extends Listenable {
- /**
- * A constructor...
- */
- constructor() {
- super();
- this.sentIQs = [];
- this._proto = {
- socket: undefined
- };
- }
-
- /**
- * XMPP service URL.
- *
- * @returns {string}
- */
- get service() {
- return 'wss://localhost/xmpp-websocket';
- }
-
- /**
- * {@see Strophe.Connection.connect}
- */
- connect(jid, pass, callback) {
- this._connectCb = callback;
- }
-
- /**
- * {@see Strophe.Connection.disconnect}
- */
- disconnect() {
- this.simulateConnectionState(Strophe.Status.DISCONNECTING);
- this.simulateConnectionState(Strophe.Status.DISCONNECTED);
- }
-
- /**
- * Simulates transition to the new connection status.
- *
- * @param {Strophe.Status} newState - The new connection status to set.
- * @returns {void}
- */
- simulateConnectionState(newState) {
- if (newState === Strophe.Status.CONNECTED) {
- this._proto.socket = {
- readyState: WebSocket.OPEN
- };
- } else {
- this._proto.socket = undefined;
- }
- this._connectCb(newState);
- }
-
- /**
- * {@see Strophe.Connection.sendIQ}.
- */
- sendIQ(iq, resultCb) {
- this.sentIQs.push(iq);
- resultCb && resultCb();
- }
- }
- /* eslint-enable no-empty-function */
|