Skip to content

Instantly share code, notes, and snippets.

View Vatsalya-singhi's full-sized avatar

Vatsalya Singhi Vatsalya-singhi

View GitHub Profile
// security
// security
app.use(helmet());
app.disable('x-powered-by');
const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
limit: 100, // Limit each IP to 100 requests per `window` (here, per 15 minutes).
message: 'Too many requests from this IP, please try again later.',
standardHeaders: 'draft-7', // draft-6: `RateLimit-*` headers; draft-7: combined `RateLimit` header
legacyHeaders: false, // Disable the `X-RateLimit-*` headers.
mqtt_sub.js
// When a message is received
client.on('message', (receivedTopic, message) => {
console.log('Received message on topic:', receivedTopic.toString());
// console.log('Message:', message.toString());
// Call Kafka's produceMessage function with received MQTT message
produceKafkaMessage(kafka_topic, message.toString())
.then(() => {
console.log('Message published to Kafka');
@Vatsalya-singhi
Vatsalya-singhi / ui_codebase.ts
Created February 26, 2024 14:58
ui code base
// MQTT PUB CODE
const publish_led_status = (value) => {
// Publish the message to the specified topic
client.publish(topic, String(value), (err) => {
if (!err) {
console.log('Message published:', value);
}
setLedStatus(value);
});
};
public onicecandidateListener(event: RTCPeerConnectionIceEvent, id: string) {
if (event.candidate && event.candidate.sdpMid && event.candidate.sdpMLineIndex) {
this.socket.sendCandidate(id, event.candidate);
} else {
console.log('candidate not sent');
}
}
public candidateListen() {
this.socket.candidateListen()
.pipe(takeWhile(() => this.alive))
.subscribe((data) => {
let id: string = data.id;
let candidate: RTCIceCandidate = new RTCIceCandidate(data.candidate);
if (!this.peerConnections[id] || this.peerConnections[id] == null) {
this.peerConnections[id] = new RTCPeerConnection(this.connectionConfig);
}
public offerListener() {
this.socket.offerListen()
.pipe(takeWhile(() => this.alive))
.subscribe(async (data) => {
// receive user id and peer offer
let id: string = data.id;
let offer: RTCSessionDescription = data.offer;
if (!this.peerConnections[id] || this.peerConnections[id] == null) {
this.peerConnections[id] = new RTCPeerConnection(this.connectionConfig);
public createAndSendOffer(id: string) {
this.peerConnections[id]
.createOffer(this.offerOptions)
.then(async (offer: RTCSessionDescriptionInit) => {
if (this.peerConnections[id].signalingState != "stable") {
console.log("-- The connection isn't stable yet; postponing...")
return;
}
this.peerConnections[id].setLocalDescription(offer).then(() => {
@Vatsalya-singhi
Vatsalya-singhi / request.ts
Created April 29, 2020 11:04
Request to access to user's accounts
// request to access user account details
this.ethereum = (window as any).ethereum;
this.webby3 = (window as any).web3;
if (typeof this.ethereum == 'undefined') {
this.dialog.presentToast('Please install MetaMask extension');
return;
}
try {
let x = await this.ethereum.enable();
console.log('ethereum enabled=>', x);
gitlab merge to master example