Skip to content

Instantly share code, notes, and snippets.

View SumindaD's full-sized avatar

Suminda Niroshan SumindaD

  • 1BillionTech
  • Colombo, Sri Lanka
View GitHub Profile
S3Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Join ['-', [!Ref Stage, !Ref 'AWS::AccountId', 's3bucket']]
ECRRepository:
Type: AWS::ECR::Repository
Properties:
RepositoryName: !Join ['-', [!Ref Stage, !Ref 'AWS::AccountId', 'ecr-repository']]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>WebRTC Video Chat</title>
<style>
#videoContainer {
function createAndSendAnswer(){
// Create Answer
connection.createAnswer().then(
answer => {
log('Sent The Answer.');
// Set Answer for negotiation
connection.setLocalDescription(answer);
function createAndSendOffer(){
if(channel){
channel.close();
}
// Create Data channel
channel = connection.createDataChannel('channel', {});
setChannelEvents(channel);
// Create Offer
function createRTCPeerConnection(){
connection = new RTCPeerConnection(configuration);
// Add both video and audio tracks to the connection
for (const track of localStream.getTracks()) {
log("Sending Stream.")
existingTracks.push(connection.addTrack(track, localStream));
}
// This event handles displaying remote video and audio feed from the other peer
function connectToWebSocket(){
socket = new WebSocket(webSocketConnection);
// Create WebRTC connection only if the socket connection is successful.
socket.onopen = function(event) {
log('WebSocket Connection Open.');
createRTCPeerConnection();
};
// Handle messages recieved in socket
service: awswebsocketchat
frameworkVersion: "1.48.2"
custom:
currentStage: ${opt:stage, self:provider.stage}
lambdaRunTime: python3.7
socketConnectionsTableName: socketConnections-#{AWS::AccountId}-${self:custom.currentStage}
provider:
name: aws
import json
import boto3
import os
dynamodb = boto3.client('dynamodb')
def handle(event, context):
connectionId = event['requestContext']['connectionId']
# Delete connectionId from the database
import json
import boto3
import os
dynamodb = boto3.client('dynamodb')
def handle(event, context):
message = json.loads(event['body'])['message']