mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Added the test files for the legacy socket.io code
This commit is contained in:
parent
812ed1d1a8
commit
9c47c6a65a
57
socket.io-client/legacy/socket.io-client-1.2.0-tests.ts
Normal file
57
socket.io-client/legacy/socket.io-client-1.2.0-tests.ts
Normal file
@ -0,0 +1,57 @@
|
||||
/// <reference path="socket.io-client.d.ts"/>
|
||||
|
||||
function testUsingWithNodeHTTPServer() {
|
||||
var socket = io('http://localhost');
|
||||
socket.on('news', function (data: any) {
|
||||
console.log(data);
|
||||
socket.emit('my other event', { my: 'data' });
|
||||
});
|
||||
}
|
||||
|
||||
function testUsingWithExpress() {
|
||||
var socket = io.connect('http://localhost');
|
||||
socket.on('news', function (data: any) {
|
||||
console.log(data);
|
||||
socket.emit('my other event', { my: 'data' });
|
||||
});
|
||||
}
|
||||
|
||||
function testUsingWithTheExpressFramework() {
|
||||
var socket = io.connect('http://localhost');
|
||||
socket.on('news', function (data: any) {
|
||||
console.log(data);
|
||||
socket.emit('my other event', { my: 'data' });
|
||||
});
|
||||
}
|
||||
|
||||
function testRestrictingYourselfToANamespace() {
|
||||
var chat = io.connect('http://localhost/chat')
|
||||
, news = io.connect('http://localhost/news');
|
||||
|
||||
chat.on('connect', function () {
|
||||
chat.emit('hi!');
|
||||
});
|
||||
|
||||
news.on('news', function () {
|
||||
news.emit('woot');
|
||||
});
|
||||
}
|
||||
|
||||
function testSendingAndGettingData() {
|
||||
var socket = io();
|
||||
socket.on('connect', function () {
|
||||
socket.emit('ferret', 'tobi', function (data: any) {
|
||||
console.log(data);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function testUsingItJustAsACrossBrowserWebSocket() {
|
||||
var socket = io('http://localhost/');
|
||||
socket.on('connect', function () {
|
||||
socket.emit('hi');
|
||||
|
||||
socket.on('message', function (msg: any) {
|
||||
});
|
||||
});
|
||||
}
|
||||
145
socket.io/legacy/socket.io-1.2.0-tests.ts
Normal file
145
socket.io/legacy/socket.io-1.2.0-tests.ts
Normal file
@ -0,0 +1,145 @@
|
||||
import socketIO = require('socket.io');
|
||||
|
||||
function testUsingWithNodeHTTPServer() {
|
||||
var app = require('http').createServer(handler);
|
||||
var io = socketIO(app);
|
||||
var fs = require('fs');
|
||||
|
||||
app.listen(80);
|
||||
|
||||
function handler(req: any, res: any) {
|
||||
fs.readFile(__dirname + '/index.html',
|
||||
function (err: any, data: any) {
|
||||
if (err) {
|
||||
res.writeHead(500);
|
||||
return res.end('Error loading index.html');
|
||||
}
|
||||
|
||||
res.writeHead(200);
|
||||
res.end(data);
|
||||
});
|
||||
}
|
||||
|
||||
io.on('connection', function (socket) {
|
||||
socket.emit('news', { hello: 'world' });
|
||||
socket.on('my other event', function (data: any) {
|
||||
console.log(data);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function testUsingWithExpress() {
|
||||
var app = require('express')();
|
||||
var server = require('http').Server(app);
|
||||
var io = socketIO(server);
|
||||
|
||||
server.listen(80);
|
||||
|
||||
app.get('/', function (req: any, res: any) {
|
||||
res.sendfile(__dirname + '/index.html');
|
||||
});
|
||||
|
||||
io.on('connection', function (socket) {
|
||||
socket.emit('news', { hello: 'world' });
|
||||
socket.on('my other event', function (data: any) {
|
||||
console.log(data);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function testUsingWithTheExpressFramework() {
|
||||
var app = require('express').createServer();
|
||||
var io = socketIO(app);
|
||||
|
||||
app.listen(80);
|
||||
|
||||
app.get('/', function (req: any, res: any) {
|
||||
res.sendfile(__dirname + '/index.html');
|
||||
});
|
||||
|
||||
io.on('connection', function (socket) {
|
||||
socket.emit('news', { hello: 'world' });
|
||||
socket.on('my other event', function (data: any) {
|
||||
console.log(data);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function testSendingAndReceivingEvents() {
|
||||
var io = socketIO(80);
|
||||
|
||||
io.on('connection', function (socket) {
|
||||
io.emit('this', { will: 'be received by everyone' });
|
||||
|
||||
socket.on('private message', function (from: any, msg: any) {
|
||||
console.log('I received a private message by ', from, ' saying ', msg);
|
||||
});
|
||||
|
||||
socket.on('disconnect', function () {
|
||||
io.sockets.emit('user disconnected');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function testRestrictingYourselfToANamespace() {
|
||||
var io = socketIO.listen(80);
|
||||
var chat = io
|
||||
.of('/chat')
|
||||
.on('connection', function (socket) {
|
||||
socket.emit('a message', {
|
||||
that: 'only'
|
||||
, '/chat': 'will get'
|
||||
});
|
||||
chat.emit('a message', {
|
||||
everyone: 'in'
|
||||
, '/chat': 'will get'
|
||||
});
|
||||
});
|
||||
|
||||
var news = io
|
||||
.of('/news')
|
||||
.on('connection', function (socket) {
|
||||
socket.emit('item', { news: 'item' });
|
||||
});
|
||||
}
|
||||
|
||||
function testSendingVolatileMessages() {
|
||||
var io = socketIO.listen(80);
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
var tweets = setInterval(function () {
|
||||
socket.volatile.emit('bieber tweet', {});
|
||||
}, 100);
|
||||
|
||||
socket.on('disconnect', function () {
|
||||
clearInterval(tweets);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function testSendingAndGettingData() {
|
||||
var io = socketIO.listen(80);
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
socket.on('ferret', function (name: any, fn: any) {
|
||||
fn('woot');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function testBroadcastingMessages() {
|
||||
var io = socketIO.listen(80);
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
socket.broadcast.emit('user connected');
|
||||
});
|
||||
}
|
||||
|
||||
function testUsingItJustAsACrossBrowserWebSocket() {
|
||||
var io = socketIO.listen(80);
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
socket.on('message', function () { });
|
||||
socket.on('disconnect', function () { });
|
||||
});
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user