Skip to content

Commit

Permalink
チャンネル分離に成功
Browse files Browse the repository at this point in the history
  • Loading branch information
KOBA789 committed Nov 5, 2011
1 parent 43e06ed commit 4e8d980
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app.js
Expand Up @@ -31,7 +31,7 @@ io.sockets.on('connection', function (socket) {

var channelName = '';

socket.emit('getChannelName', function (_channelName) {
socket.on('channelName', function (_channelName) {
channelName = _channelName;
socket.join(channelName);
});
Expand Down
47 changes: 33 additions & 14 deletions public/koba789_comment.js
Expand Up @@ -18,10 +18,22 @@ var koba789 = {};

var socket, isLocal = false;

var dev = {
channelName: 'debug-channel',
isLocal: false
};

/**
* Initial Function
*/
function init () {
/**
* Switch debug mode
*/
if (location.hostname !== 'live.nicocast.com') {
dev.isLocal = true;
}

commentList = document.getElementById('koba789-comment-list');
listContainer = document.getElementById('koba789-comment-list-container');
commentInput = document.getElementById('koba789-comment-input');
Expand All @@ -36,16 +48,12 @@ var koba789 = {};

/**
* socket.io settings
*/
if (window.location.href.match(/^file:/)) {
isLocal = true;
setTimeout(onConnect, 0);
} else {
socket = io.connect(destination);
socket.on('connect', onConnect);
socket.on('comment', onCommentReceive);
socket.on('log', onLogReceive);
}
*/
socket = io.connect(destination);
socket.on('connect', onConnect);
socket.on('comment', onCommentReceive);
socket.on('log', onLogReceive);
socket.emit('channelName', getChannelName());
}

/**
Expand All @@ -55,7 +63,6 @@ var koba789 = {};
for (var i = 1; i <= 100; i ++) {
onCommentReceive({text: 'テストメッセージ' + i.toString()});
}
socket.set('channel', 'koba789');
}

/**
Expand Down Expand Up @@ -83,7 +90,18 @@ var koba789 = {};
function onLogReceive (log) {

}


/**
* Get the Channel Name
*/
function getChannelName () {
if (!dev.isLocal) {
return location.pathname.match(/\/channel\/([a-zA-Z0-9_-]+)/)[1];
} else {
return location.search.substring(1);
}
}

/**
* Comment filter
*/
Expand Down Expand Up @@ -126,9 +144,10 @@ var koba789 = {};
function onEnterComment() {
var text = commentInput.value;
commentInput.value = '';

addComment(text, true);

if (!isLocal) socket.emit('post', text);
socket.emit('post', text);
return true;
}

koba789.init = init;
Expand Down

0 comments on commit 4e8d980

Please sign in to comment.