Skip to content

Instantly share code, notes, and snippets.

@ericmadethat
Created March 31, 2015 07:49
Show Gist options
  • Save ericmadethat/543493917d4535165bab to your computer and use it in GitHub Desktop.
Save ericmadethat/543493917d4535165bab to your computer and use it in GitHub Desktop.
broadcast wip
<template name="broadcast">
{{#if userIsPresenter}}
<button id="launchConf">Launch Conference</button> <br />
<button id="exit">Exit</button>
<button id="joinConf">Join</button>
{{/if}}
{{#if userIsViewer}}
<button id="watchConf">Only watch conf</button> <br />
{{/if}}
<!-- <button id="joinConf">Join for not logged in</button> <br /> -->
</template>
// If user is presenter and if there is no current session= show Launch button
// If user is presenter and there is already a session = show Join button
// If user is viewer and there is a current session = show Join button but dont broadcast
// If user is viewer and there is no session = show nothing until there is a session, then show join button.
Deps.autorun(function(){
Template.broadcast.onRendered( function(){
// -------------INITIAL SETTINGS----------------------
var launchConf = document.querySelector('#launchConf');
var joinConf = document.querySelector('#joinConf');
var watchConf = document.querySelector('#watchConf');
var videos = document.querySelector('#videos');
var role = Meteor.user().roles;
console.log("ROLE AT STARTUP:" + role);
window.connection = new RTCMultiConnection();
connection.dontOverrideSession = true;
connection.session = {
audio: true,
video: true,
oneway: role == 'viewer'
};
connection.onstream = function(e) {
videos.appendChild(e.mediaElement);
if (e.type == 'remote') {
connection.askToShareParticipants();
}
if (connection.isInitiator && e.type == 'remote' && !e.session.oneway) {
connection.shareParticipants({
dontShareWith: e.userid
});
}
};
// connection.onNewSession = function(session) {
// if (role == 'viewer') {
// session.join({
// oneway: true
// });
// }
// if (role == 'presenter') {
// session.join();
// }
// if (role == 'undefined') {
// session.join({
// oneway: true
// });
// }
// };
// Starts a connection channel
// connection.connect(connection.channel);
// -----------END INITIAL SETTINGS------------------------------------------
// -------------BUTTONS BUSINESS LOGIC-----------------------------
if (launchConf) {
launchConf.onclick = function() {
this.disabled = true;
// 'connection.open' will create a channel, create a room, and join it.
connection.open({
sessionid: connection.channel,
captureUserMediaOnDemand: false
});
console.log("--CREATING ROOM AND JOINING");
}
};
// joinConf button should only be shown if a room has been intialized
// will need to refactor logic later
// clicking this will call onNewSession
// joinConf.onclick = function() {
// this.disabled = true;
// console.log('JOINING PRE-EXISTING ROOM OR TRYING TO');
// }
if (joinConf) {
connection.connect(connection.channel);
connection.onNewSession = function(session) {
joinConf.onclick = function() {
this.disabled = true;
console.log('joining pre-existing room or trying too');
session.join();
}
};
};
if (watchConf) {
connection.connect(connection.channel);
connection.onNewSession = function(session) {
watchConf.onclick = function() {
this.disabled = true;
console.log('just watching!');
session.join({
oneway: true
});
}
};
};
});
Template.broadcast.helpers({
userIsPresenter: function () {
if (Meteor.user()) {
return Meteor.user().roles === "presenter";
}
},
userIsViewer: function () {
if (Meteor.user()) {
return Meteor.user().roles === "viewer";
}
},
conferenceStarted: function () {
return true;
}
});
});
connection.open
Does 2 things: sets up a RTCMultisession connection (similar to what connection.connect does) but will also create a 'session /room' and join it.
connection.connect
If there is already a RTCMultisession set up (by 'connection.open'), it will connect to it, but will not JOIN it automatically. It will however CALL 'connection.onNewSession'. If 'connection.open' didn't set up a RTCMultisession yet, then 'connection.connect' will set one up, but will not create a new room.
connection.onNewSession
This lays the rules for what happens when the RTCMultisession detects a new incoming connection. In here, we called 'session.join' to officially join the room.
connection.onstream
This just lays the rules on how to handle the incoming video media I think.
-------
Problems I don't know how to fix yet
- I have to manually refresh the page for Meteor to detect my new 'role' status.
e.g. My role will be 'undefined' on startup. If i log in Github, my role is still 'undefined' until I refresh the page.
Is this normal?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment