• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript socket.io类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: 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


示例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: default

export default (server: Http.Server) => {
    var io = SocketIO.listen(server); 
    io.on('connection', (socket: SocketIO.Socket) => {
        //console.log('connected'); 

        socket.on('join', (roomId: string) => {
            //console.log('join: ', roomId);
            socket.join(roomId);

            //自分のみ
            io.to(socket.id).emit('join', roomId);
        });

        socket.on('send', (comment: NicoNicoDesktop.IComment) => {
            //console.log(comment);
            io.to(comment.roomId).emit('flowing', comment);
        });

        socket.on('leave', (roomId: string) => {
            //console.log('leave: ', roomId);
            socket.leave(roomId);

            //自分のみ
            io.to(socket.id).emit('leave');
        });
    });
};
开发者ID:yasupeke,项目名称:niconico-desktop-server,代码行数:27,代码来源:app-socketio.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: main

function main() {
	let sv = http.createServer((req, res) => {
		res.writeHead(200, {"Content-Type": "text/plain"});
		res.end("It works.");
	});
	sv.listen(8080);
	let si = io.listen(sv);
	si.sockets.on("connection", (socket) => {
		socket.on("message", (data) => {
			si.sockets.emit("message", "Message: <b>" + data.value + "</b>");
		});
	});
}
开发者ID:shobomaru,项目名称:LearningTypeScript,代码行数:13,代码来源:app.ts


示例6: 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


示例7: express

/// <reference path="../typings/main.d.ts" />
import * as express from "express";
const app: express.Application = express();
import {urlencoded, json} from "body-parser";
import * as io from "socket.io";
import {bruteForce} from "./helpers/bruteForce";
import * as expressJWT from "express-jwt";
import {key} from "./helpers/key";

let server = require("http").Server(app);
export let socketIO: SocketIO.Server = io.listen(server);

// importing routes
// complex
import {apiComplex} from "./routes/complex";
import {apiComplexes} from "./routes/complexes";
// entity
import {apiEntity} from "./routes/entity";
import {apiEntities} from "./routes/entities";
// object
import {apiObject} from "./routes/object";
import {apiObjects} from "./routes/objects";
// bim
import {apiBim} from "./routes/bim";

app.use(urlencoded({ extended: true }));
app.use(json());

app.use(function(req, res, next) {
   res.header("Access-Control-Allow-Origin", "http://localhost:*");
   // res.header("Access-Control-Allow-Credentials", true);
开发者ID:vildantursic,项目名称:walter,代码行数:31,代码来源:app.ts


示例8: sio

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


示例9: express

import * as socketIO from 'socket.io';

var app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

app.use(express.static(path.join(__dirname, 'public'), { maxAge: 86400 }));

app.use('/jspm_packages', express.static(path.join(__dirname, '../jspm_packages')));

var router = express.Router();
router.use((req, res, next) => next());

router.route('/test').get((req, res) => res.json({ test: 'ok' }));

router.get('/config.js', (req, res) => res.sendFile(path.join(__dirname, '../config.js')));
router.get('/socket.io-client.js', (req, res) => res.sendFile(path.join(__dirname, '../jspm_packages/npm/[email protected]')));

app.use('/', router);

var server = app.listen(3000, 'localhost', () => {
    console.log('App listening at http://%s:%s', server.address().address, server.address().port);
    console.log(__dirname);
});

var io = socketIO.listen(server);
io.sockets.on('connection', function (socket) {
    console.log("user connected");
    socket.emit('helloWorld', { hello: 'world' });
});
开发者ID:Dev-I-Ant,项目名称:react-app-basic-socket-io,代码行数:30,代码来源:server.ts


示例10: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript socket.io-client类代码示例发布时间:2022-05-25
下一篇:
TypeScript socket.EventBus类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap