Posts

Showing posts from December, 2018

AWS : how to play a video file from s3 bucket in browser

URI all you have to do is to sign a request like: https://s3.amazonaws.com/yourbucket/key? response-content-disposition=inline& X-Amz-Algorithm=AWS4-HMAC-SHA256& X-Amz-Credential=AKIAJWWH7EGSUBWE34IQ/20181228/us-east-1/s3/aws4_request& X-Amz-Date=20181228T074135Z& X-Amz-Expires=86400&X-Amz-SignedHeaders=host& X-Amz-Signature=b3143f8442812e176fd61838813a33f53cfd7e198e1c6e68fab5d03d4a642403   and set it as src attribue to a video element. Player component import React, { Component } from 'react'; import PropTypes from 'prop-types'; const AWS_SERVICE = 's3'; const crypto = require('crypto'); Date.prototype.toYMDString = function() { let year = this.getFullYear().toString(); let month = this.getUTCMonth() + 1; if (month < 10) month = "0" + month; let day = this.getUTCDate(); if (day < 10) day = "0" + day; return String(year) + String(month) + S

WebRTC recording via Kurento media server

Official guide I encountered some errors while following the Official guide. Lucky, I fixed all the errors and make it work finally. Notes my workaround here, hope it work for you if you have the same problem. gpg: keyserver receive failed: keyserver error local install guide solution from stackoverflow sudo apt-key adv --keyserver hkp://keys.gnupg.net:80 --recv-keys 5AFA7A83 WebSocket connection to 'wss://<local_ip>:8433/kurento' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED cause the application server is started with https if you follow the guide: http-server -p 8443 -S -C keys/server.crt -K keys/server.key but kurento media server start without ssl by default config. You can get from the config and the default port is 8888 . /etc/kurento/kurento.conf.json solution modify kurento media server config to enable ssl and use the same cert that used for your application server. it is a little complex. but we have a easy solution, j

AWS: how to upload file to your s3 bucket via EvaporateJS in browser

Image
Evaporate and config s3 bucket and IAM user EvaporateJS Config AWS s3 bucket Managing Access Permissions to Your Amazon S3 Resources User Access Key In summary, create a s3 bucket, set up CORS settings and bucket policy. <CORSConfiguration> <CORSRule> <AllowedOrigin>https://*.yourdomain.com</AllowedOrigin> <AllowedOrigin>http://*.yourdomain.com</AllowedOrigin> <AllowedMethod>PUT</AllowedMethod> <AllowedMethod>POST</AllowedMethod> <AllowedMethod>DELETE</AllowedMethod> <AllowedMethod>GET</AllowedMethod> <ExposeHeader>ETag</ExposeHeader> <AllowedHeader>*</AllowedHeader> </CORSRule> </CORSConfiguration> { "Version": "2012-10-17", "Id": "Policy145337ddwd", "Statement": [ { "Sid": "&quo

AWS : how to get cognito user attributes in Lambda/cloud logic

Image
Lambda function(js) const AWS = require('aws-sdk'); const cognito = new AWS.CognitoIdentityServiceProvider(); function getUser(Username) { return new Promise((resolve, reject) => { cognito.adminGetUser({ UserPoolId: process.env.COGNITO_USER_POOL_ID, Username: Username }, (err, data) => { if (err) reject(err.stack); else resolve(data.UserAttributes[2].Value); }); }); } async function getEmail(Username) { return await getUser(Username); } exports.handler = async (event) => { console.log(await getEmail('abcdef')); console.log(await getEmail('hijklmn')); console.log('done'); return 'ok'; }; set Execution role with correct policy as below descripted. set an environment 'COGNITO_USER_POOL_ID' with the user pool id. Role policy { "Version": "2012-10-17", "Statement&

node.js download file from aws s3 bucket via http request with AWS Signature Version 4

Image
Main codes function getYMD(d) { let r = d.getFullYear().toString(); let m = d.getUTCMonth() + 1; if (m < 10) m = "0" + m.toString(); else m = m.toString(); r = r + m; let day = d.getUTCDate(); if (day < 10) day = "0" + day.toString(); else day = day.toString(); r = r + day; return r; } function getTZ(d) { let r = d.getFullYear().toString(); let m = d.getUTCMonth() + 1; if (m < 10) m = "0" + m.toString(); else m = m.toString(); r = r + m; let day = d.getUTCDate(); if (day < 10) day = "0" + day.toString(); else day = day.toString(); r = r + day + "T"; let h = d.getUTCHours(); if (h < 10) h = "0" + h.toString(); else h = h.toString(); r = r + h; let min = d.getUTCMinutes(); if (min < 10) min = "0" + min.toString(); else min =

easy tab component, pure js + css, without react

This is tab example 1 Passion Organization Content Engagement this is passion pannel this is organization pannel this is engagement pannel This is tab example 2 Passion Organization Content Engagement this is passion pannel 2 this is organization pannel 2 this is engagement pannel 2 end test This is haha node styles <style> .container { padding-right: 15px; padding-left: 15px; margin-right: auto; margin-left: auto; } .tabs { padding-left: 0; margin-bottom: 0; list-style: none; } ol, ul { margin-top: 0; margin-bottom: 10px; } .tabs > li { margin-bottom: -1px; position: relative; display: inline-block; padding: 6px 12px; border-radius: 5px 5px 0 0; background-color: #aac4bd; border: 2px solid #7ea299; margin-right: 2px; color: #fff; cursor: pointer; } .tabs > li.active { background-color: #fbfbfc; border-bottom: 0; padding-bottom: 8px; color: #7ea