Added messages
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
const { ApolloServer, gql, PubSub } = require("apollo-server");
|
const { ApolloServer, gql, PubSub } = require("apollo-server");
|
||||||
const Indi = require("@atoy40/indijs");
|
const Indi = require("@atoy40/indijs");
|
||||||
|
const fs = require("fs");
|
||||||
|
|
||||||
const IndiDriverInterface = Indi.IndiDriverInterface;
|
const IndiDriverInterface = Indi.IndiDriverInterface;
|
||||||
|
|
||||||
@@ -115,7 +116,7 @@ const typeDefs = gql`
|
|||||||
type LightValue {
|
type LightValue {
|
||||||
name: String!
|
name: String!
|
||||||
label: String
|
label: String
|
||||||
value: String
|
value: Int
|
||||||
}
|
}
|
||||||
|
|
||||||
type Device {
|
type Device {
|
||||||
@@ -126,6 +127,12 @@ const typeDefs = gql`
|
|||||||
connected: Boolean
|
connected: Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Message {
|
||||||
|
id: String
|
||||||
|
device: Device!
|
||||||
|
message: String!
|
||||||
|
}
|
||||||
|
|
||||||
input NumberValueInput {
|
input NumberValueInput {
|
||||||
name: String!
|
name: String!
|
||||||
value: Float!
|
value: Float!
|
||||||
@@ -155,6 +162,13 @@ const typeDefs = gql`
|
|||||||
values: [SwitchValueInput!]!
|
values: [SwitchValueInput!]!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input OneTextInput {
|
||||||
|
device: String!
|
||||||
|
property: String!
|
||||||
|
name: String!
|
||||||
|
value: String!
|
||||||
|
}
|
||||||
|
|
||||||
type Query {
|
type Query {
|
||||||
connected: Boolean
|
connected: Boolean
|
||||||
devices: [Device]
|
devices: [Device]
|
||||||
@@ -167,6 +181,7 @@ const typeDefs = gql`
|
|||||||
newDevice: Device
|
newDevice: Device
|
||||||
newProperty: Property
|
newProperty: Property
|
||||||
newValue: Vector
|
newValue: Vector
|
||||||
|
newMessage: Message
|
||||||
}
|
}
|
||||||
|
|
||||||
type Mutation {
|
type Mutation {
|
||||||
@@ -176,6 +191,7 @@ const typeDefs = gql`
|
|||||||
sendOneNumber(input: OneNumberInput!): Boolean
|
sendOneNumber(input: OneNumberInput!): Boolean
|
||||||
sendNumber(input: NumberInput!): Boolean
|
sendNumber(input: NumberInput!): Boolean
|
||||||
sendSwitch(input: SwitchInput!): Boolean
|
sendSwitch(input: SwitchInput!): Boolean
|
||||||
|
sendOneText(input: OneTextInput!): Boolean
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@@ -194,7 +210,6 @@ indi
|
|||||||
pubsub.publish(["NEW_DEVICE"], { newDevice: device });
|
pubsub.publish(["NEW_DEVICE"], { newDevice: device });
|
||||||
})
|
})
|
||||||
.on("newProperty", (property) => {
|
.on("newProperty", (property) => {
|
||||||
console.log("new props "+property.getName())
|
|
||||||
if (
|
if (
|
||||||
property.getType() === Indi.PropertyType.Number ||
|
property.getType() === Indi.PropertyType.Number ||
|
||||||
property.getType() === Indi.PropertyType.Switch ||
|
property.getType() === Indi.PropertyType.Switch ||
|
||||||
@@ -209,7 +224,6 @@ indi
|
|||||||
})
|
})
|
||||||
.on("newSwitch", (s) => {
|
.on("newSwitch", (s) => {
|
||||||
pubsub.publish(["NEW_VALUE"], { newValue: s });
|
pubsub.publish(["NEW_VALUE"], { newValue: s });
|
||||||
console.log(s);
|
|
||||||
})
|
})
|
||||||
.on("newText", (t) => {
|
.on("newText", (t) => {
|
||||||
pubsub.publish(["NEW_VALUE"], { newValue: t });
|
pubsub.publish(["NEW_VALUE"], { newValue: t });
|
||||||
@@ -217,14 +231,26 @@ indi
|
|||||||
.on("newLight", (l) => {
|
.on("newLight", (l) => {
|
||||||
pubsub.publish(["NEW_VALUE"], { newValue: l });
|
pubsub.publish(["NEW_VALUE"], { newValue: l });
|
||||||
})
|
})
|
||||||
.on("newBlob", (b) => {
|
.on("newBLOB", (b) => {
|
||||||
console.log("new blob");
|
console.log("new blob " + b.length);
|
||||||
|
fs.writeFile("test.fits", b, (err) => {
|
||||||
|
if (err) {
|
||||||
|
console.log("unable to save buffer");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log("test.fits saved");
|
||||||
|
});
|
||||||
//pubsub.publish(["NEW_BLOB"], { newValue: l });
|
//pubsub.publish(["NEW_BLOB"], { newValue: l });
|
||||||
})
|
})
|
||||||
.on("newMessage", (device, id) => {
|
.on("newMessage", (device, id) => {
|
||||||
console.log(device.getDeviceName());
|
|
||||||
console.log(device.messageQueue(id));
|
console.log(device.messageQueue(id));
|
||||||
//pubsub.publish(["NEW_VALUE"], { newValue: l });
|
pubsub.publish(["NEW_MESSAGE"], {
|
||||||
|
newMessage: {
|
||||||
|
id: device.getDeviceName() + "." + id,
|
||||||
|
device,
|
||||||
|
message: device.messageQueue(id),
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Resolvers
|
// Resolvers
|
||||||
@@ -271,7 +297,6 @@ const resolvers = {
|
|||||||
.catch(() => false);
|
.catch(() => false);
|
||||||
},
|
},
|
||||||
sendOneNumber(_, { input: { device, property, name, value } }) {
|
sendOneNumber(_, { input: { device, property, name, value } }) {
|
||||||
console.log(value);
|
|
||||||
return indi
|
return indi
|
||||||
.sendNewNumber(device, property, name, value)
|
.sendNewNumber(device, property, name, value)
|
||||||
.then(() => true)
|
.then(() => true)
|
||||||
@@ -288,10 +313,6 @@ const resolvers = {
|
|||||||
const vector = props.getValue();
|
const vector = props.getValue();
|
||||||
|
|
||||||
for (let i = 0; i < vector.values.length; i++) {
|
for (let i = 0; i < vector.values.length; i++) {
|
||||||
/*console.log(vector.values[i].name);
|
|
||||||
console.log(vector.values[i].value);
|
|
||||||
console.log(values[i].name);
|
|
||||||
console.log(values[i].value);*/
|
|
||||||
vector.values[i].value = values[i].value;
|
vector.values[i].value = values[i].value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,6 +321,12 @@ const resolvers = {
|
|||||||
.then(() => true)
|
.then(() => true)
|
||||||
.catch(() => false);
|
.catch(() => false);
|
||||||
},
|
},
|
||||||
|
sendOneText(_, { input: { device, property, name, value } }) {
|
||||||
|
return indi
|
||||||
|
.sendNewText(device, property, name, value)
|
||||||
|
.then(() => true)
|
||||||
|
.catch(() => false);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
Subscription: {
|
Subscription: {
|
||||||
@@ -318,6 +345,9 @@ const resolvers = {
|
|||||||
newValue: {
|
newValue: {
|
||||||
subscribe: () => pubsub.asyncIterator(["NEW_VALUE"]),
|
subscribe: () => pubsub.asyncIterator(["NEW_VALUE"]),
|
||||||
},
|
},
|
||||||
|
newMessage: {
|
||||||
|
subscribe: () => pubsub.asyncIterator(["NEW_MESSAGE"]),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
Device: {
|
Device: {
|
||||||
@@ -358,7 +388,7 @@ const resolvers = {
|
|||||||
},
|
},
|
||||||
permission(property) {
|
permission(property) {
|
||||||
return property.getPermission();
|
return property.getPermission();
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
Vector: {
|
Vector: {
|
||||||
|
|||||||
Reference in New Issue
Block a user