Skip to content
Browse files

Parse on message

  • Loading branch information...
1 parent 5f89df3 commit 362ece0ad49adc53467b9071d3446e34d73338c5 Case committed
Showing with 28 additions and 19 deletions.
  1. +28 −19 growl_server.js
View
47 growl_server.js
@@ -3,23 +3,32 @@ var server = dgram.createSocket('udp4');
var Binary = require('binary');
var exec = require('child_process').exec;
-Binary.stream(server, "message")
- .word8('ver')
- .word8('type')
- .word16bu('flags')
- .word16bu('notlen')
- .word16bu('titlen')
- .word16bu('desclen')
- .word16bu('applen')
- .buffer('notbuf', 'notlen')
- .buffer('titbuf', 'titlen')
- .buffer('descbuf', 'desclen')
- .buffer('appbuf', 'applen')
- .tap(function(vars) {
- var notification = vars.notbuf.toString('UTF8');
- var title = vars.titbuf.toString('UTF8');
- var description = vars.descbuf.toString('UTF8');
- var application = vars.appbuf.toString('UTF8');
- exec('notify-send "' + title + '" "' + description + '"');
- });
+server.on('message', function(buf) {
+ Binary.parse(buf)
+ .word8('ver')
+ .word8('type')
+ .tap(function(vars) {
+ if (vars.type === 1) {
+ this
+ .word16bu('flags')
+ .word16bu('notlen')
+ .word16bu('titlen')
+ .word16bu('desclen')
+ .word16bu('applen')
+ .buffer('notbuf', 'notlen')
+ .buffer('titbuf', 'titlen')
+ .buffer('descbuf', 'desclen')
+ .buffer('appbuf', 'applen')
+ .buffer('mdf', 16)
+ .tap(function(vars) {
+ var notification = vars.notbuf.toString('UTF8');
+ var title = vars.titbuf.toString('UTF8');
+ var description = vars.descbuf.toString('UTF8');
+ var application = vars.appbuf.toString('UTF8');
+
+ exec('notify-send "' + title + '" "' + description + '"');
+ })
+ }
+ });
+});
server.bind(9887);

0 comments on commit 362ece0

Please sign in to comment.
Something went wrong with that request. Please try again.