当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript io.default方法代码示例

本文整理汇总了TypeScript中socket.io.default方法的典型用法代码示例。如果您正苦于以下问题:TypeScript io.default方法的具体用法?TypeScript io.default怎么用?TypeScript io.default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在socket.io的用法示例。


在下文中一共展示了io.default方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: require

/// <reference path="../typings/main.d.ts" />
try { require("source-map-support").install(); } catch (e) { /* empty */ }
import {IncomingMessage, ServerResponse} from "http";
import * as connect from "connect";
import * as serveStatic from "serve-static";
import * as SocketIOStatic from "socket.io";
const socket: SocketIOStatic = require("socket.io");
import {configure, getLogger} from "log4js";
configure({
    appenders: [{ type: "console", layout: { type: "basic" } }],
    "levels": { default: "INFO" }
});
let logger = getLogger();
import direct from "./scene/director";


let httpPort = process.argv[2] || "3000";
let wsPort = process.argv[3] || "3001";
let app = connect();
app.use("/wsport", (req: IncomingMessage, res: ServerResponse) => {
    res.end(wsPort);
});
app.use(serveStatic("./lib/public/"));
app.listen(httpPort);
let io = socket(wsPort);
direct(io).catch(e => console.error(e.stack));
logger.info(`Server started: ${httpPort} ${wsPort}`);
开发者ID:progre,项目名称:sutahigashi,代码行数:27,代码来源:index.ts

示例2: createMessageHandler

export function createMessageHandler(httpServer: http.Server) {
  d('init');
  const io = ioServer(httpServer);

  io.on('connection', socket => {
    d('connection');
    // Forward commands between connected clients. Parties involved can be the
    // - The Cosmos UI, which acts as a remote control
    // - The web iframe or the React Native component renderers
    socket.on(RENDERER_MESSAGE_EVENT_NAME, msg => {
      d('on renderer message %o', msg);
      socket.broadcast.emit(RENDERER_MESSAGE_EVENT_NAME, msg);
    });
  });

  function sendMessage(msg: BuildMessage) {
    d('send server message %o', msg);
    io.emit(SERVER_MESSAGE_EVENT_NAME, msg);
  }

  function cleanUp() {
    const { sockets } = io.sockets;
    Object.keys(sockets).forEach(id => {
      sockets[id].disconnect(true);
    });
  }

  return { sendMessage, cleanUp };
}
开发者ID:skidding,项目名称:cosmos,代码行数:29,代码来源:messageHandler.ts

示例3: function

 var server = app.listen(config.port, function () {
     var port = server.address().port;
     app.io = SocketIO(server);
     app.io.router = new MainIO();
     app.io.router.initModules();
     console.log('App listening at http://%s:%s', host, port);
 });
开发者ID:zaksie,项目名称:gotouch,代码行数:7,代码来源:app.ts

示例4: initializeNodeServer

        initializeNodeServer() {
            this.app = express();
            this.http = http.Server(this.app);
            this.io_http = socketio(this.http);

            this.connMgr = new ConnectionManager(this.io_http);

            this.registerView();
            this.registerSocketIO();
        }
开发者ID:if1live,项目名称:kisaragi,代码行数:10,代码来源:server_main.ts

示例5: function

module.exports.create = function (bs, server, options) {

    const socketConfig = options
        .getIn(['socket', 'socketIoOptions'])
        .toJS();

    const socketServer = getSocketServer(options, server);
    const io           = socket(socketServer, socketConfig);
    const clients      = io.of(options.getIn(['socket', 'namespace']));

    return {
        socketServer,
        io: io,
        clients: clients,
        protocol: {
            send: function (path, arg) {
                const data = proto.validate(path, arg);
                if (data.errors.length) {
                    return data.errors.forEach(function (error) {
                        console.log(`Error type: ${error.errorType}, property: ${error.name}`);
                    });
                }
                clients.emit(data.payload.path, data.payload.args);
            },
            sendOptionToClient: function (client, id, options) {
                const data = proto.validate('Options.set', id, options.toJS());
                if (data.errors.length) {
                    return data.errors.forEach(function (error) {
                        console.log(`Error type: ${error.errorType}, property: ${error.name}`);
                    });
                }
                client.emit(data.payload.path, data.payload.args);
            }
        }
    };
};
开发者ID:b-cuts,项目名称:browser-sync-core,代码行数:36,代码来源:sockets.ts

示例6: require

#!/usr/bin/env node
import io from 'socket.io';

const log = require('npmlog');
log.debug = log.verbose;

const DEFAULT_PORT = 3380;

const opts = {
  port: parseInt(process.argv[2]) || DEFAULT_PORT,
};

const server = io(opts.port.toString());
server.on('connection', (socket) => {
  socket.on('msg', (data) => {
    server.emit('msg', data);
  });
});

console.log('Message broker server listening on port ' + opts.port);
开发者ID:bitpay,项目名称:bitcore,代码行数:20,代码来源:messagebroker.ts

示例7: require

/// <reference path="./typings/index.d.ts" />
'use strict';
require('app-module-path').addPath(__dirname);
var Chat = require('services/chatService.js');
var conversationController = require('api/conversation/conversationController.js');
var cors = require('middleware/cors.js');
var express = require('express');
var http = require('http');
var path = require('path');
var socketio = require('socket.io');

const PORT = process.env.PORT || 9000;
var app = express();
var server = http.Server(app);
var io = socketio(server);

// Middleware
app.use(cors);
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, '.'));

// Routers
app.use('/conversation', conversationController);

// Chat Service
var chat = new Chat(io);
chat.init();

/**
 * Returns status codes for each subsystem
 * TODO (dharness): statuses aside from api are
开发者ID:sirbabelot,项目名称:babelot-server,代码行数:31,代码来源:server.ts

示例8: percentage

import { Storages } from './Storages/Storages';
import { Torrent } from './Torrent/Torrent';
import { Filter } from './Filter/Filter';
import * as express from 'express';
import * as url from 'url';
//endregion
//region Constants
const PORT = Number(process.env.PORT || 3000);
const FILES_PATH = path.join(__dirname, '../files');
const SPEED_TICK_TIME = 750;    //ms
//endregion
//region Init
var capture = false;
var app = express();
var server = http.createServer(app);
var io = socketIO(server);
var visitedPages = {};
var torrents = {};
var torrentObjs = {};
const filter = new Filter();
//endregion
//region Utilities
function percentage(n): any {
    var p = (Math.round(n * 1000) / 10);
    return (p > 100) ? 100 : p;
}
//endregion
//region session handlers
function saveToDriveHandler(session, data) {
    var obj = data.data;
    var sessionID = session.id;
开发者ID:jazz19972,项目名称:n00b,代码行数:31,代码来源:server.ts

示例9: sockio

        profile.firstTagCounter = 0;
        await r.table('users').update(profile).run(conn);
    } else {
        // Profile has probably been updated, so return the new version
        profile = await r.table('users').get(profile.global_client_id).run(conn);
    }
    this.body = profile;
});

app.use(routerAuthenticated.routes());

/**
 * Initialize server
 */
var server = http.createServer(app.callback());
var io = sockio(server);

(async function () {
    var conn = await r.connect(AppConfig.dbConfig);

    try {
        // Ensure database exists
        await r.dbList()
            .contains(AppConfig.dbConfig.db)
            .do(function (databaseExists) {
                return r.branch(databaseExists, { created: 0 }, r.dbCreate(AppConfig.dbConfig.db));
            })
            .run(conn);
        // Ensure locations table exists
        await r.tableList().contains('locations').do(
            function (tableExists) {
开发者ID:hhoechtl,项目名称:bar-sounds-hackathon,代码行数:31,代码来源:app.ts

示例10: initSockets

import sio from "socket.io";
import {getSession} from "./session";
import {User} from "./data/User"

export const SocketServer: SocketIO.Server = sio({transports: ["websocket"]});
export const SessionSocketMap = {};
const MainRoom: string = "Lobby";

// TODO middleware or some other solution to handle connection setup for authed users vs non-auth user
export function initSockets() {
  SocketServer.on("connection", async (socket: SocketIO.Socket) => {
    const session = getSession(socket.handshake)
    SessionSocketMap[session.id] = socket

    // Join user to Socket.io rooms for their own games
    // TODO: Fail if not logged in?
    const userId = session.passport.user
    const gameIds = await User.getMyGames(userId)
    gameIds.forEach(gameId => socket.join(`game:${gameId}`))
    socket.join(`user:${userId}`)
    socket.join(MainRoom)
  });
}

export function notifyGame(gameId: string, message: string, data: any) {
  console.log(`Sending message to game: ${gameId} ${message} ${JSON.stringify(data, null, 2)}`)
  SocketServer.to(`game:${gameId}`).emit(message, data)
}

export function notifyLobby(message: string, data: any) {
  console.log("Sending message to lobby")
开发者ID:Majavapaja,项目名称:Mursushakki,代码行数:31,代码来源:Sockets.ts


注:本文中的socket.io.default方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。