Permalink
Browse files

cli: create rooms on client-side

  • Loading branch information...
1 parent 748c9d7 commit 4891fe19a937226d3f5c9aa614823d1d8c72241e @indutny committed Sep 3, 2012
Showing with 9 additions and 25 deletions.
  1. +0 −14 lib/vock/api.js
  2. +9 −11 lib/vock/cli/main.js
View
14 lib/vock/api.js
@@ -64,20 +64,6 @@ Api.prototype.query = function(data, errback, callback) {
};
//
-// ### function create (callback)
-// #### @callback {Function} callback
-// Send create request to server
-//
-Api.prototype.create = function create(callback) {
- this.query({
- type: 'create',
- port: this.socket.port
- }, callback, function(packet) {
- callback(null, packet.id);
- });
-};
-
-//
// ### function connect (id, callback)
// #### @id {String} room id
// #### @callback {Function} callback
View
20 lib/vock/cli/main.js
@@ -1,5 +1,6 @@
var vock = require('../../vock'),
nconf = require('nconf'),
+ crypto = require('crypto'),
fs = require('fs'),
path = require('path'),
colors = require('colors'),
@@ -284,25 +285,22 @@ Cli.prototype.initKeyboard = function initKeyboard() {
};
Cli.prototype.handleCreate = function handleCreate() {
- var self = this;
-
- this.instance.api.create(function(err, id) {
- if (err) throw err;
+ var id = crypto.createHash('sha1')
+ .update(crypto.randomBytes(20))
+ .digest('hex');
- self.logger.write('Room created!'.green);
- self.logger.write('Run this on other side:');
- self.logger.write(' vock connect ' + id);
- self.logger.write('Waiting for opponent...');
+ this.instance.api.connect(id, this.handleMembers.bind(this));
- self.instance.api.watch(id, self.handleMembers.bind(self));
- });
+ this.logger.write('Room created!'.green);
+ this.logger.write('Run this on other side:');
+ this.logger.write(' vock connect ' + id);
+ this.logger.write('Waiting for opponent...');
};
Cli.prototype.handleConnect = function handleConnect() {
var self = this,
id = this.argv._[1];
-
this.instance.api.connect(id, this.handleMembers.bind(this));
this.logger.write('Connecting...');
};

0 comments on commit 4891fe1

Please sign in to comment.