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

Dev #18

Closed
wants to merge 9 commits into from
Closed

Dev #18

Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "samples"]
path = samples
url = https://github.com/stomp-js/samples.git
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ See [LICENSE](LICENSE).

## Terms
Your use of this sample is subject to, and by using or downloading the sample files you agree to comply with, the [Google APIs Terms of Service](https://developers.google.com/terms/) and the [Google Cast SDK Additional Developer Terms of Service](https://developers.google.com/cast/docs/terms/).
## TODO
- new work
2 changes: 1 addition & 1 deletion css/receiver.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ cast-media-player {
/* Sample Overlay Text */
/* ------------------------------------------------- */
cast-media-player:after {
content: "SAMPLE";
content: "Simple Joy";
position: absolute;
left: 0;
right: 0;
Expand Down
105 changes: 105 additions & 0 deletions js/receiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,111 @@ Cast.

import { CastQueue } from './queuing.js';

const client = new StompJs.Client({
brokerURL: "ws://localhost:15674/ws",
connectHeaders: {
login: "guest",
passcode: "guest"
},
debug: function (str) {
console.log(str);
},
reconnectDelay: 5000,
heartbeatIncoming: 4000,
heartbeatOutgoing: 4000
});

client.debug = function(str) {
console.log(str);
};

client.onConnect = function(frame) {
// Do something, all subscribes must be done is this callback
// This is needed because this will be executed after a (re)connect
};

client.onStompError = function (frame) {
// Will be invoked in case of error encountered at Broker
// Bad login/passcode typically will cause an error
// Complaint brokers will set `message` header with a brief message. Body may contain details.
// Compliant brokers will terminate the connection after any error
console.log('Broker reported error: ' + frame.headers['message']);
console.log('Additional details: ' + frame.body);
};

client.activate();

function generateBinaryData() {
let buffer = new Int8Array(16);
return buffer
}
var binaryData = generateBinaryData(); // This need to be of type Uint8Array
// setting content-type header is not mandatory, however a good practice
client.publish({destination: '', binaryBody: binaryData,
headers: {'content-type': 'application/octet-stream'}});
// client.publish({destination: '/topic/general', body: 'Hello world'});
//
// // There is an option to skip content length header
client.publish({destination: '/example', body: 'Hello world', skipContentLengthHeader: true});
//
// // Additional headers
// client.publish({destination: '/topic/general', body: 'Hello world', headers: {'priority': '9'}});


var callback = function(message) {
// called when the client receives a STOMP message from the server
if (message.body) {
alert("got message with body " + message.body)
} else {
alert("got empty message");
}
};
var subscription = client.subscribe("/queue/test", callback);

// Create a socket instance
//var socket = new WebSocket('ws://localhost:61613');
//
//// Open the socket
//socket.onopen = function(event) {
//
// // Send an initial message
// socket.send('I am the client and I\'m listening!');
//
// // Listen for messages
// socket.onmessage = function(event) {
// console.log('Client received a message',event);
// };
//
// // Listen for socket closes
// socket.onclose = function(event) {
// console.log('Client notified socket has closed',event);
// };
//
// // To close the socket....
// socket.close()
//
//};

const context = cast.framework.CastReceiverContext.getInstance();
const playerManager = context.getPlayerManager();

// enable debug log
context.setLoggerLevel(cast.framework.LoggerLevel.DEBUG);
const castDebugLogger = cast.debug.CastDebugLogger.getInstance();

// Enable debug logger and show a warning on receiver
// NOTE: make sure it is disabled on production
castDebugLogger.setEnabled(true);

// Show debug overlay
castDebugLogger.showDebugLogs(true);

// Listen and log all Core Events.
playerManager.addEventListener(cast.framework.events.category.CORE,
event => {
console.log("Core event: " + event.type);
console.log(event);
castDebugLogger.info("ANALYTICS", event);
});

playerManager.addEventListener(
Expand All @@ -41,9 +138,16 @@ playerManager.addEventListener(
// Intercept the LOAD request to be able to read in a contentId and get data.
playerManager.setMessageInterceptor(
cast.framework.messages.MessageType.LOAD, loadRequestData => {
castDebugLogger.info('MyAPP.LOG', 'Intercepting LOAD request');
return loadRequestData;
});

// Set verbosity level for custom tags
castDebugLogger.loggerLevelByTags = {
'MyAPP.LOG': cast.framework.LoggerLevel.WARNING,
'ANALYTICS': cast.framework.LoggerLevel.INFO,
};

const playbackConfig = new cast.framework.PlaybackConfig();

// Set the player to start playback as soon as there are five seconds of
Expand Down Expand Up @@ -73,6 +177,7 @@ controls.assignButton(
)

context.start({
maxInactivity: 3600,
queue: new CastQueue(),
playbackConfig: playbackConfig,
supportedCommands: cast.framework.messages.Command.ALL_BASIC_MEDIA |
Expand Down
Loading