I'm implementing the google chrome casting feature into the Web application.
I'm going to use a custom casting button like this.
<button is='google-cast-button'></button>
const applicationId = 'application id from developer console';
window['__onGCastApiAvailable'] = function(isAvailable) {
if (isAvailable) {
initializeCastApi();
}
};
initializeCastApi = function() {
cast.framework.CastContext.getInstance().setOptions({
receiverApplicationId: applicationId,
autoJoinPolicy: chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED
});
var castSession = cast.framework.CastContext.getInstance().getCurrentSession();
if (castSession) {
castSession.addEventListener(
cast.framework.SessionEventType.APPLICATION_STATUS_CHANGED,
function(applicationStatusEventData){
console.log('****Session is starting...****');
console.log(applicationStatusEventData);
}
)
}
};
This is my code.
But when I click the custom casting button, TV is showing only a text with application name in middle of screen.
Is there anyone knows why and how to fix that? I'll appreciate any answers from everyone. Thanks.
Related
I'm trying to figure out if it's possible to make it so that if you click a link or button, a bookmark will be created. Anything that comes up on Google has to do with ebooks, and I can't seem to find anything. If anyone has the answer, it would be a huge help!
function addFavorites(a) {
pageTitle = document.title;
pageURL = document.location;
try {
// Internet Explorer solution
eval("window.external.AddFa-vorite(pageURL, pageTitle)".replace(/-/g, ''));
} catch (e) {
try {
// Mozilla Firefox solution
window.sidebar.addPanel(pageTitle, pageURL, "");
} catch (e) {
// Opera solution
if (typeof(opera) == "object") {
a.rel = "sidebar";
a.title = pageTitle;
a.url = pageURL;
return true;
} else {
// The rest browsers (i.e Chrome, Safari)
alert('Press ' + (navigator.userAgent.toLowerCase().indexOf('mac') != -1 ? 'Cmd' : 'Ctrl') + '+D to bookmark this page.');
}
}
}
return false;
}
Add to Favorites
Source: https://rudrastyh.com/javascript/favorite-button.html
Be aware of eval()
eval() may be a dangerous function under certain circumstances, which executes the code it's passed with the privileges of the caller.
Get advised by Mozilla.org and use with caution
No, there's no stright forward way for that.
Opera, Google Chrome and Safari do not provide a way to add new elements to the Favorites (Bookmarks) from JavaScript.
There was an API for that however, which is the Window.external API, and I believe it used to work as window.external.AddFavorite() in Internet Explorer, and window.sidebar.addPanel() in Firefox (obsolete, deprecated, i.e. dead, see for the API).
Not sure this info would help, but you might have to create a browser extension for that, then connect your button with your extension, this way you can ensure its stability.
My suggestion is to simply ask the users to bookmark the webpage they're in if that would help to solve the problem you're trying to solve (not sure what you're trying to create).
I'm having a problem trying to get my AWS Lambda function to successfully output a series of HTML links when its running a SQL Query.
private string GetEventSearchResults(ILambdaContext context, List<Event> events, string CustomerNumber)
{
var result = string.Empty;
var link = string.Empty;
if (events.Count > 0)
{
result = $"Events for {CustomerNumber}:";
foreach (var evt in events)
{
link = "http://localhost/event/" + $"{evt.ID}";
result += $"<br>Event: {evt.ID} - Status: {evt.Status}";
}
}
else
{
result = "No Data found matching your query";
}
return result;
}
When this method is called by my Lambda function as a LexResponse,
replyMessage = GetEventSearchResults(context, eventList, query.CustomerNumber);
return Close(
sessionAttributes,
"Fulfilled",
new LexResponse.LexMessage
{
ContentType = "PlainText",
Content = replyMessage
}
);
This response is then rendered in my HTML page by a Javascript function. Relevant portion of the Javascript that renders the response:
function showResponse(lexResponse) {
var conversationDiv = document.getElementById('conversation');
var responsePara = document.createElement("P");
responsePara.className = 'lexResponse';
if (lexResponse.message) {
responsePara.appendChild(document.createTextNode(lexResponse.message));
responsePara.appendChild(document.createElement('br'));
}
if (lexResponse.dialogState === 'ReadyForFulfillment') {
responsePara.appendChild(document.createTextNode(
'Ready for fulfillment'));
// TODO: show slot values
}
conversationDiv.appendChild(responsePara);
conversationDiv.scrollTop = conversationDiv.scrollHeight;
}
However, the output shown by the Lex bot is as shown below:
Lex Bot Output
Can anyone please help me understand what exactly is going on? Is the content type of the Lex Response responsible for this? (there's only plaintext and SSML available for Lex Response so I can't change that)
Also, if possible, can anyone please explain how to fix this if at all possible? Thanks!
Your code is correct and output is also correct.
However the console window is not able to render the HTML part of your result.
The client on which you will deploy the chatbot, is responsible for rendering the output. For example, if you respond with a ResponseCard, console or website will not be able to render it correctly but it will be displayed correctly on Facebook and Slack. So, if you integrate your chatbot on some website it will show the links in your output correctly as you desired.
You can try to integrate your chatbot with Slack or Facebook first, to see the rendering of output.
Hope it helps.
After further trial and error, I managed to get a solution that works for me.
function showResponse(lexResponse) {
var conversationDiv = document.getElementById('conversation');
var responsePara = document.createElement("P");
responsePara.className = 'lexResponse';
if (lexResponse.message) {
var message = lexResponse.message.replace(/"/g, '\'');
responsePara.innerHTML = message;
responsePara.appendChild(document.createElement('br'));
}
conversationDiv.appendChild(responsePara);
conversationDiv.scrollTop = conversationDiv.scrollHeight;
}
By making the LexResponse an Inner HTML, it fixed the markup of the text and thus the link can be seen everytime.
I have following issues on conversion:
Text field not working on converting swf file to html5 using swiffy..
some animation are not working..
There is also sound problem in in some browser.
Is there any way to identify the textfield actions ?
I have googled but nothing works.. I think they are saying use js.
1) The key is to send the value to the swiffy object with this line in javascript:
function sendValue() {
myValue=inputFieldName.value;
stage.setFlashVars('myMessageFromTextfield='+myValue);
}
2) Then, inside the fla file, in actionscript2, get the value:
getValue = function() {
if(_level0.myMessageFromTextfield == "undefined" || _level0.myMessageFromTextfield == undefined) {
this.cat.animCat.myText.text = "";
} else {
this.cat.animCat.myText.text = _level0.myMessageFromTextfield;
returnButton._visible = true;
}
}
3) You need to constantly monitor when te data apears so use a setInterval:
myInterval = setInterval(this, "getValue", 100);
4) Now, to send the value back to html file, we use getURL with the data attached:
returnButton.onRelease = function() {
getURL("Javascript:showMessage('"+_level0.myMessageFromTextfield+" says the cat');");
}
5) And finally, again in javascript inside the html we execute the function with the parameter:
function showMessage(message) {
alert(message);
}
It works perfectly in IE, Firefox, Chrome, safari (ios).
So you now can send text in ipad or iphone.
I attached the source files in the next link:
https://onedrive.live.com/redir?resid=E64343A7ADE7D670!1401&authkey=!AO86aUEdyZRqQN4&ithint=file%2czip
Hope this help you (I've been trying to solve this during many months and until today i could).
When I pull up a Google Map, there is a little gear icon near the bottom-right that allows me to share. It includes finding an embeddable <iframe>. However, once I go into Streetview this gear icon disappears.
How can I embed the streetview version of the map?
It appears the problem is that the new google maps does not have a way to embed.
If you click on the in the bottom right corner while NOT in pano / street view mode you can revert to classic maps
Then you'll see
from there you can select embed frame.
When you're in the Streeview mode, click on the "link button" next to the print button. You'll have an iframe and a link to customize and preview it.
Since Google changed in the past two years I'll post an answer that shows how to embed Street View with the new Maps.
Enter in Street View Mode with the best view you want
Click those "three dots" on the top left corner of the screen
Click "Share or Embed Image"
Click on the tab "Embed Image" and copy/paste the code
of the iframe
its too simple .just go to link below https://developers.google.com/maps/documentation/javascript/examples/streetview-embed
copy the html+javascript code into your page and modify the div style (by default it goes full screen) having id= map-canvas
now go to the desired street view and copy the latitude,longitude in the url then replace in your code in initialize function latling(latitude,longitude) done!!!! happy to post my first answer stack overflow has answered me so many times
If you are looking for a more generic way, for example to display embedded streetview based on the regular google map link or coordinates. Here is my solution:
Extract coordinates from a regular link
export const getCoordinatesFromGoogleMapURL = (url: string) => {
if (!url) {
return undefined
}
const urlParts = url.split('/#')[1]?.split(',')
if (!(urlParts && urlParts?.length > 1)) {
return undefined
}
const gpsX = parseFloat(urlParts[0])
const gpsY = parseFloat(urlParts[1])
if (isNaN(gpsX) || isNaN(gpsY)) {
return undefined
}
return [gpsX, gpsY] as [number, number]
}
Generate embed url from coordinates:
export const generateGoogleMapEmbedUrl = (coordinates: [number, number]) => {
if (!coordinates) {
return undefined
}
const baseUrl = "https://www.google.com/maps/embed/v1/streetview"
const coordinatesString = `${String(coordinates[0])},${String(coordinates[1])}`
const url = `${baseUrl}?key=${process.env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY}&location=${coordinatesString}`
return url
}
Finally we can put it together:
export function convertToEmbedURL(url: string): string {
const coordinates = getCoordinatesFromGoogleMapURL(url)
const embedUrl = generateGoogleMapEmbedUrl(coordinates)
return embedUrl;
}
You can read the official docs to find out more about params etc: https://developers.google.com/maps/documentation/embed/embedding-map#streetview_mode
I wanted to save the google map into an image from a webpage.
while i was searching for that i got this program.
http://www.codres.de/downloads/gms.exe[^]
besides other alternatives like print screen i wanted to use a program or map api which can save a specified dimension of google map instead of the screen.
i have used browser component in c# for http access and for displaying certain webpages.
I want to know whether there are options to capture the browser screen to image using any c# functionality or even the browser component would have given such options. just a guess.
i would like to have answers, suggestions on how to capture the map with custom dimension and zoom size to an image.
I used this to get captcha Image from the current page, so you can use similar code just amend the imageID to point to the google map image and use this solution for zooming.
public string newsavefunction(WebBrowser webBrowser1)
{
IHTMLDocument2 doc = (IHTMLDocument2)webBrowser1.Document.DomDocument;
IHTMLControlRange imgRange = (IHTMLControlRange)((HTMLBody)doc.body).createControlRange();
string imagename = string.Empty;
try
{
foreach (IHTMLImgElement img in doc.images)
{
imgRange.add((IHTMLControlElement)img);
imgRange.execCommand("Copy", false, null);
using (Bitmap bmp = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap))
{
bmp.Save(#"F:\captchaimages\captchapic.jpg");
}
imagename = img.nameProp;
break;
}
}
catch (System.Exception exp)
{ }
return imagename;
}