According to the Google Custom Receiver documentation, if our app performs authentication we can load the customData in json format in our sender application. In my case, I did something similar to the following,
MediaInfo mediaInfo = new MediaInfo.Builder(
"url")
.setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
.setCustomData(jsonCustomData)
.build();
Then loaded the mediaInfo like the following,
mRemoteMediaPlayer.load(mApiClient, mediaInfo, true).setResultCallback(....);
In my receiver application, I tried to retrieve the jsonCustomData like the following,
var customData = window.mediaManager.LoadRequestData.customData;
However, it doesn't seem like it's working. I've noticed that in some sample apps, some people use the Cast.CastApi.sendMessage method, and use window.message.onMessage=function(event) where event.data would contain the message. Could someone explain the difference between these two methods? what am I doing wrong?
Notice my receiver code is not wrapped a window.onload function, do I need to?
Thanks for the help!
You may want to hook into mediaManager.onLoad(event) callback (see this for how to do that properly; you need to make sure you call the original onLoad in your implementation). Then, if my memory serves me right, event.data should be of the type cast.receiver.mediaManager.LoadRequestData. If so, event.data.media.customData should have the custom data that you specified in your mediaInfo. If you use customData in your mRemoteMediaPlayer.load() command (instead of the mediaInfo), then it should be accessible in the same callback but through event.data.customData. Please validate this against the receiver API reference to make sure they are correct.
Related
I am rather confused with mechanics and hierarchy of things in javascript, reading few links and pages are adding to them.
There are various ways to create objects in Javascript. What I am getting confused is in following:
I have 3 websocket say WSServiceA, WSServiceB, WSServiceC : These are 3 different sockets and provide different data but data structure is same. Using a simple function I am updating 3 tables in web-page.
Each of these have onopen, onclose and onmessage function so I have simply copied same code 3 times, like this:
WSServiceA.onmessage(){}
WSServiceB.onmessage(){}
WSServiceC.onmessage(){}
If I create a something like this:
function CreateService(Service, WSAddress){
this.service=Service;
this.WSAddress = WSAddress;
this.websocket = new WebSocket(this.WSAddres);
this.onopen = function(event){ Send some message }
this.onmessage = function(event){ Update Table A}
}
After that I will create
ServiceA = CreateService("A", "ws://192.168.100.1.1:10001");
ServiceB = CreateService("B", "ws://192.168.100.1.2:10001");
ServiceC = CreateService("C", "ws://192.168.100.1.3:10001");
Then how and who will call ServiceA.onopen, Service.onmessage and other functions - when data comes to those sockets? Will it be called at all? Something created inside function should be visible only in that function - I am not able to understand flow and link. Probably I am missing some key concept or this should not work.
Background
There is ECMAScript, which is the language, and javascript, which is a generic name for an implementation of ECMAScript for a particular host (noting that JavaScriptâ„¢ is a trademark of Oracle Corporation).
ECMAScript by itself does very little, it doesn't even have a mechanism for input or output, it must be provided by the host. In regard to WebSockets, if the host supports them then it will implement the WebSockets API.
When you create a WebSocket through new WebSocket(...), then the host returns a host object that implements the interface. The object will have a state that changes in response to its environment (connecting, open, closing, closed) and it will dispatch events when certain things happen.
When the socket successfully makes a connection to the server, it will dispatch an open event on the socket, so that if there is an onopen listener, it will respond to the event by being called by the open handler. There are also events for error and close that have associated on* handlers.
Answer
Then how and who will call ServiceA.onopen, Service.onmessage and
other functions - when data comes to those sockets?
The host environment implementing the interface does all that.
I am new to netsuite scripting using javascript. I like to ask, how can I set field mandatory to false using javascript.
Hope that someone can help me.
Note :
If you use nlapiGetField(fieldname) in a client script to return a nlobjField object, the object returned is read-only. This means that you can use nlobjField getter methods on the object, however, you cannot use nlobjField setter methods to set field properties.
However you can use
nlapiSubmitRecord(item_obj, true, true); to ignore mandatory fields on a record.
For more details check out the included parameters in the method.
nlapiSubmitRecord(record, doSourcing, ignoreMandatoryFields);
You are using the correct methods, but setMandatory is not supported in a client script. You can instead try using the exact same code in a User Event, Before Load event handler.
Contrary to the documentation, the nlobjField returned by nlapiGetField is not read-only. Some of the setter methods still work (e.g. setDisplayType) on the client side. You can experiment with which ones do and do not work, but setMandatory is confirmed as not supported on the client side.
Using SS2.0 on a client script you can make it mandatory with this code:
var newSupervisorField = context.currentRecord.getField('custrecord_new_supervisor');
newSupervisorField.isMandatory = true;
This is what worked for me based on the input from #erictgrubaugh and #user3627301
function fieldChanged(type,name){
var metodPayment=nlapiGetFieldText('field_id_to_check');
if ((name == 'field_id_to_monitor_for_change') && (metodPayment=='Financing')) {
var field1 = nlapiGetField('field_id_to_be_disabled');
field1.setDisplayType('disabled');
}
}
You can set mandatory using SuiteScript 2.0 though although it does not works in 1.0.
Below, is an example snippet using client script on customer record
var currentRecord;require(['N/currentRecord'], (currentRecord) => {
var field = currentRecord.get().getField('comments');
field.isMandatory = true;
})
Maybe my answer was already late but for others that came across this post, this is how I do it via client script.
nlapiSetFieldMandatory('yourFieldId', true);
This was already tested because I am using this often. Though some says you cannot set fields to mandatory via client but you can. I did not find any docs about this on netsuite docs though.
I have a Parse.com cloud function that sends back a PFObject. In some cases I need to send back values for keys that don't exist in the PFObject. Is that possible?
This is what I tried:
var test = prodAndTitles["products"][0];
test["XOXO"] = "kisses";
prodAndTitles["products"][0] = test;
console.log("XOXO = " + prodAndTitles["products"][0]["XOXO"]);
This prints out kisses as expected.
But back in the app when I try to get the XOXO key it's not there:
NSLog(#"The product's XOXO %#", [self.product objectForKey:#"XOXO"]);
This prints out null.
I also tried changing the product type from PFObject to id, but it doesn't help.
Is there a solution, without going into the datastore class and creating dummy columns?
Here's a complete answer to the problem I faced:
The issue is that none of the notations above works for the Parse.com backbone javascript objects that come from the datastore. This is the notation that does work:
testObject.set('TestProp', 'TestValue');
But this is still only part of the solution. When trying to send the testObject with the newly set property to the client ios app, it causes an error:
Uncaught Tried to save an object with a pointer to a new, unsaved object.
The solution for this is to save the testObject after setting the property:
testObject.save();
This doesn't really make sense because I would have liked to add properties to the testObject and NOT save them to the datastore -- and it's a waste of a database call -- but it seems like Parse won't allow it. Weird.
This is done with setting the correct ACL. The ACL has to be set for the user to be able to read and write. Then you can add new columns. In Cocoa it looks something like this:
PFACL *acl = [PFACL ACL];
[acl setReadAccess:YES forUser:[PFUser currentUser]];
[acl setWriteAccess:YES forUser:[PFUser currentUser]];
[test setACL:acl];
I need a client-side routing solution to work with a chrome app. I've researched several and crossroads.js seems like a good fit. When I include it in my html file, it doesn't seem to work; that is, if I use code like
crossroads.addRoute('/news/{id}', function(id){
alert(id);
});
crossroads.parse('/news/123');
, the page alerts '123' but if I type '/news/321' in the browser's url bar, it preforms the browser's default action, instead of alerting '321'. What am I doing wrong. (Also, I realize the title is broad, but I believe the difficulties I'm having with crossroads.js are more general than crossroads.js in particular. It is given as an example.)
Use Hasher (by the same author) also.
The documentation on the Crossroads page tells you that you need to use Hasher, (because that will be used for monitoring the widow.location bar.).
So you would also need to use Hasher, and initialise it, then you can add your "Crossroads" routes to Hasher to start monitoring for those particular routes.
//setup crossroads
crossroads.addRoute('foo');
crossroads.addRoute('lorem/ipsum');
crossroads.routed.add(console.log, console); //log all routes
//setup hasher
hasher.initialized.add(crossroads.parse, crossroads); //parse initial hash
hasher.changed.add(crossroads.parse, crossroads); //parse hash changes
hasher.init(); //start listening for history change
//update URL fragment generating new history record
hasher.setHash('lorem/ipsum');
http://millermedeiros.github.com/crossroads.js/
The command parse tells crossroads to have a look at the string and do an action based on it.
So in the case of crossroads.parse('/news/123'); it will always use /news/123.
Since you want crossroads to parse what you have in the browser address bar, you'll need to use that value in the parse method:
crossroads.parse(document.location.pathname);
I know that for safety reasons that this is not easy to achieve, however there would be a way to do so as firebug does...
Please help, would like to invoke some script in the page's context to achieve some effect...
Basically, I would like to achieve two functionality:
1. add jQuery to any web page automatically if not already exist.
2. when open certain address, call a method of that page to auto notify the server. (an ajax functionality of the page)
I have tried to inject on the body, no luck.
tried to get the window object, which however do not have access to call the function.
Will try to change the location to something like: javascript:alert('test inject');
Many thx.
OK, after reading some official documentation and the GreaseMonkey's source, I get the following method which basically works for me.
Hope it will save sb's hour:
var appcontent = document.getElementById("appcontent"); // browser
if (appcontent) {
appcontent.addEventListener("DOMContentLoaded", function (evnt) {
var doc = evnt.originalTarget;
var win = doc.defaultView;
var unsafeWin = win.wrappedJSObject;
// vote.up is the function on the page's context
// which is take from this site as example
unsafeWin.vote.up(...);
}, true);
}
}
Greasemonkey does that. If you are developing your own extension with similar functionality, you can use Components.utils.evalInSandbox.