Code in electron renderer process not working after packaging - socket.io

code from index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
<!-- All of the Node.js APIs are available in this renderer process. -->
We are using Node.js <script>document.write(process.versions.node)</script>,
Chromium <script>document.write(process.versions.chrome)</script>,
and Electron <script>document.write(process.versions.electron)</script>.
<script src="./renderer.js"></script>
</body>
<form><input></form><div></div>
</html>
code in renderer.js:
var io = require('socket.io')();
var os = require('os');
var fs = require('fs');
io.listen(6000);
io.on('connection', function (socket) {
socket.on('my socketId', function (data) {
socket.emit('client connect', {
nickname: os.hostname()
});
});
});
Problem: It works fine using electron . running in browser. But client got no respond after packaging by electron-packager.
Thank you very much for any help!!

I finally solved this problem. I was copying the app to build first. But node_modules (and those packages) didn't exist in that directory. Either copy it or run npm install in build before running Electron Packager will make it work.

Related

Failed to syntheis speech for the Bot Framework Web Chat

I'm having a go with speech for a BOT. I have been running through the Microsoft Tutorial found here. I've taken the example Echo BOT example from there, found here, as a basis so I can use it as a basis going forward. This has been successfully deployed to my Azure environment. Also in the tutorial, you run your Bot through the Direct Line Speech Client v1, everything works as expected when doing this.
I have looked at the Bot Framework Web Chat speech notes to get the Bot working using this as my channel. Here is my code for this:
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Web Chat: Browser-supported speech</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
<style>
html, body { height: 100% }
body { margin: 0 }
#webchat {
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<div id="webchat" role="main"></div>
<script>
(async function () {
window.WebChat.renderWebChat({
directLine: createDirectLine({
secret: '<My Direct Line secret>'
}),
language: 'en-US',
webSpeechPonyfillFactory: await createCognitiveServicesSpeechServicesPonyfillFactory({
region: '<Speech cognitive service region>',
subscriptionKey: '<Speech cognitive service key>'
})
}, document.getElementById('webchat'));
document.querySelector('#webchat > *').focus();
})().catch(err => console.error(err));
</script>
</body>
</html>
I'm able to get this working and I can do speech to text and text inputs and the contents is written back, but when it tries to do text to speech back I'm getting the following errors in the browser console:
POST https://<region>.tts.speech.microsoft.com/cognitiveservices/v1 net::ERR_ABORTED 400 (Speak node can only be the root.)
webchat.js:1 Error: Failed to syntheis speech, server returned 400
at webchat.js:1
at c (webchat.js:1)
at Generator._invoke (webchat.js:1)
at Generator.e.<computed> [as next] (webchat.js:1)
at n (webchat.js:1)
at s (webchat.js:1)
I'm not quite sure if it is something in the script code or the Bot, let me know if you need any more detail. Thanks in advance!
It is weird... I hosted a echo bot on Azure and just copy and paste your html code and did some config ,I tested on edge firefox and chrome but everything works well including tts calling :
You can try it here and check the config . Hope it helps .

RxJS 6 websocket does not receive any message

I am testing out rxjs websocket with sample code below, but when I try to publish from https://www.websocket.org/echo.html, I couldn't receive any message on the HTML, is this expected? How can I subscribe to topic from https://www.websocket.org/echo.html?
<html>
<head>
<script src="https://unpkg.com/#reactivex/rxjs#6.2.2/dist/global/rxjs.umd.js"></script>
<script>
const { WebSocketSubject } = rxjs.webSocket;
const socket$ = new WebSocketSubject('wss://echo.websocket.org');
socket$.subscribe(
(data) => console.log(data),
(err) => console.error(err),
() => console.warn('Completed!')
);
console.log('here')
</script>
</head>
<body></body>
</html>
websocket.org/echo.html does not offer broadcast thus using it for local testing will not receive any reply.
Running a local websocket server for testing is the way to go.

Proxied HTTP response being modified

I have a gulpfile that launches a dev proxy server.
gulp.task('dumbserver', ()=> {
const express = require('express');
const httpProxy = require('http-proxy');
const app = express();
const proxy = httpProxy.createProxyServer();
app.use('/api', function (req, res) {
proxy.web(req, res, {target: 'https://bos1-vcd-sp-static-199-8.eng.vmware.com/api', secure: false},
(e) => console.log('error', e)
);
});
return app.listen(8080, function () {
console.log('Server started on port 8080.');
});
});
When I make a call on postman directly to https://bos1-vcd-sp-static-199-8.eng.vmware.com/api/session I get the following payload:
<Session locationId="86171c79-e8f0-4c06-a0a8-4bc7fde76915#7bcf706c-d90f-4e1b-b0cc-b2a13db3e618" org="juan" roles="System Administrator" user="administrator" userId="urn:vcloud:user:7b5f0241-f597-4851-8cae-655a15afde24" href="https://bos1-vcd-sp-static-199-8.eng.vmware.com/api/session" type="application/vnd.vmware.vcloud.session+xml">
<Link rel="down" href="https://bos1-vcd-sp-static-199-8.eng.vmware.com/api/org/" type="application/vnd.vmware.vcloud.orgList+xml"/>
<Link rel="remove" href="https://bos1-vcd-sp-static-199-8.eng.vmware.com/api/session"/>
<Link rel="down" href="https://bos1-vcd-sp-static-199-8.eng.vmware.com/api/admin/" type="application/vnd.vmware.admin.vcloud+xml"/>
<Link rel="down" href="https://bos1-vcd-sp-static-199-8.eng.vmware.com/api/admin/extension" type="application/vnd.vmware.admin.vmwExtension+xml"/>
<Link rel="nsx" href="https://bos1-vcd-sp-static-199-8.eng.vmware.com/network" type="application/xml"/>
<Link rel="openapi" href="https://bos1-vcd-sp-static-199-8.eng.vmware.com/cloudapi" type="application/json"/>
</Session>
However, when I make a call using postman to localhost:8080/api/session, the last two links have the hrefs rewritten to be
<Link rel="nsx" href="https://localhost:8080/network" type="application/xml"/>
<Link rel="openapi" href="https://localhost:8080/cloudapi" type="application/json"/>
But none of the other links have been rewritten.
Any suggestions about what could be going on?
It turns out that http-proxy adds a HOST header. The server side code that was generating the links was using that HOST header if available as the base URL, overriding the configured value.
Not deleting the question in the hopes that the knowing fact that http-proxy adds a host header to requests may cause a bug in your code.

Angular-ui-router templateUrl not working with Chrome and IE, but works for Firefox

Created a very simple Angular ui-router files to test, I found out "templateUrl" ('contact' state in my example code) in the stateProvider not working with Chrome and IE, but works for Firefox, however, 'template'('home' state in my example code) property works in Chrome/IE/Firefox.
My test project only contains two html files under same folder:
index.html
<html>
<head>
<script src="http://unpkg.com/angular#1.5/angular.js"></script>
<script src="http://unpkg.com/angular-ui-router#1.0.0-beta.3/release/angular-ui-router.js"></script>
</head>
<body ng-app="main-app">
<a ui-sref="home">Home</a>
<a ui-sref="contact">Contact</a>
</br>
<ui-view></ui-view>
</body>
<script>
var myApp = angular.module('main-app', ['ui.router']);
myApp.config(function($stateProvider) {
var homeState = {
name: 'home',
url: '/home',
template: 'hello world!'
}
var aboutState = {
name: 'contact',
url: '/contact',
templateUrl: 'contact.html'
}
$stateProvider.state(homeState);
$stateProvider.state(aboutState);
});
</script>
</html>
contact.html
Phone: 416-1113333
There is nothing wrong with your example, it seems you are trying to serve the app via file:// protocol but browsers like Chrome does not allow XHR calls when using the file:// protocol.
Here is the same example accessible via the HTTP server that works identically across browsers.
Another options would be:
embed templates in your index.html file using the <script> directive:
http://docs.angularjs.org/api/ng.directive:script so your templates
are downloaded with the main HTML file and it is no longer necessary
to load them via XHR
change browser settings to allow XHR calls over the file://
protocol. For example, for Chrome follow this answer for a more details

API request from front-end using sails.io.js

I have a basic front-end (html, css, jquery) and I'd like to use sails.io.js to communicate with an API server (developped with sails, with cors enabled). The API is running on localhost:10000 but it will be on an another domain than the one of the webclient later on.
Directly from jquery, I can issue some get request to this API and get the expected results.
When it comes to websocket, I have some problems...
In the index.html (just to test), I put the following:
<script src="js/sails.io.js"></script>
<script type="text/javascript">
io.sails.url('http://localhost:10000');
io.socket.get('/data', function serverResponded (body, sailsResponseObject) {
// body === sailsResponseObject.body
console.log('Sails responded with: ', body);
console.log('with headers: ', sailsResponseObject.headers);
console.log('and with status code: ', sailsResponseObject.statusCode);
});
</script>
But Chrome's developer tools tell me
ReferenceError: io is not defined
Any idea ?
UPDATE
I'm serving index.html with a web server (python -m SimpleHTTPServer)
I've installed sails.io.js using bower.
I've try to make this test as simple as possible:
index.html
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<script src="bower_components/sails.io.js/dist/sails.io.js"></script>
<script src="index.js"></script>
</body>
</html>
index.js:
window.onload=function(){
io.sails.url = 'http://localhost:10000';
io.socket.get('http://localhost:10000/data', function (body, response) {
console.log('Sails responded with: ', body);
});
};
My sails (0.9.16) API is only returning a json object on the GET /data route.
I have implemented a dummy __getcookie function in the api:
'get /__getcookie': function(req, res, next){
res.json({ok: 123});
}
And commented the line 481 in interpret.js (Scott comments below).
I have also modify config/socket.js with:
authorization: false,
=> I can now get the result from the /data route of my API :)
But... on each request I have the following error:
error: Error: No valid session available from this socket.
First of all, sails.io.js includes the code for socket.io.js, so there is no need to try and include that separately. You should remove this line:
<script src="bower_components/socket.io/lib/socket.js"></script>
Next, if you're just loading index.html from disk (rather than serving it from a web server), you'll need to tell the Sails socket client what URL to connect to:
io.sails.url = 'http://localhost:10000';
Put this anywhere before you start making socket calls; the library is smart enough to wait until its connected before trying to make the calls. So, altogether:
window.onload=function(){
io.sails.url = 'http://localhost:10000';
io.socket.get('http://localhost:10000/data', function (body, sailsResponseObject) {
console.log('Sails responded with: ', body);
console.log('with headers: ', sailsResponseObject.headers);
console.log('and with status code: ', sailsResponseObject.statusCode);
});
};
should work. You should be able to see in the console whether or not the socket connected by looking for the "io.socket connected successfully." message.
did you try with a / in front of the src, like:
< script src="js/sails.io.js">
Do you have the sails.io.js in the /assets/js/ folder (sails 0.10) or in the /assets/linker/js folder (sails 0.9 and below).
Did sails lift copied that js file to .tmp/public/js folder?
Where is your index.html file located?

Resources