Skip to content

Instantly share code, notes, and snippets.

@gleitz
Created September 13, 2015 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gleitz/57176f953d165e6c4fd3 to your computer and use it in GitHub Desktop.
Save gleitz/57176f953d165e6c4fd3 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using Meteor;
using Extensions;
public class MeteorUpdate : MonoBehaviour {
public string meteorURL = "wss://calder.meteor.com/websocket";
void Start () {
Debug.Log ("starting!");
Meteor.Connection.Logging = true;
Security.PrefetchSocketPolicy("calder.meteor.com", 443);
StartCoroutine(MeteorExample());
}
void Update () {
}
IEnumerator MeteorExample() {
Debug.Log ("connecting!");
yield return Meteor.Connection.Connect (meteorURL);
Debug.Log (Meteor.Connection.Connected.ToString());
// Login
yield return Meteor.Accounts.LoginAsGuest ();
Debug.Log ("logged in!");
var collection = Collection<MeteorMap>.Create ("spheres");
var subscription = Meteor.Subscription.Subscribe("spheres");
collection.DidAddRecord += (arg1, doc) => {
Debug.Log ("id: " + doc._id);
Debug.Log (doc.sphereUrl);
};
collection.DidChangeRecord += (arg1, doc, arg3, arg4) => {
Debug.Log ("id: " + doc._id);
Debug.Log (doc.sphereUrl);
};
yield return (Coroutine)subscription;
}
}
public class MeteorMap : Meteor.MongoDocument {
public string sphereUrl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment