ais-stream-decoder
    TypeScript icon, indicating that this package has built-in type declarations

    2.1.2 • Public • Published

    AIS Stream Decoder

    AIS/NMEA decoder with native stream interface for Node.js.

    NPM Version CI Tests

    Installation

    This is a Node.js module available through the npm registry.

    Installation is done using the npm install command:

    $ npm install ais-stream-decoder

    Features

    • Currently supports message types 1,2,3,4,5,18,24 (more to come) and partially supports message type 8 (inland static and voyage data)
    • Handles multi-part messages out of the box
    • Streaming API implemented as a Node.js transform stream
    • Returns nicely formatted JSON messages
    • Written in TypeScript

    Usage

    Decode a single line of data:

    import AisDecoder from 'ais-stream-decoder';
    
    const aisDecoder = new AisDecoder();
    aisDecoder.on('error', err => console.error(err));
    aisDecoder.on('data', decodedMessage => console.log(decodedMessage));
    
    const nmea = '!AIVDM,1,1,,B,133i;RPP1DPEbcDMV@1r:Ow:2>`<,0*41';
    aisDecoder.write(nmea);

    =>

    {"type":1,"channel":"B","repeat":0,"mmsi":205278090,"navStatus":0,"rateOfTurn":null,"speedOverGround":8.4,"accuracy":true,"lon":4.73319,"lat":51.725665,"courseOverGround":260.1,"heading":null,"utcSecond":37,"specialManoeuvre":0,"raim":true,"radio":59916,"sentences":["!AIVDM,1,1,,B,133i;RPP1DPEbcDMV@1r:Ow:2>`<,0*41"]}

    Handles multi-part messages like a pro:

    import AisDecoder from 'ais-stream-decoder';
    
    const aisDecoder = new AisDecoder();
    aisDecoder.on('error', err => console.error(err));
    aisDecoder.on('data', decodedMessage => console.log(decodedMessage));
    
    const part1 =
      '!AIVDM,2,1,7,A,57lof8`2F5HeT<eC:204e86373:222222222221@8HQC16Ch0:RA7kAD,0*28';
    const part2 = '!AIVDM,2,2,7,A,PBp888888888880,2*79';
    
    aisDecoder.write(part1);
    aisDecoder.write(part2);

    =>

    {"type":5,"channel":"A","repeat":0,"mmsi":525200930,"aisVersion":2,"imo":9835915,"callsign":"YCKT2","name":"AKRA 102","typeAndCargo":80,"dimBow":67,"dimStern":33,"dimPort":19,"dimStarboard":1,"epfd":1,"etaMonth":9,"etaDay":7,"etaHour":16,"etaMinute":0,"draught":4.2,"destination":"ID_MERAK","dte":false,"sentences":["!AIVDM,2,1,7,A,57lof8`2F5HeT<eC:204e86373:222222222221@8HQC16Ch0:RA7kAD,0*28","!AIVDM,2,2,7,A,PBp888888888880,2*79"]}

    Use it to read and decode NMEA line-by-line from a file:

    import AisDecoder from 'ais-stream-decoder';
    import {createReadStream} from 'fs';
    import {resolve} from 'path';
    import {createInterface} from 'readline';
    
    const aisDecoder = new AisDecoder();
    aisDecoder.on('error', err => console.error(err));
    aisDecoder.on('data', decodedMessage => console.log(decodedMessage));
    
    const fileStream = createReadStream(
      resolve(__dirname, './examples/messages.txt')
    );
    const readLine = createInterface(fileStream);
    readLine.on('line', line => aisDecoder.write(line));

    We all love pipes!

    import AisDecoder from 'ais-stream-decoder';
    import split from 'split';
    import {createReadStream} from 'fs';
    import {resolve} from 'path';
    
    const fileStream = createReadStream(
      resolve(__dirname, './examples/messages.txt')
    );
    const aisDecoder = new AisDecoder({silent: true});
    
    fileStream
      .pipe(split())
      .pipe(aisDecoder)
      .on('data', decodedMessage => {
        console.log(decodedMessage);
      });

    License

    MIT

    Install

    npm i ais-stream-decoder

    DownloadsWeekly Downloads

    31

    Version

    2.1.2

    License

    MIT

    Unpacked Size

    56.2 kB

    Total Files

    54

    Last publish

    Collaborators

    • mjaros