Compact AIS decoder in TypeScript for browser and web apps
npm install ais-webshell
npm install ais-web
`
$3
`typescript
import { AisReceiver } from 'ais-web';
import { encodePositionMessage, AisPositionMessage } from 'ais-web';
// Define vessel position data
const vessel: AisPositionMessage = {
mmsi: 123456789,
lat: 37.7749,
lon: -122.4194,
sog: 12.3,
cog: 45,
heading: 44,
navStatus: 0,
rateOfTurn: 0,
accuracy: false,
timestamp: Date.now(),
};
// Encode position to AIS NMEA sentences
const sentences = encodePositionMessage(vessel);
// Setup AIS decoder
const decoder = new AisReceiver();
decoder.on('position', (msg) => {
console.log('Decoded position message:', msg);
});
// Feed encoded sentences to decoder
sentences.forEach(sentence => decoder.onMessage(sentence));
`
---
Why Choose ais-web?
- Zero Dependencies: Lightweight codebase, no bulky libraries.
- Web-Optimized: Runs smoothly in browsers and Node.js environments.
- Accurate AIS Handling: Covers essential AIS message types for maritime applications.
- Simple API: Easy to integrate with event-driven decoding and straightforward encoding.
- Robust Testing: Verified correctness across global vessel positions and AIS message scenarios.
---
What’s Included
- AIS Encoder for position and static messages.
- AIS Decoder supporting single-part and multi-part messages.
- Event-driven architecture with position and static message events.
- Checksum validation for AIS NMEA sentences.
- Timeout-based multi-part message reassembly.
---
Limitations
- Currently supports only AIS message types 1, 2, 3 (Position Reports) and 5 (Static and Voyage Data).
- Some rare AIS message types and proprietary extensions are not implemented.
- Assumes valid NMEA sentence input; malformed sentences may cause decoding failures.
- Radio and special maneuver fields have default basic handling.
- Real-time network integration and AIS data stream management are left to the user’s application layer.
---
Testing
- Each world region’s position decoding is tested independently to ensure precision and reliability.
- Test cases cover typical vessel parameters like MMSI, lat/lon, speed (SOG), course (COG), heading, and navigation status.
- Test suite leverages the encoder to generate real AIS sentences for decoding verification.
- Use npm test` to run the full suite and verify AIS message handling correctness.