adding facebook sdk to react-starter-kit - facebook-javascript-sdk

Where or how do I add the FB sdk? I want to add share button and page box plugin.
<!-- fb stuff -->
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.10&appId=${FB_APP_ID}";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<!-- /fb stuff -->

Include the JavaScript SDK on your page once, ideally right after the opening <body> tag
Source: https://developers.facebook.com/docs/plugins/share-button/#configurator
In React, you can also load it in your main components componentDidMount function, for example:
componentDidMount() {
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1version=v2.10&appId=${FB_APP_ID}";
fjs.parentNode.insertBefore(js, fjs);
}
}(document, 'script', 'facebook-jssdk'));
}
The fb-root div will be auto-generated if it does not exist.
You may need to use FB.XFBML.parse in componentDidUpdate, make sure you understand why: https://developers.facebook.com/docs/reference/javascript/FB.XFBML.parse/
Of course you can only use FB after the JS SDK has been loaded. Here is an example for the fbAsyncInit function: http://www.devils-heaven.com/facebook-javascript-sdk-login/

Related

MSE WebM video with no audio

I've written a MSE video player and it's loading WebMs. These are loading well, however I have a problem with video files with no audio tracks.
I've tried changing the codec depending on if there is audio
mediaSource.addSourceBuffer(`video/webm; ${videoHasAudio(asset) ? 'codecs="vp9,vorbis"' : 'codecs="vp9"'}`)`
And I thought this was working but now isn't. How do I run silent WebMs in MSE?
I have added sample MSE project here:
https://github.com/thowfeeq178/MediaSourceExtention
checkout the example in the github
overview:
we need to add one for video and one for audio like below:
// BBB : https://dash.akamaized.net/akamai/bbb_30fps/bbb_30fps.mpd
var baseUrl = "https://dash.akamaized.net/akamai/bbb_30fps/";
var initUrl = baseUrl + "bbb_30fps_480x270_600k/bbb_30fps_480x270_600k_0.m4v";
var initAudioUrl = baseUrl + "bbb_a64k/bbb_a64k_0.m4a";
var templateUrl =
baseUrl + "bbb_30fps_480x270_600k/bbb_30fps_480x270_600k_$Number$.m4v";
var templateUrlForAudio = baseUrl + "bbb_a64k/bbb_a64k_$Number$.m4a";
var sourceBuffer;
var audioSourceBuffer;
var index = 0;
var audioIndex = 0;
var numberOfChunks = 159;
var video = document.querySelector("video");
var ms = new MediaSource();
function onPageLoad() {
console.log("page loaded ..");
if (!window.MediaSource) {
console.error("No Media Source API available");
return;
}
// making source controlled by JS using MS
video.src = window.URL.createObjectURL(ms);
ms.addEventListener("sourceopen", onMediaSourceOpen);
}
function onMediaSourceOpen() {
// create source buffer
sourceBuffer = ms.addSourceBuffer('video/mp4; codecs="avc1.4d401f"');
audioSourceBuffer = ms.addSourceBuffer('audio/mp4; codecs="mp4a.40.5"');
// when ever one segment is loaded go for next
sourceBuffer.addEventListener("updateend", nextSegment);
audioSourceBuffer.addEventListener("updateend", nextAudioSegment);
// fire init segemnts
GET(initUrl, appendToBuffer);
GET(initAudioUrl, appendToAudioBuffer);
// play
video.play();
}
// get next segment based on index and append, once everything loaded unlisten to the event
function nextSegment() {
var url = templateUrl.replace("$Number$", index);
GET(url, appendToBuffer);
index++;
if (index > numberOfChunks) {
sourceBuffer.removeEventListener("updateend", nextSegment);
}
}
// get next audio segment based on index and append, once everything loaded unlisten to the event
function nextAudioSegment() {
var audioUrl = templateUrlForAudio.replace("$Number$", audioIndex);
GET(audioUrl, appendToAudioBuffer);
audioIndex++;
if (index > numberOfChunks) {
audioSourceBuffer.removeEventListener("updateend", nextAudioSegment);
}
}
// add to existing source
function appendToBuffer(videoChunk) {
if (videoChunk) {
sourceBuffer.appendBuffer(new Uint8Array(videoChunk));
}
}
function appendToAudioBuffer(audioChunk) {
if (audioChunk) {
audioSourceBuffer.appendBuffer(new Uint8Array(audioChunk));
}
}
// just network thing
function GET(url, callback) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.responseType = "arraybuffer";
xhr.onload = function(e) {
if (xhr.status != 200) {
console.warn("Unexpected status code " + xhr.status + " for " + url);
return false;
}
callback(xhr.response);
};
xhr.send();
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>MSE Demo</title>
</head>
<body onload="onPageLoad()">
<h1>MSE Demo</h1>
<div>
<video muted controls width="80%"></video>
</div>
</body>
</html>

How to use Discourse comments in VueJS?

I have a website that uses Vuejs. And a forum in Discourse. I am trying to insert a javascript in the template file that will connect comments from the forum to a specific page on Vuejs site. But I get the error:
Templates should only be responsible for mapping the state to the UI.
Avoid placing tags with side-effects in your templates, such as <script>,
as they will not be parsed.
My Detail.vue code:
<div id='discourse-comments'></div>
<script type="text/javascript">
DiscourseEmbed = { discourseUrl: 'https://forum.epicseven.ru/',
discourseEmbedUrl: '{{url absolute="true"}}' };
(function() {
var d = document.createElement('script'); d.type = 'text/javascript';
d.async = true;
d.src = DiscourseEmbed.discourseUrl + 'javascripts/embed.js';
(document.getElementsByTagName('head')[0] ||
document.getElementsByTagName('body')[0]).appendChild(d);
})();
</script>
I was try change text/javascript to application/javascript, but when i try render it, i receive error:
- invalid expression: missing ) after argument list in
" \n DiscourseEmbed = { discourseUrl: 'https://forum.epicseven.ru/',\n
discourseEmbedUrl: '"+_s(url absolute="true")+"' };\n\n (function() {\n
var d = document.createElement('script'); d.type =
'application/javascript'; d.async = true;\n d.src =
DiscourseEmbed.discourseUrl + 'javascripts/embed.js';\n
(document.getElementsByTagName('head')[0] ||
document.getElementsByTagName('body')[0]).appendChild(d);\n })();\n"
Raw expression: DiscourseEmbed = { discourseUrl:
'https://forum.epicseven.ru/',
discourseEmbedUrl: '{{url absolute="true"}}' };
(function() {
var d = document.createElement('script'); d.type =
'application/javascript'; d.async = true;
d.src = DiscourseEmbed.discourseUrl + 'javascripts/embed.js';
(document.getElementsByTagName('head')[0] ||
document.getElementsByTagName('body')[0]).appendChild(d);
})();
How i can fix this error? Maybe try to use different part of code?

Speech Synthesis API offline languages

Is it possible to use the speech synthesis API offline? If so, can I use multiple languages or just the default language?
I have tried this code and it works online, but it does not work offline. How can I make it work online?
<html>
<head>
<title>Index</title>
</head>
<p id = "1"></p>
<script src="../js/jquery-3.2.1.js"></script>
<script type="text/javascript">
$(document).ready(function() {
document.addEventListener("keydown", function (e) {
var audio = document.getElementById("myAudio");
if (e.keyCode ===49 || e.keyCode ===97) { //1 is pressed
mySpeech();
}
});
})
function mySpeech(){
var msg = new SpeechSynthesisUtterance();
var voices = window.speechSynthesis.getVoices();
msg.voiceURI = 'native';
msg.lang = 'it-IT'
//msg.voice = voices[$('#voices').val()];
msg.rate = 1; // 0 to 1
msg.pitch = 1; // 0 to 2
msg.text = "hello world";
speechSynthesis.speak(msg);
}
</script>
</body>
The only languages that will work offline are the browser's local voices.

FB.logout() called without an access token. all.js:54

I load the facebook SDK like this:
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
So, I get this error:
FB.logout() called without an access token. all.js:54
How would I fix this? as its in the facebook SKD file?!
Try this code
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
Full instruction can find here

Localizing the sign-in button

hallo following this tutorial
https://developers.google.com/+/web/signin/#customizing_the_sign-in_button
when i implement the localization script to show the button in korean, german or whatever the g+ button dissapear
<script type="text/javascript">
// Specify the language code prior to loading the JavaScript API
window.___gcfg = {
lang: 'ko'
}
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/client:plusone.js?onload=onLoadCallback';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
Maybe im doing something wrong but the code looks so easy...
thank you for your time and sorry for my english.
You're in luck, Ian Barber just wrote a blog post about localizing Google+:
http://www.riskcompletefailure.com/2013/08/google-sign-in-localisation.html
That should answer your question.
The issue in the code is that you are missing a semicolon after the global window config markup:
<script type="text/javascript">
// Specify the language code prior to loading the JavaScript API
window.___gcfg = {
lang: 'ko'
};
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/client:plusone.js?onload=onLoadCallback';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
Should work.