Skip to content

Instantly share code, notes, and snippets.

View adrigardi90's full-sized avatar
😬
Keep it simple!

Adrián García adrigardi90

😬
Keep it simple!
View GitHub Profile
@adrigardi90
adrigardi90 / events.js
Last active June 7, 2020 12:04
Leave conference server listernet
const leaveConference = (socket, namespace) => async ({ room, from, conferenceRoom }) => {
console.log(`Conference - User "${from}" wants to leave the conference room ${room}`)
try {
const user = await ChatRedis.getUser(room, from)
await ChatRedis.setUser(room, from, { ...user, conference: false })
socket.leave(conferenceRoom, () => {
namespace.to(conferenceRoom).emit('leaveConference', { room, from })
})
} catch (error) {
@adrigardi90
adrigardi90 / Conference.vue
Last active June 4, 2020 22:07
Handle offer from admin
<script>
export default {
async mounted() {
this.myVideo = document.getElementById("localVideo")
// New user gets the offer
if(this.conference.offer) {
const { offer: { from, desc } } = this.conference
this.init(from, desc)
}
@adrigardi90
adrigardi90 / Conference.vue
Last active June 4, 2020 22:03
Responding to a new user
<script>
export default {
methods: {
initWebRTC(user, desc) {
// Add user
this.$set(this.peers, user, {
username: user,
pc: new RTCPeerConnection(this.configuration),
peerStream: undefined,
peerVideo: undefined
@adrigardi90
adrigardi90 / events.js
Last active May 31, 2020 18:25
New conference invitation event
const conferenceInvitation = (namespace) => async ({ room, to, from }) => {
console.log(`Conference - Invitation from "${from}" to "${to}" in room ${room}`)
try {
const { privateChat, conference } = await ChatRedis.getUser(room, to)
// User already talking
if (privateChat || conference) {
console.log(`Conference - User "${to}" is already talking. PrivateChat: ${privateChat} - Conference: ${conference}`)
return namespace.to(from).emit('conferenceInvitation', { message: `User ${to} is already talking`, from })
}
namespace.in(room).emit('conferenceInvitation', { room, to, from })
@adrigardi90
adrigardi90 / Conference.vue
Last active May 31, 2020 18:31
Conference component
<template>
<div class="conference-container">
<div class="conference-container__header">
<h3>Private conference (up to 3)</h3>
<md-menu>
<md-button
class="md-icon-button page-container-logout"
md-menu-trigger
:disabled="peersLength === 2 || users.length === 1"
v-if="conference.admin">
@adrigardi90
adrigardi90 / events.js
Last active May 31, 2020 12:21
JoinConference event
const joinConference = (socket, namespace) => ({ username, room, to, from }) => {
const admin = username === to
console.log(admin
? `Conference - User "${username}" wants to open a conference room`
: `Conference - User "${username}" wants to join the "${to}" conference`)
// Join the room
socket.join(to, async () => {
if (!room) return
try {
@adrigardi90
adrigardi90 / Vide.vue
Last active May 28, 2020 18:47
Video component
<template>
<div class="video">
<div class="video__spinner">
<md-progress-spinner
v-if="!videoStream"
class="md-accent"
md-mode="indeterminate">
</md-progress-spinner>
</div>
<AudioVideoControls
@adrigardi90
adrigardi90 / WebRTC.js
Last active May 28, 2020 18:33
webRTC configuration and functionality
export const videoConfiguration = {
data() {
return {
constraints: {}, // Media constraints
configuration: servers, // TURN/STUN ice servers
// Offer config
offerOptions: {
offerToReceiveAudio: 1,
offerToReceiveVideo: 1
},
@adrigardi90
adrigardi90 / public-stun-list.txt
Created April 30, 2020 22:33 — forked from mondain/public-stun-list.txt
Public STUN server list
23.21.150.121:3478
iphone-stun.strato-iphone.de:3478
numb.viagenie.ca:3478
s1.taraba.net:3478
s2.taraba.net:3478
stun.12connect.com:3478
stun.12voip.com:3478
stun.1und1.de:3478
stun.2talk.co.nz:3478
stun.2talk.com:3478
@adrigardi90
adrigardi90 / paint-elements.js
Last active February 8, 2020 20:41
Paint elements into the canvas
let totalSeconds = 0
// Background image
const backgroundObj = { image: new Image(), ready: false, speed: 100 }
backgroundObj.image.onload = () => backgroundObj.ready = true
backgroundObj.image.src = "images/sky.png"
function paintElements(elapsed) {
if (!firstMove) {