1
1
mirror of https://github.com/n8n-io/n8n.git synced 2024-09-20 09:27:44 +03:00

Add SSE Trigger-Node

This commit is contained in:
Jan Oberhauser 2019-12-31 19:03:46 -06:00
parent 8f25303928
commit 23985dbcb2
3 changed files with 62 additions and 0 deletions

View File

@ -33,6 +33,7 @@ import {
faCogs,
faClone,
faCloud,
faCloudDownloadAlt,
faCopy,
faCut,
faDotCircle,
@ -106,6 +107,7 @@ library.add(faCog);
library.add(faCogs);
library.add(faClone);
library.add(faCloud);
library.add(faCloudDownloadAlt);
library.add(faCopy);
library.add(faCut);
library.add(faDotCircle);

View File

@ -0,0 +1,57 @@
import * as EventSource from 'eventsource';
import { ITriggerFunctions } from 'n8n-core';
import {
INodeType,
INodeTypeDescription,
ITriggerResponse,
} from 'n8n-workflow';
export class SseTrigger implements INodeType {
description: INodeTypeDescription = {
displayName: 'SSE Trigger',
name: 'sseTrigger',
icon: 'fa:cloud-download-alt',
group: ['trigger'],
version: 1,
description: 'Triggers worklfow on a new Server-Sent Event',
defaults: {
name: 'SSE Trigger',
color: '#225577',
},
inputs: [],
outputs: ['main'],
properties: [
{
displayName: 'URL',
name: 'url',
type: 'string',
default: '',
placeholder: 'http://example.com',
description: 'The URL to receive the SSE from.',
required: true,
},
]
};
async trigger(this: ITriggerFunctions): Promise<ITriggerResponse> {
const url = this.getNodeParameter('url') as string;
const eventSource = new EventSource(url);
eventSource.onmessage = (event) => {
const eventData = JSON.parse(event.data);
this.emit([this.helpers.returnJsonArray([eventData])]);
};
async function closeFunction() {
eventSource.close();
}
return {
closeFunction,
};
}
}

View File

@ -143,6 +143,7 @@
"dist/nodes/RenameKeys.node.js",
"dist/nodes/RssFeedRead.node.js",
"dist/nodes/Set.node.js",
"dist/nodes/SseTrigger.node.js",
"dist/nodes/SplitInBatches.node.js",
"dist/nodes/Slack/Slack.node.js",
"dist/nodes/SpreadsheetFile.node.js",
@ -172,6 +173,7 @@
"@types/basic-auth": "^1.1.2",
"@types/cheerio": "^0.22.15",
"@types/cron": "^1.6.1",
"@types/eventsource": "^1.1.2",
"@types/express": "^4.16.1",
"@types/gm": "^1.18.2",
"@types/imap-simple": "^4.2.0",
@ -195,6 +197,7 @@
"basic-auth": "^2.0.1",
"cheerio": "^1.0.0-rc.3",
"cron": "^1.7.2",
"eventsource": "^1.0.7",
"glob-promise": "^3.4.0",
"gm": "^1.23.1",
"googleapis": "^46.0.0",