Commit 380a3846 authored by Alex's avatar Alex
Browse files

and Gcm message send example

parent c16179c1
......@@ -37,6 +37,10 @@
<HintPath>..\..\packages\MatriX.2.0.0.20\lib\net45\Matrix.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
......
using System;
using Matrix.Xmpp.Client;
using Matrix.Xmpp.Google.Mobile;
using Newtonsoft.Json.Linq;
namespace FirebaseClient
{
class Program
{
static string senderId = "YOUR_FIREBASE_SENDER_ID";
static string serverKey = "YOUR_FIREBASE_SERVER_KEY";
static string senderId = "YOUR_FIREBASE_SENDER_ID";
static string serverKey = "YOUR_FIREBASE_SERVER_KEY";
static string testDeviceId = "YOUR_TEST_DEVICE_ID";
static XmppClient xmppClient = new XmppClient();
......@@ -16,7 +19,7 @@ namespace FirebaseClient
Matrix.License.LicenseManager.SetLicense(lic);
}
static void Main(string[] args)
{
// set your MatriX license first
......@@ -38,7 +41,8 @@ namespace FirebaseClient
xmppClient.OnReceiveXml += XmppClient_OnReceiveXml;
xmppClient.OnSendXml += XmppClient_OnSendXml;
xmppClient.OnMessage += XmppClient_OnMessage;
xmppClient.OnLogin += XmppClient_OnLogin;
xmppClient.Open();
Console.WriteLine("Press return key to exit the application");
......@@ -47,6 +51,36 @@ namespace FirebaseClient
xmppClient.Close();
}
private static void XmppClient_OnLogin(object sender, Matrix.EventArgs e)
{
// we send a Gcm message here after we are authenticated
/*
* sample message from Google docs
{
'notification':{'title':'Portugal vs. Denmark','body':'5 to 1'},
'message_id':'some-id',
'to':'some-device'
}
*/
var jsonMessgae = JObject.FromObject(new
{
notification = new
{
title = "Portugal vs. Denmark",
body = "5 to 1"
},
message_id = Guid.NewGuid().ToString(),
to = testDeviceId
});
var msg = new Message { Id = Guid.NewGuid().ToString() };
msg.Add(new Gcm { Value = jsonMessgae.ToString() });
xmppClient.Send(msg);
}
private static void XmppClient_OnMessage(object sender, MessageEventArgs e)
{
// received a GCM message
......
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MatriX" version="2.0.0.20" targetFramework="net46" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net46" />
</packages>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment