This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gitlab merge to master example |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(() => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
}); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller, Get } from '@nestjs/common'; | |
@Controller('users') // Base route: /users | |
export class UsersController { | |
@Get() // Handles GET /users | |
findAll(): string { | |
return 'This action returns all users'; | |
} | |
} |
OlderNewer