Murat Girgin

By day a simple engineer. By night, also an engineer.


Project maintained by muratg Hosted on GitHub Pages — Theme by mattgraham

Introducing SignalR.TypeScript

Hello, fellow programmers.

If you, like me, love both SignalR and TypeScript, you might find this interesting and/or useful.

What is this?

SignalR.TypeScript helps you generate TypeScript type definitions for your SignalR hubs. It also generates type definitions for the items you pass between client and server.

Some benefits of using TypeScript include:

If you prefer to use TypeScript instead of raw JavaScript on your client code, this tool can be really handy and would save you from hand-rolling your .d.ts files or using “any” everywhere. Please note that this is still in “alpha” so there might be rough edges.

How do I use this with Visual Studio 2012 or 2013?

Supported .NET types

Known issues/current limitations

An example types.d.ts output

This file was generated for the JabbR project.

/* Sample code -- create a .ts file, and paste the following to get started
	/// <reference path="types.d.ts" />
	/// <reference path="signalr.d.ts" />
	// Proxies 
	var monitor: IMonitorProxy = (<any>$.connection).monitor;
	var chat: IChatProxy = (<any>$.connection).chat;
	// Client implementations go here... add some functions.
	monitor.client = { 
	};
	chat.client = { 
	};
	$.connection.hub.start().done((a) => {
		// alert('connected.'); 
		// (do something) 
	});
*/

// Client interfaces. These are the return types for the proxies.
// Implement these in your .ts file, but do not manually edit them here. 
interface IMonitorClient { }
interface IChatClient { }

// Data interfaces 
interface ClientMessage {
	Id: string;
	Content: string;
	Room: string;
}
interface UserViewModel {
	Name: string;
	Hash: string;
	Active: boolean;
	Status: string;
	Note: string;
	AfkNote: string;
	IsAfk: boolean;
	Flag: string;
	Country: string;
	LastActivity: string;
	IsAdmin: boolean;
}
interface LobbyRoomViewModel {
	Name: string;
	Count: number;
	Private: boolean;
	Closed: boolean;
	Topic: string;
}
interface MessageViewModel {
	HtmlEncoded: boolean;
	Id: string;
	Content: string;
	HtmlContent: string;
	When: string;
	User: UserViewModel;
	MessageType: number;
	UserRoomPresence: string;
	ImageUrl: string;
	Source: string;
}
interface RoomViewModel {
	Name: string;
	Count: number;
	Private: boolean;
	Topic: string;
	Closed: boolean;
	Welcome: string;
	Users: Array<UserViewModel>;
	Owners: Array<string>;
	RecentMessages: Array<MessageViewModel>;
}
interface ClientNotification {
	Room: string;
	ImageUrl: string;
	Source: string;
	Content: string;
}

// Hub interfaces 
interface IMonitor {
}
interface IChat {
	onConnected(): IPromise<void>;
	join(): IPromise<void>;
	join(reconnecting: boolean): IPromise<void>;
	send(content: string, roomName: string): IPromise<boolean>;
	send(clientMessage: ClientMessage): IPromise<boolean>;
	getUserInfo(): IPromise<UserViewModel>;
	onReconnected(): IPromise<void>;
	onDisconnected(): IPromise<void>;
	getCommands(): IPromise<any>;
	getShortcuts(): IPromise<any>;
	getRooms(): IPromise<Array<LobbyRoomViewModel>>;
	getPreviousMessages(messageId: string): IPromise<Array<MessageViewModel>>;
	loadRooms(roomNames: Array<any>): IPromise<void>;
	getRoomInfo(roomName: string): IPromise<RoomViewModel>;
	postNotification(notification: ClientNotification): IPromise<void>;
	postNotification(notification: ClientNotification, executeContentProviders: boolean): IPromise<void>;
	typing(roomName: string): IPromise<void>;
	updateActivity(): IPromise<void>;
	tabOrderChanged(tabOrdering: Array<any>): IPromise<void>;
}

// Generetated proxies 
interface IMonitorProxy {
		server: IMonitor;
		client: IMonitorClient;
}
interface IChatProxy {
		server: IChat;
		client: IChatClient;
}