Try calling websocket plugin

pull/5370/head
ioedeveloper 5 years ago
parent 4e51d00d05
commit 2be4e71d1a
  1. 2
      apps/remix-ide/src/app/files/remixDProvider.js
  2. 2
      apps/remix-ide/src/app/files/remixd-handle.js
  3. 262
      apps/remix-ide/src/lib/remixd.js
  4. 20206
      package-lock.json

@ -61,7 +61,7 @@ module.exports = class RemixDProvider {
} }
async init (cb) { async init (cb) {
const result = await this._appManager.call('remixd', 'folderIsReadOnly', {}) const result = await this._appManager.call('remixdWebsocketPlugin', 'folderIsReadOnly', {})
this._readOnlyMode = result this._readOnlyMode = result
} }

@ -20,6 +20,7 @@ var css = csjs`
const profile = { const profile = {
name: 'remixd', name: 'remixd',
methods: ['folderIsReadOnly'],
description: 'Using Remixd daemon, allow to access file system', description: 'Using Remixd daemon, allow to access file system',
kind: 'other', kind: 'other',
version: packageJson.version version: packageJson.version
@ -31,7 +32,6 @@ export class RemixdHandle extends WebsocketPlugin {
this.fileSystemExplorer = fileSystemExplorer this.fileSystemExplorer = fileSystemExplorer
this.locahostProvider = locahostProvider this.locahostProvider = locahostProvider
this.appManager = appManager this.appManager = appManager
this.methods = ['get']
} }
deactivate () { deactivate () {

@ -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

20206
package-lock.json generated

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save