Skip to content

Commit

Permalink
Bump versions
Browse files Browse the repository at this point in the history
  • Loading branch information
doctorpangloss committed Mar 14, 2019
1 parent 87310e3 commit 6120923
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Examples.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 84 additions & 0 deletions Examples/AccountsExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System.Collections;
using UnityEngine;

namespace Meteor.Examples
{
/// <summary>
/// A simple example demonstrating the accounts package and basic subscription and method calling.
///
/// To use this with a meteor server, add the following content to a javascript file in the server/ directory:
/// <code>
/// let collection = new Mongo.Collection('collectionName', {connection: null});
/// Meteor.publish('subscriptionEndpointName', function (number1, number2, number3) {
/// console.log(`Subscribed: ${number1}, ${number2}, ${number3}`);
/// return collection.find({});
/// });
///
/// Meteor.methods({
/// 'getStringMethod': function (number1, number2, number3) {
/// console.log(`Called method: ${number1}, ${number2}, ${number3}`);
/// return "test";
/// }
/// });
///
/// Meteor.setInterval(function () {
/// collection.insert({
/// stringField: 'test',
/// intField: 1
/// })
/// }, 1000);
///
/// Accounts.onCreateUser(function (user) {
/// console.log(`User created: ${user._id}`);
/// return user;
/// });
/// </code>
/// </summary>
public class AccountsExample : MonoBehaviour
{
IEnumerator Start()
{
yield return StartCoroutine(MeteorExample());
}

IEnumerator MeteorExample()
{
var production = false;

// Connect to the meteor server. Yields when you're connected
yield return Meteor.Connection.Connect("ws://localhost:3000/websocket");

// Login
yield return (Coroutine) Meteor.Accounts.LoginAsGuest();

// Create a collection
var collection = new Meteor.Collection<DocumentType>("collectionName");

// Add some handlers with the new observer syntax
var observer = collection.Find().Observe(added: (string id, DocumentType document) =>
{
Debug.Log($"Document added: [_id={document._id}]");
});

// Subscribe
var subscription = Meteor.Subscription.Subscribe("subscriptionEndpointName", /*arguments*/ 1, 3, 4);
// The convention to turn something into a connection is to cast it to a Coroutine
yield return (Coroutine) subscription;

// Create a method call that returns a string
var methodCall = Meteor.Method<string>.Call("getStringMethod", /*arguments*/1, 3, 4);

// Execute the method. This will yield until all the database side effects have synced.
yield return (Coroutine) methodCall;

// Get the value returned by the method.
Debug.Log($"Method response:\n{methodCall.Response}");
}

public class DocumentType : Meteor.MongoDocument
{
public string stringField;
public int intField;
}
}
}
3 changes: 3 additions & 0 deletions Examples/AccountsExample.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 32 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
Meteor-Unity
============

**Download Version 3.1:** http://hiddenswitch.github.io/Meteor-Unity/Meteor-Unity_v3.1.unitypackage.
**Download Version 3.2:** http://hiddenswitch.github.io/Meteor-Unity/Meteor-Unity_v3.2.unitypackage.

A Unity SDK for Meteor. Tested with Unity3D 5.3.2p2, Meteor's Galaxy hosting and Modulus hosting on iOS 9.2 and 9.3 64bit platforms. See the [Documentation](http://hiddenswitch.github.io/Meteor-Unity/annotated.html).
A Unity SDK for Meteor. Tested with Unity3D 2018.3.2f1 on il2cpp platforms. See the [Documentation](http://hiddenswitch.github.io/Meteor-Unity/annotated.html).

This release supports `il2cpp` backends, allowing it to be used in production for iOS builds. iOS, Android and desktop platforms are supported. WebGL is not supported.

See the example code at the bottom of the Readme for an overview of all the supported features. Wherever possible, the API matches the Meteor API, and the details match Meteor details. There is an exception to how things usually work in Meteor:

- In Meteor, disconnecting and reconnecting triggers a removal of all records and adding of all new records, as though a subscription was torn down and recreated. In Meteor-Unity, disconnecting does not result in removing records, while reconnecting will result in add messages / added called in observe handles.

Compared to Meteor, Meteor-Unity has some limitations. It cannot simulate code yet, so database side effects must come from the server. It cannot handle documents that aren't explicitly typed.
Compared to Meteor, Meteor-Unity has some limitations. It cannot simulate code yet, so database side effects must come from the server. It also cannot handle documents that are not explicitly typed.

##### Tips

Expand Down Expand Up @@ -93,3 +91,32 @@ Compared to Meteor, Meteor-Unity has some limitations. It cannot simulate code y
public int intField;
}
```
To use the above example, include the following file in the `server/` directory in your Meteor project:
```js
let collection = new Mongo.Collection('collectionName', {connection: null});
Meteor.publish('subscriptionEndpointName', function (number1, number2, number3) {
console.log(`Subscribed: ${number1}, ${number2}, ${number3}`);
return collection.find({});
});
Meteor.methods({
'getStringMethod': function (number1, number2, number3) {
console.log(`Called method: ${number1}, ${number2}, ${number3}`);
return "test";
}
});
Meteor.setInterval(function () {
collection.insert({
stringField: 'test',
intField: 1
})
}, 1000);
Accounts.onCreateUser(function (user) {
console.log(`User created: ${user._id}`);
return user;
});
```

0 comments on commit 6120923

Please sign in to comment.