JavaScript API can be used for web sites running on mobile or desktop web browsers. It is compatible with any modern browsers that support web sockets. JavaScript API supports ONLY Chrome , FireFox , Opera.
Include the library in your SmartTV applications HTML page
<!DOCTYPE html>
<html>
<head lang="en">
<!-- Add the script to your html (exposes a `msf` object to the window) -->
<script src="scripts/vendor/msf-2.0.x.min.js"></script>
</head>
...
</html>
API Usage
Discovery
In order for a client to start or join a MultiScreen experience, the client application must be able to discover a compatible SmartTV service. The API manages searching for compatible services and only requires a few lines of code. Below is a chunk of code from the Hello World mobile web application
ImportantJS Libary version 2.3.3 is changed search API. It works on only Chrome, Firefox, Opera except IE, Safari
Example :
var search = msf.search();
search.on('found', function(services){
for(var i=0; i<services.length; i++){
console.log('Found service '+services[i].name);
}
});
search.start();
Connect
Once a compatible SmartTV is discovered, you can launch and connect to your SmartTV application from you mobile client. Application management is centralized to a single class (Application) that handles starting, stopping, installing, and connecting to your application. Here is a quick example.
Example :
// The first argument is the application id or hosted url
// The second is the channel (communication) id you will use for your application
var app = service.application('http://mydomain.com/myapp','com.mydomain.myapp');
// App connect supports callback and event listener coding styles
app.connect({name: 'John Doe'}, function (err) {
if(err) return console.error(err);
console.log('callback : you are connected');
});
Communicate
Once your client has started and established a connection with the SmartTV application, You can use the applications channel to send and receive messages between the devices. The Application class extends Channel, so in the example below we will continue with application instance we created earlier. Applications also provide notifications when someone connects, disconnects, and publishes a message.
Example:
app.on('clientConnect', function(client){
// This will publish the say event to the client that connected
app.publish('say', 'Hello '+client.attributes.name, client.id);
});
// This event will fire when another client publishes the `say` event to a target including your client
app.on('say', function(msg, fromClient){
console.log(fromClient.attributes.name + ' says, ' + msg);
});
Manage Your Cookies
We use cookies to improve your experience on our website and to show you relevant
advertising. Manage you settings for our cookies below.
Essential Cookies
These cookies are essential as they enable you to move around the website. This
category cannot be disabled.
Company
Domain
Samsung Electronics
.samsungdeveloperconference.com
Analytical/Performance Cookies
These cookies collect information about how you use our website. for example which
pages you visit most often. All information these cookies collect is used to improve
how the website works.
Company
Domain
LinkedIn
.linkedin.com
Meta (formerly Facebook)
.samsungdeveloperconference.com
Google Inc.
.samsungdeveloperconference.com
Functionality Cookies
These cookies allow our website to remember choices you make (such as your user name, language or the region your are in) and
tailor the website to provide enhanced features and content for you.
Company
Domain
LinkedIn
.ads.linkedin.com, .linkedin.com
Advertising Cookies
These cookies gather information about your browser habits. They remember that
you've visited our website and share this information with other organizations such
as advertisers.
Company
Domain
LinkedIn
.linkedin.com
Meta (formerly Facebook)
.samsungdeveloperconference.com
Google Inc.
.samsungdeveloperconference.com
Preferences Submitted
You have successfully updated your cookie preferences.