private void SendUpdates() { if (this._ownerMessage.Events.Count != 0) { if (this._connection.NetConnectionClient.Connection != null) { SharedObjectMessage message; RtmpConnection connection = this._connection.NetConnectionClient.Connection as RtmpConnection; RtmpChannel channel = connection.GetChannel(3); if (connection.ObjectEncoding == FluorineFx.ObjectEncoding.AMF0) { message = new SharedObjectMessage(null, this._name, this._version, this.IsPersistentObject); } else { message = new FlexSharedObjectMessage(null, this._name, this._version, this.IsPersistentObject); } message.AddEvents(this._ownerMessage.Events); if (channel != null) { channel.Write(message); } else { log.Warn(__Res.GetString("Channel_NotFound")); } } this._ownerMessage.Events.Clear(); } }
public void Connect(NetConnection connection, string parameters) { SharedObjectMessage message; if (this._initialSyncReceived) { throw new InvalidOperationException("SharedObject already connected"); } ValidationUtils.ArgumentNotNull(connection, "connection"); ValidationUtils.ArgumentNotNull(connection.Uri, "connection"); ValidationUtils.ArgumentConditionTrue(connection.Uri.Scheme == "rtmp", "connection", "NetConnection object must use the Real-Time Messaging Protocol (RTMP)"); ValidationUtils.ArgumentConditionTrue(connection.Connected, "connection", "NetConnection object must be connected"); this._connection = connection; this._initialSyncReceived = false; if (connection.ObjectEncoding == FluorineFx.ObjectEncoding.AMF0) { message = new SharedObjectMessage(this._name, this._version, this._persistentSO); } else { message = new FlexSharedObjectMessage(this._name, this._version, this._persistentSO); } SharedObjectEvent sharedObjectEvent = new SharedObjectEvent(SharedObjectEventType.SERVER_CONNECT, null, null); message.AddEvent(sharedObjectEvent); this._connection.NetConnectionClient.Write(message); }
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); } } }
private static ISharedObjectMessage DecodeFlexSharedObject(ByteBuffer stream) { stream.Skip(1); RtmpReader reader = new RtmpReader(stream); string name = reader.ReadString(); int version = reader.ReadInt32(); bool persistent = reader.ReadInt32() == 2; reader.ReadInt32(); SharedObjectMessage so = new FlexSharedObjectMessage(null, name, version, persistent); DecodeSharedObject(so, stream, reader); return(so); }
private static void SendSOPersistenceMismatch(RtmpConnection connection, string name, bool persistent) { SharedObjectMessage msg; if (connection.ObjectEncoding == ObjectEncoding.AMF0) { msg = new SharedObjectMessage(name, 0, persistent); } else { msg = new FlexSharedObjectMessage(name, 0, persistent); } msg.AddEvent(new SharedObjectEvent(SharedObjectEventType.CLIENT_STATUS, StatusASO.SO_PERSISTENCE_MISMATCH, "error")); connection.GetChannel((byte)3).Write(msg); }
private static void SendSOCreationFailed(RtmpConnection connection, string name, bool persistent) { SharedObjectMessage msg; if (connection.ObjectEncoding == ObjectEncoding.AMF0) { msg = new SharedObjectMessage(name, 0, persistent); } else { msg = new FlexSharedObjectMessage(name, 0, persistent); } msg.AddEvent(new SharedObjectEvent(SharedObjectEventType.CLIENT_STATUS, StatusASO.SO_CREATION_FAILED, "error")); connection.GetChannel((byte)3).Write(msg); }
private static void SendSOPersistenceMismatch(RtmpConnection connection, string name, bool persistent) { SharedObjectMessage message; if (connection.ObjectEncoding == ObjectEncoding.AMF0) { message = new SharedObjectMessage(name, 0, persistent); } else { message = new FlexSharedObjectMessage(name, 0, persistent); } message.AddEvent(new SharedObjectEvent(SharedObjectEventType.CLIENT_STATUS, "SharedObject.BadPersistence", "error")); connection.GetChannel(3).Write(message); }
static ISharedObjectMessage DecodeFlexSharedObject(ByteBuffer stream) { // Unknown byte, always 0? stream.Skip(1); RtmpReader reader = new RtmpReader(stream); string name = reader.ReadString(); // Read version of SO to modify int version = reader.ReadInt32(); // Read persistence informations bool persistent = reader.ReadInt32() == 2; // Skip unknown bytes reader.ReadInt32(); SharedObjectMessage so = new FlexSharedObjectMessage(null, name, version, persistent); DecodeSharedObject(so, stream, reader); return(so); }
public void Close() { if ((this._initialSyncReceived && (this._connection != null)) && this._connection.Connected) { SharedObjectMessage message; if (this._connection.ObjectEncoding == FluorineFx.ObjectEncoding.AMF0) { message = new SharedObjectMessage(this._name, this._version, this._persistentSO); } else { message = new FlexSharedObjectMessage(this._name, this._version, this._persistentSO); } SharedObjectEvent sharedObjectEvent = new SharedObjectEvent(SharedObjectEventType.SERVER_DISCONNECT, null, null); message.AddEvent(sharedObjectEvent); this._connection.NetConnectionClient.Write(message); base.RemoveAttributes(); this._ownerMessage.Events.Clear(); } this._initialSyncReceived = false; }
/// <summary> /// Send update notification over data channel of RTMP connection /// </summary> private void SendUpdates() { if (_ownerMessage.Events.Count != 0) { if (_connection.NetConnectionClient.Connection != null) { RtmpConnection connection = _connection.NetConnectionClient.Connection as RtmpConnection; // Only send updates when issued through RTMP request RtmpChannel channel = connection.GetChannel((byte)3); // Send update to "owner" of this update request SharedObjectMessage syncOwner; if (connection.ObjectEncoding == ObjectEncoding.AMF0) { syncOwner = new SharedObjectMessage(null, _name, _version, this.IsPersistentObject); } else { syncOwner = new FlexSharedObjectMessage(null, _name, _version, this.IsPersistentObject); } syncOwner.AddEvents(_ownerMessage.Events); if (channel != null) { channel.Write(syncOwner); } else { #if !SILVERLIGHT log.Warn(__Res.GetString(__Res.Channel_NotFound)); #endif } } _ownerMessage.Events.Clear(); } }