'use strict';

var mlink = require('../midware');
var Router = mlink.Router;
var config = require('../../lib/config');
var debuggerRouter = Router.get('debugger');

debuggerRouter.registerHandler(function (message) {
  if (message.payload.method === 'AtomDebug.applyChannelId') {
    var channelId = debuggerRouter.newChannel();
    message.payload = {
      method: 'AtomDebug.pushChannelId',
      params: {
        channelId: channelId,
        connectUrl: config.getConnectUrl(channelId)
      }
    };
    message.reply();
  }
}).at('page.entry');