forked from brunnolou/Cockpit-Real-time-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
83 additions
and
49 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
const store = require('../store'); | ||
const events = require('../events'); | ||
|
||
function Broadcast(action = 'updated', data) { | ||
function Broadcast(event, data) { | ||
const connections = Object.values(store.activeConnections); | ||
|
||
connections.forEach(({ connection }) => { | ||
try { | ||
const obj = JSON.stringify({ action, data }); | ||
console.log('obj: ', obj); | ||
if (!Object.values(events).includes(event)) return console.log('Invalid event:', event); | ||
|
||
connection.sendUTF(obj); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
connections.forEach(({ connection, id }) => { | ||
if (!connection) return; | ||
|
||
connection.send(JSON.stringify({ event, data })); | ||
|
||
console.log('Broadcasted event: ', id, event); | ||
}); | ||
|
||
return Object.keys(store.activeConnections); | ||
} | ||
|
||
module.exports = Broadcast; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
CONNECT: 'connect', | ||
REGIONS_SAVE_AFTER: 'regions.save.after', | ||
REGIONS_REMOVE_AFTER: 'regions.remove.after', | ||
COLLECTIONS_SAVE_AFTER: 'collections.save.after', | ||
COLLECTIONS_REMOVE_AFTER: 'collections.remove.after', | ||
COLLECTIONS_PREVIEW: 'cockpit:collections.preview', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
const webSocketServer = require('./webSocketServer'); | ||
const webServer = require('./webServer'); | ||
|
||
// Start web server | ||
const httpServer = webServer(); | ||
|
||
// Start Sockets server | ||
webSocketServer(httpServer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
// WebHook | ||
const WebHook = { | ||
event: 'collections.save.after', | ||
hook: 'requestb', | ||
backend: 1, | ||
args: [ | ||
'portfolio', | ||
{ | ||
title: 'Project Ones', | ||
description: 'clodsmcaoidnc ', | ||
title_slug: 'project-ones', | ||
_mby: '5a3bf33ab5262doc1197003155', | ||
_by: '5a3bf33ab5262doc1197003155', | ||
_modified: 1513948857, | ||
_created: 1513878440, | ||
_id: '5a3bf3a810d59doc1957272294', | ||
published: true, | ||
}, | ||
true, | ||
], | ||
}; | ||
|
||
// WebSocket | ||
const WebSocket = { | ||
event: 'cockpit:collections.preview', | ||
entry: { | ||
title: 'This is supper fast!!', | ||
description: 'Oi', | ||
published: true, | ||
title_slug: 'this-is-supper-fast', | ||
_mby: '5a3bf33ab5262doc1197003155', | ||
_by: '5a3bf33ab5262doc1197003155', | ||
_modified: 1514387407, | ||
_created: 1513881601, | ||
_id: '5a3c00012dad9doc1289733293', | ||
}, | ||
lang: 'default', | ||
}; | ||
|
||
console.log('WebHook: ', WebHook); | ||
console.log('WebSocket: ', WebSocket); |