Error while streaming through Chromecast cast_sender.js - javascript

Add chrome cast according to the tutorial.
After adding the Chromecast button, I click it, select an available device from the network, and it is connected. The status "Streaming" is visible in the browser, in fact nothing happens, except for the following error in the console:
TypeError: Cannot read property 'loadMedia' of null
Code:
cast.framework.CastContext.getInstance().setOptions({
receiverApplicationId: '111111',
autoJoinPolicy: chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED
});
var currentMediaURL =
'https://.....';
var contentType = 'mp4';
var mediaInfo = new chrome.cast.media.MediaInfo(currentMediaURL,contentType);
var request = new chrome.cast.media.LoadRequest(mediaInfo);
console.log('Below variable -mediaInfo ');
console.log(mediaInfo);
console.log('Below variable -request ');
console.log(request);
var castSession = cast.framework.CastContext.getInstance().getCurrentSession();
console.log('Below variable -castSession ');
console.log(castSession);
castSession.loadMedia(request).then(
function () {
console.log('Load succeed');
},
function (errorCode) {
console.log('Error code: ' + errorCode);
});
Code testing:
As I understand it, for some reason, the link to the stream is not sent.
There is an interesting question, why does the link to the stream go to the variable contentid although there is a variablecontentUrl?

Related

FileReader API error while using jsmediatags

While using JSMediaTags, the onError event handler for the jsmediatags.open method receives an error object with properties:
type = "fileReader"
info = "Offset 0 hasn't been loaded yet"
See pseudo-code below.
The exact text of the error is not in the JSMediaTags file, leading me to believe that the error is being generated by the browser, but I am unable to find insight into what the specific problem is.
I'm running this on my local workstation, with a Windows 7 OS running IIS. I've tested in Chrome v 61, and Firefox v 55. Same error in both.
As you can see, I'm trying to first send the file object (as a file) into the jsmediatags.read function. This results in the error detailed above.
I've commented out the code where, instead of the file object, I try sending in 1.) the complete local path to the file, 2.) the result of createObjectURL on the file object, as well as 3.) the file object's name property. These last 3 do not result in either an onSuccess or onError event being fired.
<script type="text/javascript" src="tagreader/jsmediatags.js"></script>
<input type="file" id="fileinput" onchange="window.handleLocalFiles(this.files)">
<script>
var gobjFileTags = null;
function handleLocalFiles(argFiles){
if (argFiles && (argFiles.length > 0)){
testTagReader(argFiles[0]);
}
}
function testTagReader(objFile){
var objTagReader = null;
var strURL = "";
var strFileName = "";
var strLocalPath = "";
objTagReader = window.jsmediatags;
objTagReader.read(objFile, {
onSuccess: function(tag){
window.gobjFileTags = tag;
window.readFileTags();
},
onError: function(objError){
window.alert("objTagReader Error - type: " + objError.type + ", info: " + objError.info);
}
});
}
function readFileTags(){
window.alert("readFileTags called");
}

createWriteStream finishes, but file not available

My node server uses Watson TTS api to synthesize text sent by the client using POST. Writes TTs stream to a file named using a counter (1.ogg,2.ogg...), and once finished, sends back filename. Client loads it into audio tag and plays audio.
Although I am using createWriteStream's on('finish'), I sometimes get an error client-side where the file can't be loaded, as if not there yet:
GET http://localhost/tts_server/audio/24.ogg 412 (Precondition Failed)
Uncaught (in promise) DOMException: Failed to load because no supported source was found.
Additionally,it ALWAYS fails if counter (and so filename) is 1. And it OFTEN fails if the text to synthesize is long.
Client-side relevant code
$.post("http://192.168.0.4:3000", { text : text }, function(data){
player.src = 'audio/' + data.count + '.ogg';
player.oncanplaythrough = player.play();
});
Server-side relevant code
var count = 10;
// function to TTS with Watson
function syntText(texto, cb){
var tts = new TextToSpeechV1 ({
username: '****',
password: '****'
});
var params = {
text: texto,
voice: 'es-ES_EnriqueVoice',
accept: 'audio/ogg;codecs=opus'
};
var ws = fs.createWriteStream('../audio/' + count + '.ogg');
ws.on('finish', cb);
tts.synthesize(params).pipe(ws);
}
// post
app.post('/', function(req, res){
syntText(req.body.text, function(){ //body parser here
res.json({count : count});
count++;
});
});
Thank you

Addon-sdk websocket keeps disconnectiong

I want to open permanent websocket connection to a server in firefox extension. So I've created page-mod in main.js
_stickyInterface = pageWorker.Page({
contentURL : self.data.url('wsInterface.html')
});
interface looks this way:
<html>
<head>
<script>
//const HOST = 'ws://localhost:9099';
const HOST = 'ws://10.0.0.32:9099';
// subprotocol-key: used when server handles communication of more applications.
// With subprotocol is server able to delegate messages for this purpose
//const STICKY_SUBPROTOCOL_KEY = "Myris_JsApi";
const STICKY_SUBPROTOCOL_KEY = 'sticky-protocol';
// internal identifier of this app
const APP_KEY = "Myris_Chrome";
var _connection = null;
var _requestQueue = [];
_connection = new WebSocket(HOST, STICKY_SUBPROTOCOL_KEY);
_connection.onopen = function () {
console.log("Sticky Interface: Connection opened.");
var JSONObject = new Object;
JSONObject.appKey = APP_KEY;
_connection.send(JSON.stringify(JSONObject));
console.log('sent');
};
_connection.onerror = function (evt) {
console.log("Error ");
console.log(evt);
_connection.close();
}
//ok
_connection.onclose = function (evt) {
console.log("Close ");
_connection.close();
}
_connection.onmessage = function(evt) {
console.log('MESSAGE');
}
</script>
</head>
<body></body>
</html>
Connection is opened, messages are received. But client keeps disconnecting. There is no error message in browser console. Except for these lines (and I think the last two appeard after connection disconnected)
ReferenceError: reference to undefined property permissions['private-browsing'] self.js:50
1413381004615 Services.HealthReport.HealthReporter WARN Saved state file does not exist.
1413381004615 Services.HealthReport.HealthReporter WARN No prefs data found.
and even after then, with some timeout
"Error " StickyInterface.html:30
error { target: WebSocket, isTrusted: true, NONE: 0, CAPTURING_PHASE: 1, AT_TARGET: 2, BUBBLING_PHASE: 3, ALT_MASK: 1, CONTROL_MASK: 2, SHIFT_MASK: 4, META_MASK: 8, currentTarget: WebSocket } StickyInterface.html:31
"Close " StickyInterface.html:37
The connection to ws://10.0.0.32:9099/ was interrupted while the page was loading. StickyInterface.html:17
GET http://localhost/extensions-dummy/blocklistURL [HTTP/1.1 404 Not Found 13ms]
Connection fails, even with no activity mage. Using freshy installed Firefox 33.

How to postMessage through port when websocket receives the word.?

I am trying to use the websocket's onMessage function so that when it receives the word "go", it will postMessage through the port for the current tab. The current tab id is valid, but I keep getting the error Uncaught TypeError: Cannot read property 'postMessage' of undefined.
ws.onmessage = function (evt) {
if(evt.data == "connect"){
rpwd = "helloworld";
ports[curTabID].postMessage({text: rpwd});
}
};
The problem was with my mistaking ports and tab.id to be the same thing. The postMessage must be called on a port. I had to add in an onConnect listener to get the port for whatever tab was opened.
var ports = {};
function onConnect(port) {
ports[port.sender.tab.id] = port;
}
chrome.extension.onConnect.addListener(onConnect);
After that, I needed to know what my current tab id was so that I can look it up in the ports array, which is populated by the onConnect.
var curTabID = 0;
chrome.tabs.onSelectionChanged.addListener(function(tabId) {
curTabID = tabId;
});
From that, I was able to get the port info necessary to send the postMessage.
ws.onmessage = function (evt) {
if(evt.data == "connect"){
rpwd = "helloworld";
ports[curTabID].postMessage({text: rpwd});
}
};
I struggled pretty hard with this code, so I hope I can save somebody time.

SignalR throwing JavaScript Error

I'm new to signalr. I've started an MVC 4.0 application, out of the box, and wired up my signalr JavaScript on the Index View. When I click either the Register or Login buttons, signalr throws a JavaScript error.
Unhandled exception at line 11, column 10700 in http://localhost:49172/Scripts/jquery.signalR- 0.5.1.min.js
0x800a138f - Microsoft JScript runtime error: Unable to set value of the property 'src': object is null or undefined
Any suggestions appreciated.
EDIT:
This is the extent of my code:
$(function () {
var blasht = $.connection.blashtHub;
blasht.addMessage = function (message) {
$('#messages').append('<li>' + message + '');
};
$("#blashtIt").click(function () {
var control = $('#blashtText');
var control2 = $('#hiddenUserId');
// Call the chat method on the server
blasht.send(control2.val(), control.val());
control.val('');
});
blasht.updateTopTen = function (message) {
//add code to update the top user's list
};
// Start the connection
$.connection.hub.start();
});
As suggested I dropped the min and here is where it is crashing, on the frame.sc = src; line.
reconnect: function (connection) {
var that = this;
window.setTimeout(function () {
var frame = connection.frame,
src = transportLogic.getUrl(connection, that.name, true) + "&frameId=" + connection.frameId;
connection.log("Upating iframe src to '" + src + "'.");
frame.src = src;
}, connection.reconnectDelay);
},
SignalR, not me, is invoking this reconnect function. Obviously, that is how it maintains a connection with the server.
The is a bug in the current version of SignalR for the "Forever-Frame" implementation, which is the one that IE9 uses:
https://github.com/SignalR/SignalR/issues/446
A workaround is to force SignalR not to use Forever-Frame transport (https://github.com/SignalR/SignalR/wiki/SignalR-JS-Client).
So change
$.connection.hub.start();
to
$.connection.hub.start({ transport: ['webSockets', 'serverSentEvents', 'longPolling'] });
From the error message, and without your having shown any code, I'd have to guess that you have code that looks like this:
foo.src = someValue;
...where foo is null or undefined. Which begs the question of why is foo null or undefined, but without more context, it's impossible to say. Stepping through with the IE8+ "F12 Developer Tools" may help you pinpoint it.
(Update after code was posted)
I'm guessing that the line causing the error is frame.src = src;. Reformatting that code with consistent indentation:
reconnect: function (connection) {
var that = this;
window.setTimeout(function () {
var frame = connection.frame,
src = transportLogic.getUrl(connection, that.name, true) + "&frameId=" + connection.frameId;
connection.log("Upating iframe src to '" + src + "'.");
frame.src = src; // <=== Presumably this is the line failing
}, connection.reconnectDelay);
},
It would appear that as of the time the delayed function is called, connection.frame is null or undefined. So you'll need to find out why that is. The first thing I'd do is check whether connection.frame is null or undefined when reconnect is called, or if it's only later when the delayed function runs (e.g., has something cleared it in the meantime, and if so, why).

Categories