Skip to content

Instantly share code, notes, and snippets.

View tokafish's full-sized avatar

Thomas Fisher tokafish

  • Plaid
  • San Francisco
View GitHub Profile
@tokafish
tokafish / video.js
Last active August 29, 2015 14:06
Adding video
navigator.getUserMedia({ video: true, audio: true }, function(stream) {
currentUser.stream = stream;
}, function() {});
// ...
peer = new SimplePeer({ stream: currentUser.stream });
peer.on('stream', function(stream) {
var video = document.querySelector("video");
var peer = new SimplePeer({ initiator: true });
peer.on('signal', function (data) {
channel.trigger('client-signal-' + peerUserId, { userId: currentUser.id, data: data });
});
peer.on('ready', function () {
peer.send('hey peer, how is it going?')
});
@tokafish
tokafish / local-peer.js
Created September 9, 2014 00:33
Simple Peer
var peer1 = new SimplePeer({ initiator: true });
var peer2 = new SimplePeer();
peer1.on('signal', function (data) {
// when peer1 has signaling data, give it to peer2
peer2.signal(data);
});
peer2.on('signal', function (data) {
// same as above, but in reverse
@tokafish
tokafish / pusher_controller.rb
Last active December 9, 2016 20:44
Pusher Authentication
class PusherController < ApplicationController
protect_from_forgery except: :auth
def auth
response = Pusher[params[:channel_name]].authenticate params[:socket_id],
user_id: params[:id],
user_info: { name: params[:name] }
render json: response
end
@tokafish
tokafish / getUserMedia.html
Last active August 29, 2015 14:06
getUserMedia
<!DOCTYPE html>
<html>
<head><title>getUserMedia</title></head>
<body>
<video autoplay></video>
<script>
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
var constraints = { audio: false, video: true };
app.directive('isolated', function() {
return {
scope: {
message: '='
},
template: '<input ng-model="message.content"><span>{{message.content}}</span>'
};
});
@tokafish
tokafish / directive.js
Last active August 29, 2015 13:56
Isolated scopes
app.directive('isolated', function() {
return {
scope: {},
template: '<input ng-model="message.content"><span>{{message.content}}</span>'
};
});
@tokafish
tokafish / edit.html
Created February 10, 2014 18:03
ngModel and scope inheritance
<div ng-controller="EditController">
<span>{{message.content}}</span>
<div ng-if="userIsAdmin">
<span>Edit Message</span>
<input ng-model="message.content"/>
</div>
</div>
@tokafish
tokafish / controllers.js
Last active August 29, 2015 13:56
Nested scopes
app.controller('OuterController', function($scope) {
$scope.outer = 'From the outside';
});
app.controller('InnerController', function($scope) {
$scope.inner = 'looking in.';
});
@tokafish
tokafish / controllers.js
Last active August 29, 2015 13:56
Multiple scopes
app.controller('HelloController', function($scope) {
$scope.message = 'Hello World!';
});
app.controller('GoodbyeController', function($scope) {
$scope.message = 'Goodbye World!';
});