I trying to adopt the demo in this article http://www.asp.net/signalr/overview/getting-started/tutorial-high-frequency-realtime-with-signalr which is developed with vS2012, however I am using vs2010.
I made the model:
[HubName("moveShapeHub")]
public class MoveShapeHub : Hub
{
public void UpdateModel(ShapeModel clientModel)
{
clientModel.LastUpdatedBy = Context.ConnectionId;
Clients.AllExcept(clientModel.LastUpdatedBy).updateShape(clientModel);
}
}
Modified Global.cs:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
RouteTable.Routes.MapHubs();
}
In the view:
var moveShapeHub = $.connection.moveShapeHub,
$shape = $("#shape"),
shapeModel = {
left: 0,
top: 0
};
moveShapeHub.client.updateShape = function (model) {
shapeModel = model;
$shape.css({ left: model.left, top: model.top });
};
$.connection.hub.start().done(function () {
$shape.draggable({
drag: function () {
shapeModel = $shape.offset();
moveShapeHub.server.updateModel(shapeModel);
}
});
I get the following error:
Unable to get property 'client' of undefined or null reference.
Any idea what I am doing wrong; would appreciate your suggestions.
It looks like you're not including the following code in your HTML:
<script src='/signalr/hubs'></script>
Make sure that that code snippet is included AFTER your inclusion of the signalr js library.
If you're still adding the script tag correctly then you're having a path misunderstanding issue where your server is being hosted on a different port.
Lets say your sample is running on http://localhost:1337, you can view your signalr/hubs file by going to http://localhost:1337/signalr/hubs in your browser and you should get generated JavaScript.
A common issue that people run into is they include the /signalr/hubs file but they host their site on http://localhost:1337/bar/. Therefore SignalR tries to load the hubs file from http://localhost:1337/signalr/hubs when really it's located at http://localhost:1337/bar/signalr/hubs.
Verify that your inclusion of /signalr/hubs is pointing to the correct location. I usually do:
<script src="<%: ResolveUrl("~/signalr/hubs") %>"></script>
To always resolve the App-relative URL.
Also be sure to call RouteTable.Routes.MapHubs(); BEFORE you map any other routes.
Have you verified that connection is being established with the server, if not add a .fail(function(){
alert("failed to connect")}); to the end of your connection.hub.start method, to see if it is connecting ok, afterwards try this method:
moveShapeHub.on('updateShape', function(model) {
shapeModel = model;
$shape.css({ left: model.left, top: model.top });
});
Related
Does anyone know what the error "You uploaded the wrong number of assets with Enabler components for this creative. The creative must have exactly 2 asset(s) with Enabler." means?
I'm assuming DoubleClick changed something on their end. I tried uploading old creative and received the same error.
I am using Hype3 to create my ad. Here is the script in the head of the file. I wonder if something has changed with the enabler.
<head>
<script src="https://s0.2mdn.net/ads/studio/Enabler.js"></script>
<meta name="ad.size" content="width=1000,height=90">
<script>
// If true, start function. If false, listen for INIT.
window.onload = function() {
if (Enabler.isInitialized()) {
enablerInitHandler();
} else {
Enabler.addEventListener(studio.events.StudioEvent.INIT, enablerInitHandler);
}
}
function enablerInitHandler() {
// Start ad, initialize animation,
// load in your image assets, call Enabler methods,
// and/or include other Studio modules.
// Also, you can start the Polite Load
}
//If true, start function. If false, listen for VISIBLE.
//So your pageLoadedHandler function will look like the following:
function pageLoadedHandler() {
if (Enabler.isVisible()) {
adVisibilityHandler();
} else {
Enabler.addEventListener(studio.events.StudioEvent.VISIBLE,
adVisibilityHandler);
}
}
function bgExitHandler1(e) {
Enabler.exitOverride('Background Exit1', 'URL');
}
function exitClose(e) {
Enabler.reportManualClose();
Enabler.close();
}
document.getElementById('exit').addEventListener('click', bgExitHandler1, false);
document.getElementById('close_btn').addEventListener('click', exitClose, false);
</script>
<head>
I realized that the issue was caused by the fact that I chose the wrong format. I needed to choose 'interstitial' in order for it to work with my files.
Suppose i want to override a function inside the native code provided by Sencha in the file ext-all-debug.js.
The function is defined inside the Ext.util.Renderable-class and has the name cacheRefEls.
The overriding should take place inside the index.html of the project to make it easier to maintain for future releases.
I have already tried out the override solutions proposed inside this thread:
Steps to overriding Sencha ExtJS standard component functionality (Ext.tree.Panel & Ext.data.TreeStore as two examples)
My index.html looks as follows:
<html>
...
<script type="text/javascript">
Ext.define('Myapp.view.Renderable', {
override: 'Ext.util.Renderable',
cacheRefEls: function(el) {
console.log("in overider method");
//my adapted version of it
}
});
</script>
...
</html>
Unfortunately after accessing the localhost:8080 over Firefox-33 it is visible from the Firebug-2-Console-log that it still uses the native version of the function.
What am i missing here?
In ExtJS 5, you need to move these methods to the privates configuration.
You should have seen the error:
Public method "cacheRefEls" conflicts with private framework method declared by Ext.util.Renderable
You can still override the private method. In your case, the solution would be:
Ext.define('Myapp.view.Renderable', {
override: 'Ext.util.Renderable',
privates: {
cacheRefEls: function(el) {
console.log("in overider method");
//my adapted version of it
}
}
});
Using the addon-sdk of firefox I'm following a tutorial about creating reusable modules, the example uses the geolocation API built into Firefox, so the code is simple:
function getCurrentPosition(callback){
var xpcomGeolocation = Cc["#mozilla.org/geolocation;1"].getService(Ci.nsIDOMGeoGeolocation);
xpcomGeolocation.getCurrentPosition(callback);
}
var widget = require("sdk/widget").Widget({
id: "whereami",
label: "Where Am I?",
contentURL: "http://www.mozilla.org/favicon.ico",
onClick: function(){
console.log("clicked!");
getCurrentPosition(function(position){
console.log("latitude: " + position.coords.latitude);
console.log("longitude: " + position.coords.longitude);
});
}
});
When running firefox with the plugin on, clicking the widget give this error:
Message: [Exception... "Component returned failure code: 0x80570018 (NS_ERROR_XPC_BAD_IID) [nsIJSCID.getService]" nsresult: "0x80570018 (NS_ERROR_XPC_BAD_IID)" location: "JS frame :: resource://gre/modules/XPIProvider.jsm -> jar:file:///tmp/tmpTFowYc.mozrunner/extensions/jid1-LIBIfbK6zvWAiQ#jetpack.xpi!/bootstrap.js -> resource://gre/modules/commonjs/toolkit/loader.js -> resource://jid1-libifbk6zvwaiq-at-jetpack/whereami/lib/main.js :: getCurrentPosition :: line 7" data: no]
According to docs, it's possible to get an error when importing nsIDGeoGeolocation so you must use Cc["#mozilla.org/geolocation;1"].getService(Ci.nsISupports); instead. Also, you must ask for permission to access geolocation, please see section Prompting for permission in
Using geolocation
reference.
By the way, as an advice, I think it will be simpler to use navigator.geolocation.getCurrentPosition(successCallback, errorCallback) since it handles prompting for permission for you, but I don't know what are you trying to do beyond this. Just to explain it a little, you could have an addon page data/index.html where you tell the user you are going to prompt him for his geolocation. Besides this, you must have a PageMod that runs a data/script.js for that addon page page, which has access to navigator.geolocation. That content script may communicate with your lib/main.js file so it has access to the user geo location. Somethings like this:
data/index.html:
<html>
<body>
<h1>Hello user!</h1>
</body>
</html>
data/script.js:
var successCallback = function(position) {
/* this way this script will talk to the pagemod in lib/main.js the user's position */
self.port.emit("gotGeolocation", position.coords.latitude, position.coords.longitude);
};
navigator.geolocation.getCurrentPosition(successCallback, errorCallback);
lib/main.js:
var data = require("sdk/self").data;
var pageMod = require("sdk/page-mod");
var tabs = require("sdk/tabs");
pageMod.PageMod({
/* attach the contentScriptFile to this html page */
include: data.url("index.html"),
contentScriptFile: data.url("script.js"),
onAttach: function(worker) {
/* listen to the script.js worker "gotGeolocation" message */
worker.port.on("gotGeolocation", function(latitude, longitude) {
console.log("latitude:", latitude);
console.log("longitude:", longitude);
});
}
});
/* this will open the index.jtml page and promt the user to access his geo position */
tabs.open(data.url("index.html"));
All this code it's only to better describe the idea, it hasn't been tested and in fact there are some indefinded objects. But I hope to give you an idea of how you can acces navigator.geolocation and pass its coords to the main.js script.
I think that you just forgot this at the top:
var { Cc, Ci } = require('chrome');
Also there a third party module for geolocation https://github.com/ZER0/geolocation
I'm having an issue here when attempting to build an integration to our partners. They're gonna submit an image URL as a GET-variable, which I obviously don't want to print straight up. The submitted image URL is submitted back to our servers with AJAX to be sanitized, returned and then updated.
What I want to do here is when the model loads, I want to display a placeholder image, and when the sanitation check is done by the server, it will return the URL (the same or another placeholder) that is to be set as the template image source.
Now, the problem is that I don't get how to make Ember listen for the update of this event. I'm trying to use observes, but apparently, this isn't available in the route. Here's my current code:
ROUTE
MyApp.PartnerRoute = Ember.Route.extend({
imageUrl: "/img/placeholder.png";
getImageUrl: function(imageUrlToCheck) {
instance = this;
$.ajax({
url: "/ajax/get-image-url",
type: "post",
data: {
"imageUrl": imageUrlToCheck
},
success: function(response) {
if(response.status === 0) {
instance.set("imageUrl", response.data.imageUrl);
}
}
});
},
// Ember update property.
imageUrlDidChange: function() {
this.get("imageUrl");
}.observes("imageUrl"),
model: function(params) {
this.getImageUrl(params.imageUrl);
return {
heading: "Welcome!",
imageUrl: this.imageUrl
}
}
});
VIEW
<script type="text/x-handlebars" data-template-name="partner">
<h1>{{heading}}</h1>
<img {{bind-attr src=imageUrl}} />
</script>
I get the error message:
Uncaught TypeError: Object function () {
this.get("imageUrl");
} has no method 'observes'
I'm not at all sure as of how to make this happen. Am I going about this the wrong way? Any help is appreciated.
Thank you for your time.
Best regards,
dimhoLt
PS. I've extracted the applicable pieces of code from much bigger objects, so if there are any typos, missing commas etc, it's due to the copy-paste and is not applicable to the actual code.
EDIT:
Worth noting is that because of legacy functionality I haven't yet rewritten, I was forced to turn off Ember extended prototypes. This is, I guess, the major cause of the issue.
Since I wrote this, I've also gone over to using a fixed model instead of attempting to work directly with the route.
You need to use a setter
http://emberjs.jsbin.com/OxIDiVU/117/edit
model: function(params) {
var model = {
heading: "Welcome!",
imageUrl: this.imageUrl
};
this.getImageUrl(params.imageUrl).then(function(result){
Em.set(model, 'imageUrl', result.imageUrl);
});
return model;
}
I'm using the following to grab some updated HTML and insert it into a div with id "content"
var updater = new Ajax.PeriodicalUpdater('content', '/Doc?'+d.getTime(),
{
method: 'post',
frequency: 5,
});
The problem is that when the server is shut down (it's running inside of an app that is modifying and server up the data), the updater then simply clears out the content div.
Is there a way to make it so that when PeriodicalUpdater times out, gets a 404, etc. it just leaves the content unchanged? I would rather that the last available data just stay there, not be erased.
For completeness, this is my entire code:
<html>
<head>
<title></title>
<script type="text/javascript" src="/Prototype"></script>
<script type="text/javascript">
var css;
var css_data;
function load_content()
{
var d = new Date();
css = document.createElement('style');
css.setAttribute('type', 'text/css');
if(css.styleSheet) { css.styleSheet.cssText = '';} //Because IE is evil
else { css_data = document.createTextNode(''); css.appendChild(css_data); } //And everyone else is cool
document.getElementsByTagName("head")[0].appendChild(css);
var updater = new Ajax.PeriodicalUpdater({success: 'content'}, '/%doc_path%?'+d.getTime(),
{
method: 'post',
frequency: 5,
onSuccess: function(transport) {
new Ajax.Request('/%css_path%?'+d.getTime(), {
method: 'post',
onSuccess: function(transport) {
if(css.styleSheet) { css.styleSheet.cssText = transport.responseText}
else {
var new_css_data = document.createTextNode(transport.responseText);
css.replaceChild(new_css_data, css_data);
css_data = new_css_data;
}
}
});
new Ajax.Request('/%title_path%?'+d.getTime(), {
method: 'post',
onSuccess: function(transport) {
document.title = transport.responseText;
}
});
}
});
}
</script>
</head>
<body>
<div id="content"></div>
<script type="text/javascript">
load_content();
</script>
</body>
</html>
As you can see, I tried Triptych's solution...but still no go. It updates with blank data when the request fails still. Since I've got the whole thing here now, can anyone see any mistakes I'm making.
Note: Ignore the strings like %doc_path%... those are just control strings I use so that they can later be replaces programmatically with the proper path for each document...all stuff that's done on the server and really doesn't matter for this.
#Vinze
According to the documentation, onFailure is "Invoked when a request completes and its status code exists but is not in the 2xy family. This is skipped if a code-specific callback is defined, and happens before onComplete."
But if the server was stopped, wouldn't it just time out and there be no status code at all? Maybe I'm understanding that wrong...
Pass an object (not a string) as the first parameter to PeriodicalUpdater. The value keyed as 'success' will only be called on successful AJAX calls.
new Ajax.PeriodicalUpdater({success: 'content'}, '/Doc?'+d.getTime(),
{
method: 'post',
frequency: 5,
});
More on Ajax.Updater (from which PeriodicalUpdater inherits)
you can add a onFailure option in the option list as the Ajax.PeriodicalUpdater inherits the properties of Ajax.Request (http://www.prototypejs.org/api/ajax/request)
In the opposite you may be more interested in the use of "onComplete" or any of the "Request life-cycle" in the link below
How about doing it all by yourself?
Start with a function that will call the update:
function requestMoreInfo(){
new Ajax.Request('url',
{
method:'get',
parameters: "someget=here",
onSuccess: handleTheReturn
});
}
Then create a function that will handle the answer from the server:
function handleTheReturn(reply){
var newMessages = eval('(' + reply.responseText + ')');
//update your element or whatever
}
And then run it every 20(or whatever) seconds with:
new PeriodicalExecuter(requestMoreInfo, 20);
Then just add a first requestMoreInfo to your onload function and your good to go... now to solve your problem, just validate the newMessages var in the handleTheReturn function and you can do anything you want(make the server send a JSON object to know is ok, or some other codes maybe, or search for the specific errors you want to avoid!
More details on this.
Ajax.PeriodicalUpdater does not inherit from Ajax.Updater, as explained on http://www.prototypejs.org/api/ajax/periodicalupdater:
Ajax.PeriodicalUpdater is not a specialization of Ajax.Updater, despite its name.
It does forward the optional parameters to Ajax.Updater (itself a class that inherits from Ajax.Request), which does seem to imply that it is equivalent to instantiating an Ajax.Request and passing callbacks to it.
I have tested and can confirm that adding a onFailure function does not work in this case. Nor does adding onException.
Both could have been expected to work, since they are passed to the Ajax.Updater object instantiated by the Ajax.PeriodicalUpdater. However, after some debugging, it appears that Ajax.Updater never considers an unavailable server as an exception or a failure. That is, the container for success is always updated (well, emptied, in this case), even when defined as {success : 'content', failure : 'failureContent'}.
Also, according to my tests, Ajax.Updater (and Ajax.PeriodicalUpdater) calls neither onSuccess() nor onComplete() when the server does not respond.
In fact, the only callback I managed to get is on0, as follows:
new Ajax.PeriodicalUpdater('content', 'url', {
frequency: 5,
on0: function(requester, exception) {
alert("ERROR 0");
}
});
It appears that 0 is the error code for Ajax.Request (the parent class for Ajax.Updater) when the server is not reachable.
The bad news, however, is that on0() is called before the content is updated/emptied, meaning that it is impossible to replace that content with a custom one.
As far as I can tell, in the case of the server being unreachable, no optional callback at all is called after the content is updated.
This is true both for Ajax.PeriodicalUpdater and Ajax.Updater. Meaning that the only way I see to get the wanted behavior is to use Ajax.Request directly.