Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/cruds/stream_messages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { ApolloClient } from "apollo-client";
import gql from "graphql-tag";

export class STREAM_MESSAGES {
public fetching: boolean;
private _client: ApolloClient<any>;
private _socket;

constructor(client, socket) {
this._client = client;
this._socket = socket;
}

send(agentId: number, body: string, metadata: any = {}): Promise<any> {
const QUERY_FUNTCION = "sendAgentStreamMessage";

const MUTATION = gql`
mutation ${QUERY_FUNTCION}($postMessage: SendAgentStreamMessageInput!) {
${QUERY_FUNTCION}(input: $postMessage) {
clientMutationId
success
}
}
`;

const postMessage = {
clientMutationId: "not_used",
agentId,
body,
metadata,
};

return this._client
.mutate({
mutation: MUTATION,
variables: { postMessage },
})
.then((response) => response.data[QUERY_FUNTCION])
.catch((e) => {
console.log(e);
return e;
});
}
}
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import fetch from "node-fetch";
import { SYSTEMLOGS } from "./cruds/system_logs";
import { USERACCOUNT } from "./cruds/userAccounts";
import { MAPOBJECTS } from "./cruds/map_objects";
import { STREAM_MESSAGES } from "./cruds/stream_messages";
import { INSTANT_ACTIONS } from "./cruds/instant_actions";
import { MISSIONQUEUE } from "./cruds/mission_queue";
import { AGENTS_INTERCONNECTIONS } from "./cruds/tools_interconnections";
Expand Down Expand Up @@ -53,6 +54,7 @@ export class HelyosServices {
mapObjects: MAPOBJECTS;
agents: AGENTS;
yard: YARD;
streamMessages: STREAM_MESSAGES;
instantActions: INSTANT_ACTIONS;
systemLogs: SYSTEMLOGS;
assignments: ASSIGNMENT;
Expand Down Expand Up @@ -116,6 +118,7 @@ export class HelyosServices {
if (this.connected) {
this.mapObjects = new MAPOBJECTS(this._client, this.socket);
this.userAccounts = new USERACCOUNT(this._client, this.socket);
this.streamMessages = new STREAM_MESSAGES(this._client, this.socket);
this.instantActions = new INSTANT_ACTIONS(this._client, this.socket);
this.agents = new AGENTS(this._client, this.socket);
this.missionQueue = new MISSIONQUEUE(this._client, this.socket);
Expand Down