當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。