
- Complete NestJS TypeScript implementation with WebSocket support - Direct messaging (DM) and group chat functionality - End-to-end encryption with AES encryption and key pairs - Media file support (images, videos, audio, documents) up to 100MB - Push notifications with Firebase Cloud Messaging integration - Mention alerts and real-time typing indicators - User authentication with JWT and Passport - SQLite database with TypeORM entities and relationships - Comprehensive API documentation with Swagger/OpenAPI - File upload handling with secure access control - Online/offline status tracking and presence management - Message editing, deletion, and reply functionality - Notification management with automatic cleanup - Health check endpoint for monitoring - CORS configuration for cross-origin requests - Environment-based configuration management - Structured for Flutter SDK integration Features implemented: ✅ Real-time messaging with Socket.IO ✅ User registration and authentication ✅ Direct messages and group chats ✅ Media file uploads and management ✅ End-to-end encryption ✅ Push notifications ✅ Mention alerts ✅ Typing indicators ✅ Message read receipts ✅ Online status tracking ✅ File access control ✅ Comprehensive API documentation Ready for Flutter SDK development and production deployment.
73 lines
2.1 KiB
JavaScript
73 lines
2.1 KiB
JavaScript
"use strict";
|
|
var Buffer = require("safer-buffer").Buffer;
|
|
|
|
// Single-byte codec. Needs a 'chars' string parameter that contains 256 or 128 chars that
|
|
// correspond to encoded bytes (if 128 - then lower half is ASCII).
|
|
|
|
exports._sbcs = SBCSCodec;
|
|
function SBCSCodec(codecOptions, iconv) {
|
|
if (!codecOptions)
|
|
throw new Error("SBCS codec is called without the data.")
|
|
|
|
// Prepare char buffer for decoding.
|
|
if (!codecOptions.chars || (codecOptions.chars.length !== 128 && codecOptions.chars.length !== 256))
|
|
throw new Error("Encoding '"+codecOptions.type+"' has incorrect 'chars' (must be of len 128 or 256)");
|
|
|
|
if (codecOptions.chars.length === 128) {
|
|
var asciiString = "";
|
|
for (var i = 0; i < 128; i++)
|
|
asciiString += String.fromCharCode(i);
|
|
codecOptions.chars = asciiString + codecOptions.chars;
|
|
}
|
|
|
|
this.decodeBuf = Buffer.from(codecOptions.chars, 'ucs2');
|
|
|
|
// Encoding buffer.
|
|
var encodeBuf = Buffer.alloc(65536, iconv.defaultCharSingleByte.charCodeAt(0));
|
|
|
|
for (var i = 0; i < codecOptions.chars.length; i++)
|
|
encodeBuf[codecOptions.chars.charCodeAt(i)] = i;
|
|
|
|
this.encodeBuf = encodeBuf;
|
|
}
|
|
|
|
SBCSCodec.prototype.encoder = SBCSEncoder;
|
|
SBCSCodec.prototype.decoder = SBCSDecoder;
|
|
|
|
|
|
function SBCSEncoder(options, codec) {
|
|
this.encodeBuf = codec.encodeBuf;
|
|
}
|
|
|
|
SBCSEncoder.prototype.write = function(str) {
|
|
var buf = Buffer.alloc(str.length);
|
|
for (var i = 0; i < str.length; i++)
|
|
buf[i] = this.encodeBuf[str.charCodeAt(i)];
|
|
|
|
return buf;
|
|
}
|
|
|
|
SBCSEncoder.prototype.end = function() {
|
|
}
|
|
|
|
|
|
function SBCSDecoder(options, codec) {
|
|
this.decodeBuf = codec.decodeBuf;
|
|
}
|
|
|
|
SBCSDecoder.prototype.write = function(buf) {
|
|
// Strings are immutable in JS -> we use ucs2 buffer to speed up computations.
|
|
var decodeBuf = this.decodeBuf;
|
|
var newBuf = Buffer.alloc(buf.length*2);
|
|
var idx1 = 0, idx2 = 0;
|
|
for (var i = 0; i < buf.length; i++) {
|
|
idx1 = buf[i]*2; idx2 = i*2;
|
|
newBuf[idx2] = decodeBuf[idx1];
|
|
newBuf[idx2+1] = decodeBuf[idx1+1];
|
|
}
|
|
return newBuf.toString('ucs2');
|
|
}
|
|
|
|
SBCSDecoder.prototype.end = function() {
|
|
}
|