UNPKG

substance

Version:

Substance is a JavaScript library for web-based content editing. It provides building blocks for realizing custom text editors and web-based publishing systems.

51 lines (40 loc) 972 B
import EventEmitter from '../../util/EventEmitter' var __id__ = 0 /** Simple TestServerWebSocket implementation for local testing */ class TestServerWebSocket extends EventEmitter { constructor(messageQueue, serverId, clientId) { super() this.__id__ = __id__++ this.messageQueue = messageQueue this.serverId = serverId this.clientId = clientId this._isSimulated = true this.readyState = 1; // consider always connected } connect() { this.messageQueue.connectServerSocket(this) } /** Gets called by the message queue to handle a message */ _onMessage(data) { this.emit('message', data) } /** Gets called by the message queue to handle a message */ send(data) { var msg = { from: this.serverId, to: this.clientId } if (data) { // msg.data = JSON.parse(data) msg.data = data } this.messageQueue.pushMessage(msg) } } export default TestServerWebSocket