Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code for Victor for debugging PhoneGap Crash!
var apiKey = '16178811';
var sessionId = '1_MX4xNjE3ODgxMX4xMjcuMC4wLjF-RnJpIERlYyAxNCAxODoyMDo1NyBQU1QgMjAxMn4wLjMwMDcxMDM4fg';
var token = 'T1==cGFydG5lcl9pZD0xNjE3ODgxMSZzaWc9OTM0YzJmYjk3YTZjMmY0ZmIzODFiZjE0YjMxNzZlMDVlYTQ4MDJjZDpzZXNzaW9uX2lkPTFfTVg0eE5qRTNPRGd4TVg0eE1qY3VNQzR3TGpGLVJuSnBJRVJsWXlBeE5DQXhPRG95TURvMU55QlFVMVFnTWpBeE1uNHdMak13TURjeE1ETTRmZyZjcmVhdGVfdGltZT0xMzU1NTM4MDY1JmV4cGlyZV90aW1lPTEzNTgxMzAwNjUmcm9sZT1wdWJsaXNoZXImY29ubmVjdGlvbl9kYXRhPSZub25jZT0xNTY3MA==';
TB.setLogLevel(TB.DEBUG);
var session = TB.initSession(sessionId);
session.addEventListener('sessionConnected', sessionConnectedHandler);
session.addEventListener('streamCreated', streamCreatedHandler);
session.connect(apiKey, token);
var publisher;
function sessionConnectedHandler(event) {
publisher = TB.initPublisher(apiKey, 'myPublisherDiv');
session.publish(publisher);
// Subscribe to streams that were in the session when we connected
subscribeToStreams(event.streams);
}
function streamCreatedHandler(event) {
// Subscribe to any new streams that are created
subscribeToStreams(event.streams);
}
function subscribeToStreams(streams) {
for (var i = 0; i < streams.length; i++) {
// Make sure we don't subscribe to ourself
if (streams[i].connection.connectionId == session.connection.connectionId) {
return;
}
// Create the div to put the subscriber element in to
var div = document.createElement('div');
div.setAttribute('id', 'stream' + streams[i].streamId);
document.body.appendChild(div);
// Subscribe to the stream
session.subscribe(streams[i], div.id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.