protected override void OnSharedObject(RtmpConnection connection, RtmpChannel channel, RtmpHeader header, SharedObjectMessage message) { ISharedObject sharedObject = null; string name = message.Name; IScope scope = connection.Scope; bool isPersistent = message.IsPersistent; if (scope == null) { SharedObjectMessage message2; if (connection.ObjectEncoding == ObjectEncoding.AMF0) { message2 = new SharedObjectMessage(name, 0, isPersistent); } else { message2 = new FlexSharedObjectMessage(name, 0, isPersistent); } message2.AddEvent(new SharedObjectEvent(SharedObjectEventType.CLIENT_STATUS, "SharedObject.NoObjectFound", "error")); connection.GetChannel(3).Write(message2); } else { ISharedObjectService scopeService = ScopeUtils.GetScopeService(scope, typeof(ISharedObjectService)) as ISharedObjectService; if (!scopeService.HasSharedObject(scope, name)) { ISharedObjectSecurityService service2 = ScopeUtils.GetScopeService(scope, typeof(ISharedObjectSecurityService)) as ISharedObjectSecurityService; if (service2 != null) { IEnumerator sharedObjectSecurity = service2.GetSharedObjectSecurity(); while (sharedObjectSecurity.MoveNext()) { ISharedObjectSecurity current = sharedObjectSecurity.Current as ISharedObjectSecurity; if (!current.IsCreationAllowed(scope, name, isPersistent)) { SendSOCreationFailed(connection, name, isPersistent); return; } } } if (!scopeService.CreateSharedObject(scope, name, isPersistent)) { SendSOCreationFailed(connection, name, isPersistent); return; } } sharedObject = scopeService.GetSharedObject(scope, name); if (sharedObject.IsPersistentObject != isPersistent) { log.Debug(string.Format("Shared object '{0}' persistence mismatch", name)); SendSOPersistenceMismatch(connection, name, isPersistent); } else { sharedObject.DispatchEvent(message); } } }
protected override void OnSharedObject(RtmpConnection connection, RtmpChannel channel, RtmpHeader header, SharedObjectMessage message) { ISharedObject so = null; string name = message.Name; IScope scope = connection.Scope; bool persistent = message.IsPersistent; if (scope == null) { // The scope already has been deleted. SendSOCreationFailed(connection, name, persistent); return; } ISharedObjectService sharedObjectService = ScopeUtils.GetScopeService(scope, typeof(ISharedObjectService)) as ISharedObjectService; if (!sharedObjectService.HasSharedObject(scope, name)) { ISharedObjectSecurityService securityService = ScopeUtils.GetScopeService(scope, typeof(ISharedObjectSecurityService)) as ISharedObjectSecurityService; if (securityService != null) { // Check handlers to see if creation is allowed IEnumerator enumerator = securityService.GetSharedObjectSecurity(); while (enumerator.MoveNext()) { ISharedObjectSecurity handler = enumerator.Current as ISharedObjectSecurity; if (!handler.IsCreationAllowed(scope, name, persistent)) { SendSOCreationFailed(connection, name, persistent); return; } } } if (!sharedObjectService.CreateSharedObject(scope, name, persistent)) { SendSOCreationFailed(connection, name, persistent); return; } } so = sharedObjectService.GetSharedObject(scope, name); if (so.IsPersistentObject != persistent) { log.Debug(string.Format("Shared object '{0}' persistence mismatch", name)); SendSOPersistenceMismatch(connection, name, persistent); return; } so.DispatchEvent(message); }
/// <summary> /// Creates a new shared object for given scope. Server-side shared objects /// (also known as Remote SO) are special kind of objects synchronized between clients. /// <para> /// To get an instance of RSO at client-side, use <c>SharedObject.getRemote()</c>. /// </para> /// SharedObjects can be persistent and transient. Persistent RSO are stateful, i.e. store their data between sessions. /// If you need to store some data on server while clients go back and forth use persistent SO, otherwise perfer usage of transient for /// extra performance. /// </summary> /// <param name="scope">Scope that shared object belongs to.</param> /// <param name="name">Name of SharedObject.</param> /// <param name="persistent">Whether SharedObject instance should be persistent or not.</param> /// <returns>true if SO was created, false otherwise.</returns> public bool CreateSharedObject(IScope scope, string name, bool persistent) { ISharedObjectService service = (ISharedObjectService)ScopeUtils.GetScopeService(scope, typeof(ISharedObjectService)); return(service.CreateSharedObject(scope, name, persistent)); }