Skip to content

Commit b2e5022

Browse files
committed
Merge pull request #62 from mattleibow/xamarin-component
Xamarin Component
2 parents 9cf17c7 + 2153486 commit b2e5022

50 files changed

Lines changed: 2169 additions & 41 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

DETAILS.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Socket.IO .NET
2+
3+
Socket.IO enables real-time bidirectional event-based communication.
4+
It works on every platform, browser or device, focusing equally on reliability and speed.
5+
6+
* **Real-time analytics**
7+
Push data to clients that gets represented as real-time counters, charts or logs.
8+
* **Instant messaging and chat**
9+
Socket.IO's "Hello world" is a chat app in just a few lines of code.
10+
* **Binary streaming**
11+
Starting in 1.0, it's possible to send any blob back and forth: image, audio, video.
12+
* **Document collaboration**
13+
Allow users to concurrently edit a document and see each other's changes.
14+
15+
> **USED BY EVERYONE**
16+
> From Microsoft Office, Yammer, Zendesk, Trello... to hackathon winners and little startups.
17+
18+
> **IMMENSELY POWERFUL, YET EASY TO USE**
19+
> Our getting started guide will show you how to create lots of amazing applications in fewer
20+
> than 200 lines of code.
21+
22+
## Connect to Server
23+
24+
Connecting to a Socket.IO server is just two lines:
25+
26+
// connect to a Socket.IO server
27+
socket = IO.Socket("http://chat.socket.io/");
28+
socket.Connect();
29+
30+
// disconnect from the server
31+
socket.Close();
32+
33+
## Subscribe to Events
34+
35+
Listening for messages from the server is easy,all we need to do is
36+
attach a delegate to the event name using the `On` method.
37+
38+
The `data` received from the http://chat.socket.io/ server is a `JToken` value:
39+
40+
// whenever the server emits "login", print the login message
41+
socket.On("login", data => {
42+
connected = true;
43+
44+
// get the json data from the server message
45+
var jobject = data as JToken;
46+
47+
// get the number of users
48+
var numUsers = jobject.Value<int>("numUsers");
49+
50+
// display the welcome message...
51+
});
52+
53+
// whenever the server emits "new message", update the chat body
54+
socket.On("new message", data => {
55+
// get the json data from the server message
56+
var jobject = data as JToken;
57+
58+
// get the message data values
59+
var username = jobject.Value<string>("username");
60+
var message = jobject.Value<string>("message");
61+
62+
// display message...
63+
});
64+
65+
## Send a Message
66+
67+
Sending a message to the server is just a single line of code that makes use of the
68+
`Emit` method:
69+
70+
// we can send messages to the server
71+
socket.Emit("add user", "username");
72+
if (connected) {
73+
socket.Emit("new message", "This is a message from Xamarin.Android...");
74+
}
75+
76+
// or we can just send events
77+
socket.Emit("typing");
78+
// cancel that typing event
79+
socket.Emit("stop typing");

LICENSE.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Quobject
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Any raw assets you want to be deployed with your application can be placed in
2+
this directory (and child directories) and given a Build Action of "AndroidAsset".
3+
4+
These files will be deployed with you package and will be accessible using Android's
5+
AssetManager, like this:
6+
7+
public class ReadAsset : Activity
8+
{
9+
protected override void OnCreate (Bundle bundle)
10+
{
11+
base.OnCreate (bundle);
12+
13+
InputStream input = Assets.Open ("my_asset.txt");
14+
}
15+
}
16+
17+
Additionally, some Android functions will automatically load asset files:
18+
19+
Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System.Collections.Generic;
2+
using Android.Graphics;
3+
using Android.Views;
4+
using Android.Widget;
5+
6+
namespace SocketIoClientDotNet.Sample.Xamarin_Android
7+
{
8+
public class ChatAdapter : BaseAdapter<ChatAdapter.ChatItem>
9+
{
10+
private readonly List<ChatAdapter.ChatItem> chatItems;
11+
12+
public ChatAdapter(List<ChatAdapter.ChatItem> chatItems)
13+
{
14+
this.chatItems = chatItems;
15+
}
16+
17+
public override ChatAdapter.ChatItem this[int position]
18+
{
19+
get { return chatItems[position]; }
20+
}
21+
22+
public override int Count
23+
{
24+
get { return chatItems.Count; }
25+
}
26+
27+
public override long GetItemId(int position)
28+
{
29+
return position;
30+
}
31+
32+
public override View GetView(int position, View convertView, ViewGroup parent)
33+
{
34+
var item = chatItems[position];
35+
var layout = item.Username == null
36+
? Android.Resource.Layout.SimpleListItem1
37+
: Android.Resource.Layout.SimpleListItem2;
38+
39+
var inflater = LayoutInflater.From(parent.Context);
40+
41+
if (convertView == null || (int)convertView.Tag != layout)
42+
{
43+
convertView = inflater.Inflate(layout, parent, false);
44+
convertView.Tag = layout;
45+
}
46+
47+
if (item.Username == null)
48+
{
49+
var text1 = convertView.FindViewById<TextView>(Android.Resource.Id.Text1);
50+
51+
text1.Text = item.Message;
52+
}
53+
else
54+
{
55+
var text1 = convertView.FindViewById<TextView>(Android.Resource.Id.Text1);
56+
var text2 = convertView.FindViewById<TextView>(Android.Resource.Id.Text2);
57+
58+
text1.Typeface = Typeface.DefaultBold;
59+
text1.Text = item.Username;
60+
text2.Text = item.Message;
61+
}
62+
63+
return convertView;
64+
}
65+
66+
public struct ChatItem
67+
{
68+
public ChatItem(string username, string message)
69+
: this()
70+
{
71+
Username = username;
72+
Message = message;
73+
}
74+
75+
public string Username { get; set; }
76+
public string Message { get; set; }
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)