Last active
December 27, 2015 07:49
-
-
Save ctborg/7292184 to your computer and use it in GitHub Desktop.
Cleaned up GoInstant GoAngular example: https://developers.goinstant.com/v1/GoAngular/API/platform.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html ng-app="FormSync"> | |
<head> | |
<title>GoAngular Form Synchronization</title> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script> | |
<script src="https://cdn.goinstant.net/v1/platform.min.js"></script> | |
<script src="https://cdn.goinstant.net/integrations/goangular/latest/goangular.min.js"></script> | |
<script> | |
// Create our AngularJS application module & require the goinstant module | |
var app = angular.module('FormSync', ['goinstant']); | |
// The provider will join this room for us | |
var connectUrl = 'https://goinstant.net/YOURACCOUNT/YOURAPP'; | |
var rooms = ['exampleRoom', 'exampleRoomTwo']; | |
// Configure our connection with the platformProvider | |
app.config(function(platformProvider) { | |
platformProvider.set(connectUrl, { rooms: rooms }); | |
}); | |
// We could even use GoInstant directly in our controller! | |
app.controller('completeControl', function($scope, platform) { | |
// platform is a promise, resolved once a connection is established | |
platform.then( | |
// We're successfully connected | |
function(platform) { | |
console.log('Connected to GoInstant!'); | |
// We've already joined this room because we specified it in | |
// our configuration | |
var yourRoom = platform.rooms['exampleRoom']; | |
function myListener(user) { | |
console.log('A new user, "' + user.displayName + '", joined the room'); | |
} | |
yourRoom.on('join', myListener, function(err) { | |
if (err) { | |
// unable to deregister. clean up or retry. | |
} | |
// myListener is now set up to recieve events | |
}); | |
}, | |
function(err) { | |
console.error('Could not connect to platform', err); | |
} | |
); | |
}); | |
</script> | |
</head> | |
<body> | |
<div ng-controller="completeControl"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment