Prepare electron releases
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { DataSourceState } from './'
|
||||
import { DataSourceStateMachine } from './'
|
||||
|
||||
type MessageCallback = (topic: string, payload: Buffer) => void
|
||||
|
||||
// A DataSource should automatically reconnect if connection was broken
|
||||
interface DataSource<DataSourceOptions> {
|
||||
connect(options: DataSourceOptions): DataSourceState
|
||||
connect(options: DataSourceOptions): DataSourceStateMachine
|
||||
disconnect(): void
|
||||
onMessage(messageCallback: MessageCallback): void
|
||||
topicSeparator: string
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
interface InternalState {
|
||||
import { EventEmitter } from 'events'
|
||||
|
||||
export interface DataSourceState {
|
||||
connecting: boolean
|
||||
connected: boolean
|
||||
error?: Error
|
||||
}
|
||||
|
||||
export class DataSourceState {
|
||||
private state: InternalState = {
|
||||
export class DataSourceStateMachine extends EventEmitter {
|
||||
private state: DataSourceState = {
|
||||
error: undefined,
|
||||
connected: false,
|
||||
connecting: false
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Client, connect as mqttConnect } from 'mqtt'
|
||||
import { DataSource, DataSourceState } from './'
|
||||
import { DataSource, DataSourceStateMachine } from './'
|
||||
|
||||
export interface MqttOptions {
|
||||
url: string
|
||||
@@ -15,8 +15,8 @@ export class MqttSource implements DataSource<MqttOptions> {
|
||||
this.messageCallback = messageCallback
|
||||
}
|
||||
|
||||
public connect(options: MqttOptions): DataSourceState {
|
||||
const state = new DataSourceState()
|
||||
public connect(options: MqttOptions): DataSourceStateMachine {
|
||||
const state = new DataSourceStateMachine()
|
||||
|
||||
const client = mqttConnect(options.url, {
|
||||
resubscribe: false
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { DataSource } from './DataSource'
|
||||
import { DataSourceState } from './DataSourceState'
|
||||
import { DataSourceState, DataSourceStateMachine } from './DataSourceState'
|
||||
import { MqttOptions, MqttSource } from './MqttSource'
|
||||
|
||||
export {
|
||||
DataSource,
|
||||
DataSourceState,
|
||||
DataSourceStateMachine,
|
||||
MqttOptions,
|
||||
MqttSource,
|
||||
}
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
import { Tree, TreeNode } from './Model'
|
||||
|
||||
export class DotExport {
|
||||
public static renderNodeInformation(node: TreeNode): string {
|
||||
return `\t${node.sourceEdge.hash()} [label=${this.renderLabel(node.value)}]`
|
||||
}
|
||||
public static toDot(tree: Tree): string {
|
||||
let i = 1
|
||||
let leaveEdges = Object.values(tree.edges)
|
||||
.map(e => e.node)
|
||||
.map(node => node.leafes())
|
||||
.reduce((a, b) => a.concat(b), [])
|
||||
.map(leave => leave.branch())
|
||||
|
||||
const allEdges: Array<string> = []
|
||||
const nodeInformation: {[s: string]: string} = {}
|
||||
leaveEdges.map(edges => edges.reduce( (prev, current) => {
|
||||
let currentHash = current.sourceEdge.hash()
|
||||
nodeInformation[currentHash] = this.renderNodeInformation(current)
|
||||
if (current && prev) {
|
||||
allEdges.push(`\t${prev.sourceEdge.hash()} -> ${currentHash} [label=${this.renderLabel(current.sourceEdge.name)}]`)
|
||||
}
|
||||
return current
|
||||
}))
|
||||
|
||||
return `strict digraph ethane {
|
||||
${
|
||||
[this.renderNodeInformation(tree)]
|
||||
.concat(Object.values(nodeInformation))
|
||||
.concat(allEdges)
|
||||
.join('\n')
|
||||
}
|
||||
}`;
|
||||
}
|
||||
|
||||
private static renderLabel(value: any): string {
|
||||
let str;
|
||||
if(!isNaN(value)) {
|
||||
str = value
|
||||
} else {
|
||||
str = JSON.stringify(value)
|
||||
if(str && str.length > 0) {
|
||||
str = str.slice(1, -1)
|
||||
}
|
||||
}
|
||||
|
||||
if (!str) {
|
||||
return '""'
|
||||
}
|
||||
|
||||
if(str.length > 20) {
|
||||
str = str.slice(0, 20)+'…'
|
||||
}
|
||||
|
||||
if (str[0] !== '"') {
|
||||
str = `"${str}"`
|
||||
}
|
||||
|
||||
return str
|
||||
}
|
||||
}
|
||||
@@ -3,15 +3,13 @@ import { MqttSource, DataSource } from './DataSource'
|
||||
|
||||
import * as socketIO from 'socket.io'
|
||||
|
||||
const server = require('http').createServer();
|
||||
|
||||
let tree = new Tree()
|
||||
const http = require('http')
|
||||
let options = {url: 'mqtt://nodered'}
|
||||
let dataSource = new MqttSource()
|
||||
let count = 200
|
||||
|
||||
const a: Array<any> = []
|
||||
|
||||
const server = http.createServer()
|
||||
const io = socketIO(server)
|
||||
io.on('connection', client => {
|
||||
console.log('connection')
|
||||
|
||||
Reference in New Issue
Block a user