Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated readme examples to es6 #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ Usage
-----

```js
var Client = require('castv2').Client;
var mdns = require('mdns');
const Client = require('castv2').Client;
const mdns = require('mdns');

var browser = mdns.createBrowser(mdns.tcp('googlecast'));
const browser = mdns.createBrowser(mdns.tcp('googlecast'));

browser.on('serviceUp', function(service) {
browser.on('serviceUp', service => {
console.log('found device %s at %s:%d', service.name, service.addresses[0], service.port);
ondeviceup(service.addresses[0]);
browser.stop();
Expand All @@ -43,27 +43,27 @@ browser.start();

function ondeviceup(host) {

var client = new Client();
client.connect(host, function() {
const client = new Client();
client.connect(host, () => {
// create various namespace handlers
var connection = client.createChannel('sender-0', 'receiver-0', 'urn:x-cast:com.google.cast.tp.connection', 'JSON');
var heartbeat = client.createChannel('sender-0', 'receiver-0', 'urn:x-cast:com.google.cast.tp.heartbeat', 'JSON');
var receiver = client.createChannel('sender-0', 'receiver-0', 'urn:x-cast:com.google.cast.receiver', 'JSON');
const connection = client.createChannel('sender-0', 'receiver-0', 'urn:x-cast:com.google.cast.tp.connection', 'JSON');
const heartbeat = client.createChannel('sender-0', 'receiver-0', 'urn:x-cast:com.google.cast.tp.heartbeat', 'JSON');
const receiver = client.createChannel('sender-0', 'receiver-0', 'urn:x-cast:com.google.cast.receiver', 'JSON');

// establish virtual connection to the receiver
connection.send({ type: 'CONNECT' });

// start heartbeating
setInterval(function() {
setInterval(() => {
heartbeat.send({ type: 'PING' });
}, 5000);

// launch YouTube app
receiver.send({ type: 'LAUNCH', appId: 'YouTube', requestId: 1 });

// display receiver status updates
receiver.on('message', function(data, broadcast) {
if(data.type = 'RECEIVER_STATUS') {
receiver.on('message', (data, broadcast) => {
if (data.type = 'RECEIVER_STATUS') {
console.log(data.status);
}
});
Expand Down