Skip to content

Instantly share code, notes, and snippets.

View app.js
let publisher;
const handleError = (e) => console.log(e);
const startScreenShareWithAudio = async () => {
let stream;
try {
stream = await navigator.mediaDevices.getDisplayMedia({video: true, audio: true});
} catch (e) {
handleError(e);
}
if (stream) {
@enricop89
enricop89 / app.js
Created Feb 3, 2021
Screensharing with audio from Mic
View app.js
const publish = Promise.all([
OT.getUserMedia({
videoSource: 'screen'
}),
OT.getUserMedia({
videoSource: null
})
])
.then(([screenStream, micStream]) => {
return OT.initPublisher(null, {
@enricop89
enricop89 / query.graphql
Created Jan 19, 2021
Insights API Query Example
View query.graphql
{
project(projectId: 123456) {
sessionData {
sessions(sessionIds:["YOUR_SESSION_ID"]){
resources {
subscriberMinutes,
publisherMinutes
}
}
}
@enricop89
enricop89 / App.js
Created Jul 21, 2020
RN App js file for testing setPreferredRes and FrameRate
View App.js
import React, { Component } from 'react';
import { View, Button, TextInput, Text, SafeAreaView } from 'react-native';
import { OTSession, OTPublisher, OTSubscriber, OT } from 'opentok-react-native';
import { Picker } from '@react-native-community/picker';
export default class App extends Component {
constructor(props) {
super(props);
this.apiKey = '';
this.sessionId =
@enricop89
enricop89 / index.js
Created Jun 10, 2020
getDiplayMedia with audio constraint
View index.js
let publisher;
const handleError = (e) => console.log(e);
const startScreenShareWithAudio = async () => {
let stream;
try {
stream = await navigator.mediaDevices.getDisplayMedia({video: true, audio: true});
} catch (e) {
handleError(e);
}
if (stream) {
@enricop89
enricop89 / publisher.js
Last active May 22, 2020
Example of Publisher Retry logic
View publisher.js
let currentRetryAttempt = 0;
const maxRetryAttempts = 3;
const retryAttemptTimeout = 1000;
function handleRetryPublisher() {
setTimeout(() => {
currentRetryAttempt += 1;
this.createPublisher();
}, this.retryAttemptTimeout);
}
@enricop89
enricop89 / lambda.yml
Created Apr 18, 2020
CF Lambda DLQ example
View lambda.yml
Resources:
MyFunction:
Type: AWS::Lambda::Function
Properties:
DeadLetterConfig:
TargetArn: arn:aws:sqs:us-east-2:123456789012:dlq
@enricop89
enricop89 / handler.js
Created Apr 17, 2020
AWS lambda handler - Global exceptions
View handler.js
module.exports.handler = async (event) => {
console.log('Received event:', JSON.stringify(event, null, 2));
try {
// Function Logic
} catch (err) {
console.log('[Handler] - Main function: ', err);
// Send the error to Third-party monitoring services
}
};
View index.html
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="nexmoClient.js"></script>
</head>
View example.js
// First option
application.callServer(JSON.stringify({number: 393201122334, clientRef: "my-reference"}))
// Second option
application.callServer("393201122334_my-ref")
// then split the number in your answer NCCO