Revert "Resolved merge conflict"

This reverts commit 2ddb2d7460fd16f57c3951fa4d7f37140067bf41.
pull/11/head
ioedeveloper 4 years ago
parent 4e9ca72c4c
commit 30df8424e8
  1. 262
      apps/remix-ide/src/lib/remixd.js
  2. 18
      package-lock.json

@ -1,145 +1,145 @@
'use strict' // 'use strict'
var EventManager = require('../lib/events') // var EventManager = require('../lib/events')
var modalDialog = require('../app/ui/modaldialog') // var modalDialog = require('../app/ui/modaldialog')
var yo = require('yo-yo') // var yo = require('yo-yo')
class Remixd { // class Remixd {
constructor (port) { // constructor (port) {
this.event = new EventManager() // this.event = new EventManager()
this.port = port // this.port = port
this.callbacks = {} // this.callbacks = {}
this.callid = 0 // this.callid = 0
this.socket = null // this.socket = null
this.connected = false // this.connected = false
this.receiveResponse() // this.receiveResponse()
} // }
online () { // online () {
return this.socket !== null // return this.socket !== null
} // }
close () { // close () {
if (this.socket) { // if (this.socket) {
this.socket.close() // this.socket.close()
this.socket = null // this.socket = null
} // }
} // }
start (cb) { // start (cb) {
if (this.socket) { // if (this.socket) {
try { // try {
this.socket.close() // this.socket.close()
} catch (e) {} // } catch (e) {}
} // }
this.event.trigger('connecting', []) // this.event.trigger('connecting', [])
this.socket = new WebSocket('ws://localhost:' + this.port, 'echo-protocol') // eslint-disable-line // this.socket = new WebSocket('ws://localhost:' + this.port, 'echo-protocol') // eslint-disable-line
this.socket.addEventListener('open', (event) => { // this.socket.addEventListener('open', (event) => {
this.connected = true // this.connected = true
this.event.trigger('connected', [event]) // this.event.trigger('connected', [event])
cb() // cb()
}) // })
this.socket.addEventListener('message', (event) => { // this.socket.addEventListener('message', (event) => {
var data = JSON.parse(event.data) // var data = JSON.parse(event.data)
if (data.type === 'reply') { // if (data.type === 'reply') {
if (this.callbacks[data.id]) { // if (this.callbacks[data.id]) {
this.callbacks[data.id](data.error, data.result) // this.callbacks[data.id](data.error, data.result)
delete this.callbacks[data.id] // delete this.callbacks[data.id]
} // }
this.event.trigger('replied', [data]) // this.event.trigger('replied', [data])
} else if (data.type === 'notification') { // } else if (data.type === 'notification') {
this.event.trigger('notified', [data]) // this.event.trigger('notified', [data])
} else if (data.type === 'system') { // } else if (data.type === 'system') {
if (data.error) { // if (data.error) {
this.event.trigger('system', [{ // this.event.trigger('system', [{
error: data.error // error: data.error
}]) // }])
} // }
} // }
}) // })
this.socket.addEventListener('error', (event) => { // this.socket.addEventListener('error', (event) => {
this.errored(event) // this.errored(event)
cb(event) // cb(event)
}) // })
this.socket.addEventListener('close', (event) => { // this.socket.addEventListener('close', (event) => {
if (event.wasClean) { // if (event.wasClean) {
this.connected = false // this.connected = false
this.event.trigger('closed', [event]) // this.event.trigger('closed', [event])
} else { // } else {
this.errored(event) // this.errored(event)
} // }
this.socket = null // this.socket = null
}) // })
} // }
async receiveResponse (requestId) { // async receiveResponse (requestId) {
return new Promise((resolve, reject) => { // return new Promise((resolve, reject) => {
this.event.register('replied', (data) => { // this.event.register('replied', (data) => {
if (data.id === requestId) { // if (data.id === requestId) {
if (data.error) reject(data.error) // if (data.error) reject(data.error)
else resolve(data.result) // else resolve(data.result)
} // }
}) // })
}) // })
} // }
errored (event) { // errored (event) {
function remixdDialog () { // function remixdDialog () {
return yo`<div>Connection to Remixd closed. Localhost connection not available anymore.</div>` // return yo`<div>Connection to Remixd closed. Localhost connection not available anymore.</div>`
} // }
if (this.connected) { // if (this.connected) {
modalDialog('Lost connection to Remixd!', remixdDialog(), {}, {label: ''}) // modalDialog('Lost connection to Remixd!', remixdDialog(), {}, {label: ''})
} // }
this.connected = false // this.connected = false
this.socket = null // this.socket = null
this.event.trigger('errored', [event]) // this.event.trigger('errored', [event])
} // }
call (service, fn, args, callback) { // call (service, fn, args, callback) {
return new Promise((resolve, reject) => { // return new Promise((resolve, reject) => {
this.ensureSocket((error) => { // this.ensureSocket((error) => {
if (error) { // if (error) {
callback && typeof callback === 'function' && callback(error) // callback && typeof callback === 'function' && callback(error)
reject(error) // reject(error)
return // return
} // }
if (this.socket && this.socket.readyState === this.socket.OPEN) { // if (this.socket && this.socket.readyState === this.socket.OPEN) {
var data = this.format(service, fn, args) // var data = this.format(service, fn, args)
this.callbacks[data.id] = callback // this.callbacks[data.id] = callback
this.socket.send(JSON.stringify(data)) // this.socket.send(JSON.stringify(data))
resolve(data.id) // resolve(data.id)
} else { // } else {
callback && typeof callback === 'function' && callback('Socket not ready. state:' + this.socket.readyState) // callback && typeof callback === 'function' && callback('Socket not ready. state:' + this.socket.readyState)
reject('Socket not ready. state:' + this.socket.readyState) // reject('Socket not ready. state:' + this.socket.readyState)
} // }
}) // })
}) // })
} // }
ensureSocket (cb) { // ensureSocket (cb) {
if (this.socket) return cb(null, this.socket) // if (this.socket) return cb(null, this.socket)
this.start((error) => { // this.start((error) => {
if (error) { // if (error) {
cb(error) // cb(error)
} else { // } else {
cb(null, this.socket) // cb(null, this.socket)
} // }
}) // })
} // }
format (service, fn, args) { // format (service, fn, args) {
var data = { // var data = {
id: this.callid, // id: this.callid,
service: service, // service: service,
fn: fn, // fn: fn,
args: args // args: args
} // }
this.callid++ // this.callid++
return data // return data
} // }
} // }
module.exports = Remixd // module.exports = Remixd

18
package-lock.json generated

@ -3841,9 +3841,9 @@
"dev": true "dev": true
}, },
"compare-func": { "compare-func": {
"version": "1.3.2", "version": "1.3.4",
"resolved": "https://registry.npmjs.org/compare-func/-/compare-func-1.3.2.tgz", "resolved": "https://registry.npmjs.org/compare-func/-/compare-func-1.3.4.tgz",
"integrity": "sha1-md0LpFfh+bxyKxLAjsM+6rMfpkg=", "integrity": "sha512-sq2sWtrqKPkEXAC8tEJA1+BqAH9GbFkGBtUOqrUX57VSfwp8xyktctk+uLoRy5eccTdxzDcVIztlYDpKs3Jv1Q==",
"dev": true, "dev": true,
"requires": { "requires": {
"array-ify": "^1.0.0", "array-ify": "^1.0.0",
@ -8213,9 +8213,9 @@
"dev": true "dev": true
}, },
"uglify-js": { "uglify-js": {
"version": "3.9.2", "version": "3.9.4",
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.9.2.tgz", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.9.4.tgz",
"integrity": "sha512-zGVwKslUAD/EeqOrD1nQaBmXIHl1Vw371we8cvS8I6mYK9rmgX5tv8AAeJdfsQ3Kk5mGax2SVV/AizxdNGhl7Q==", "integrity": "sha512-8RZBJq5smLOa7KslsNsVcSH+KOXf1uDU8yqLeNuVKwmT0T3FA0ZoXlinQfRad7SDcbZZRZE4ov+2v71EnxNyCA==",
"dev": true, "dev": true,
"optional": true, "optional": true,
"requires": { "requires": {
@ -11072,9 +11072,9 @@
} }
}, },
"moment": { "moment": {
"version": "2.25.3", "version": "2.26.0",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.25.3.tgz", "resolved": "https://registry.npmjs.org/moment/-/moment-2.26.0.tgz",
"integrity": "sha512-PuYv0PHxZvzc15Sp8ybUCoQ+xpyPWvjOuK72a5ovzp2LI32rJXOiIfyoFoYvG3s6EwwrdkMyWuRiEHSZRLJNdg==", "integrity": "sha512-oIixUO+OamkUkwjhAVE18rAMfRJNsNe/Stid/gwHSOfHrOtw9EhAY2AHvdKZ/k/MggcYELFCJz/Sn2pL8b8JMw==",
"dev": true "dev": true
}, },
"morphdom": { "morphdom": {

Loading…
Cancel
Save