protected virtual void OnNewMessage(WaveMessage msg) { if (DataReceived != null) { DataReceived(this, new DataEventArgs <object>(msg)); } }
public short Add(WaveMessage msg, long sourceViewID, NodeTransition transition, bool isPopup, bool startTimeoutTimer = true) { short result = -1; if (Core.UseRequestIDs) { result = GetNextRequestID(); requests[result] = new RequestData(sourceViewID, transition, isPopup); msg.AddInt16(MessageOutFieldID.RequestID, result); } if (startTimeoutTimer && (result >= 0)) { // safety first - try to remove old timer RemoveTimer(result); // start timeout timer DispatcherTimer timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(NetworkRequestTimeout); timer.Tick += (s, e) => OnTimeout(result); timers[result] = timer; timer.Start(); } return(result); }
public void OnMessageReceived(WaveServerComponent dest, Enum msgID, WaveMessage data) { if (msgID is AggregateMessageMessageID) { if (data != null) { if ((AggregateMessageMessageID)msgID == AggregateMessageMessageID.AggregateMessage) { foreach (IFieldBase field in data.RootList) { if ((field is BinaryField) && (field.FieldID == (short)AggregateMessageFieldID.PackedMessage)) { // we have embedded message - lets unpack and publish that BinaryField tempBinary = (BinaryField)field; if ((tempBinary.Data != null) && (tempBinary.Data.Length > 0)) { Core.RouteServerMessage(new WaveMessage(tempBinary.Data)); } } } } } } }
/// <summary> /// Called when we get a new buffer of recorded data /// </summary> private void Callback(IntPtr waveInHandle, WaveMessage message, IntPtr userData, WaveHeader waveHeader, IntPtr reserved) { if (message == WaveMessage.WaveInData) { if (recording) { var hBuffer = (GCHandle)waveHeader.userData; var buffer = (WaveInBuffer)hBuffer.Target; if (buffer == null) { return; } lastReturnedBufferIndex = Array.IndexOf(buffers, buffer); RaiseDataAvailable(buffer); try { buffer.Reuse(); } catch (Exception e) { recording = false; RaiseRecordingStopped(e); } } } }
protected override void WndProc(ref System.Windows.Forms.Message m) { WaveMessage message = (WaveMessage)m.Msg; switch (message) { case WaveMessage.WaveOutDone: case WaveMessage.WaveInData: IntPtr hOutputDevice = m.WParam; WaveHeader waveHeader = new WaveHeader(); Marshal.PtrToStructure(m.LParam, waveHeader); waveCallback(hOutputDevice, message, IntPtr.Zero, waveHeader, IntPtr.Zero); break; case WaveMessage.WaveOutOpen: case WaveMessage.WaveOutClose: case WaveMessage.WaveInClose: case WaveMessage.WaveInOpen: waveCallback(m.WParam, message, IntPtr.Zero, null, IntPtr.Zero); break; default: base.WndProc(ref m); break; } }
public void AddLocationData(WaveMessage msg) { if ((watcher != null) && (watcher.Status == GeoPositionStatus.Ready) && ((DateTimeOffset.UtcNow - watcher.Position.Timestamp) <= maximumDelay)) { msg.AddInt32(DefAgentFieldID.MapLatitude, (int)(watcher.Position.Location.Latitude * DegreesToMicrodegrees)); msg.AddInt32(DefAgentFieldID.MapLongitude, (int)(watcher.Position.Location.Longitude * DegreesToMicrodegrees)); } }
public bool PostServerMessage(WaveMessage msg) { if ((msg == null) || (transport == null)) { return(false); } transport.SendData(msg.ToEncodedByteArray()); return(true); }
public void OnMessageReceived(WaveServerComponent dest, Enum msgID, WaveMessage data) { if (msgID is CacheAgentMessageID) { if (data != null) { switch ((CacheAgentMessageID)msgID) { case CacheAgentMessageID.RequestCacheHash: { WaveMessage msgOut = new WaveMessage(); msgOut.AddBinary(CacheAgentFieldID.CacheHash, Server.CalculateHash()); // return cache's own CIID (if any) if (cacheID.HasValue) { msgOut.AddBinary(MessageOutFieldID.CacheItemID, cacheID.Value.ToByteArray()); } msgOut.Send(WaveServerComponent.CacheAgent, CacheAgentMessageID.CacheHashCheck); break; } case CacheAgentMessageID.SendWABCacheCIID: { BinaryField bin = (BinaryField)data[MessageOutFieldID.CacheItemID]; if (bin.Data != null) { CacheItemID temp = new CacheItemID(bin.Data); if (!cacheID.HasValue || !cacheID.Value.Equals(temp)) { cacheID = temp; goto case CacheAgentMessageID.ClearCache; } } break; } case CacheAgentMessageID.ClearCache: { Server.Clear(); break; } } } } }
public void OpenMediaStream(string contentID, byte[] streamSessionID = null) { WaveMessage msg = new WaveMessage(); msg.AddBinary(MessageOutFieldID.ContentReferenceID, StringHelper.GetBytes(contentID)); if (streamSessionID != null) { msg.AddBinary(MediaReferenceFieldID.StreamSessionID, streamSessionID); } msg.Send(WaveServerComponent.MediaAgent, MediaAgentMessageID.OpenStream); }
/// <summary> /// Adds message to the transport queue - to be send whenever possible (depends on transport). /// </summary> /// <param name="destination">Server component to send message to.</param> /// <param name="msgID">Message ID (from enumeration of corresponding server component).</param> /// <param name="data">Data to be sent - as either ready WaveMessage or a FieldList.</param> /// <returns>Returns true if the transport is active and message was added to the queue.</returns> public static bool SendMessage(WaveServerComponent destination, Enum msgID, WaveMessage msg) { if (destination != WaveServerComponent.Unknown) { DebugHelper.Trace("Out: {0} -> {1}", destination, msgID); msg.ApplicationID = (int)destination; msg.MessageID = Convert.ToInt16(msgID); return(Network.PostServerMessage(msg)); } return(false); }
/// <summary> /// Made non-static so that playing can be stopped here /// </summary> /// <param name="hWaveOut"></param> /// <param name="uMsg"></param> /// <param name="dwInstance"></param> /// <param name="wavhdr"></param> /// <param name="dwReserved"></param> private void Callback(IntPtr hWaveOut, WaveMessage uMsg, IntPtr dwInstance, WaveHeader wavhdr, IntPtr dwReserved) { if (uMsg == WaveMessage.WaveOutDone) { GCHandle hBuffer = (GCHandle)wavhdr.userData; WaveOutBuffer buffer = (WaveOutBuffer)hBuffer.Target; Interlocked.Decrement(ref _queuedBuffers); Exception exception = null; // check that we're not here through pressing stop if (PlaybackState == PlaybackState.Playing) { // to avoid deadlocks in Function callback mode, // we lock round this whole thing, which will include the // reading from the stream. // this protects us from calling waveOutReset on another // thread while a WaveOutWrite is in progress lock (_waveOutLock) { try { if (buffer.OnDone()) { Interlocked.Increment(ref _queuedBuffers); } } catch (Exception e) { // one likely cause is soundcard being unplugged exception = e; } } } if (_queuedBuffers == 0) { if (_callbackInfo.Strategy == WaveCallbackStrategy.FunctionCallback && _playbackState == PlaybackState.Stopped) { // the user has pressed stop // DO NOT raise the playback stopped event from here // since on the main thread we are still in the waveOutReset function // Playback stopped will be raised elsewhere } else { // set explicitly for when we reach the end of the audio. _playbackState = PlaybackState.Stopped; RaisePlaybackStoppedEvent(exception, (_pressStop ? false : true)); } } } }
private void SendForm(FormAction trigger, ActionSet actionSet, Node sourceNode, BlockBase sourceBlock, long sourceViewID, bool expectResponse = false) { if (sourceNode != null) { WaveMessage msg = new WaveMessage(); Core.Navigation.Requests.Add(msg, sourceViewID, trigger.Transition, trigger.IsPopUp); if (Core.CSLVersion == WaveCSLVersion.Version5) { msg.AddInt16(NaviAgentFieldID.ActionTypeID, (short)trigger.ActionType); msg.AddBoolean(NaviAgentFieldID.FormRequiresNoWait, trigger.WaitForNode); } else { msg.AddByte(NaviAgentFieldID.ActionRef, (byte)trigger.FormID); } FieldList payload = FieldList.CreateField(NaviAgentFieldID.ActionPayload); payload.AddString(NaviAgentFieldID.FormRequestURL, trigger.FormURL); sourceNode.AttachFormData((short)trigger.FormID, payload); msg.AddFieldList(payload); Core.System.Location.AddLocationData(msg); if (sourceNode.CacheID != null) { msg.AddBinary(MessageOutFieldID.CacheItemID, sourceNode.CacheID.Value.ToByteArray()); } else { msg.AddString(MessageOutFieldID.ItemURI, sourceNode.URI); } if (Core.CSLVersion != WaveCSLVersion.Version5) { msg.AddInt32(NaviAgentFieldID.ActionSetID, actionSet.DefinitionID); } msg.Send(WaveServerComponent.NavigationAgent, NaviAgentMessageID.Action); if (expectResponse) { Core.UI.SignalViewNavigationStart(sourceViewID); } } }
private void GoToNodeByID(CacheItemID?id, string nodeURI, NodeTransition transition, bool isPopup, long targetViewID) { // check if node is in the cache object data = null; if (id.HasValue) { data = Core.Cache.Server[id.Value]; } if (data == null) { // request node from server if (!String.IsNullOrEmpty(nodeURI)) { WaveMessage msg = new WaveMessage(); Core.Navigation.Requests.Add(msg, targetViewID, transition, isPopup); msg.AddString(MessageOutFieldID.ItemURI, nodeURI); Core.System.Location.AddLocationData(msg); msg.Send(WaveServerComponent.NavigationAgent, NaviAgentMessageID.RequestNodeOnCacheError); Core.UI.SignalViewNavigationStart(targetViewID); } } else { // load node from cache UnpackCachedNode((FieldList)data, transition, isPopup, targetViewID); // inform server if (id.HasValue || !String.IsNullOrEmpty(nodeURI)) { WaveMessage msg = new WaveMessage(); if (id.HasValue) { msg.AddBinary(MessageOutFieldID.CacheItemID, id.Value.ToByteArray()); } else { msg.AddString(MessageOutFieldID.ItemURI, nodeURI); } msg.Send(WaveServerComponent.NavigationAgent, NaviAgentMessageID.SubscribeToNodeWithoutRequest); } } }
private void SendFrameAcknowledgement(byte[] ciid, byte[] cRefID, short frameNumber) { WaveMessage msg = new WaveMessage(); if (ciid != null) { msg.AddBinary(MessageOutFieldID.CacheItemID, ciid); } else { msg.AddBinary(MessageOutFieldID.ContentReferenceID, cRefID); } msg.AddInt16(MediaReferenceFieldID.FrameNumber, frameNumber); msg.Send(WaveServerComponent.MediaAgent, MediaAgentMessageID.FrameAcknowledgement); }
public void GoToNodeByURI(string nodeURI, NodeTransition transition, bool isPopup, long sourceViewID, bool refresh = false) { // check if node is in the cache object data = Core.Cache.Server[nodeURI]; if ((data == null) || refresh) { // not in cache, ask server Core.Network.EnsureConnection(); WaveMessage msg = new WaveMessage(); Core.Navigation.Requests.Add(msg, sourceViewID, transition, isPopup); if (refresh) { msg.AddBoolean(MessageOutFieldID.RefreshingNode, true); } msg.AddString(MessageOutFieldID.ItemURI, nodeURI); Core.System.Location.AddLocationData(msg); msg.Send(WaveServerComponent.NavigationAgent, NaviAgentMessageID.RequestNode); Core.UI.SignalViewNavigationStart(sourceViewID); } else { if (data is FieldList) { // inform server WaveMessage msg = new WaveMessage(); msg.AddString(MessageOutFieldID.ItemURI, nodeURI); msg.Send(WaveServerComponent.NavigationAgent, NaviAgentMessageID.SubscribeToNodeWithoutRequest); // unpack UnpackCachedNode((FieldList)data, transition, isPopup, sourceViewID); } else { DebugHelper.Out("Unexpected data type: {0}", data.GetType().FullName); } } }
public void OnMessageReceived(WaveServerComponent dest, Enum msgID, WaveMessage data) { if (msgID is DefAgentMessageID) { if (data != null) { switch ((DefAgentMessageID)msgID) { case DefAgentMessageID.BulkDefinitionResponse: { if (data.RootList.Count > 0) { List <FieldList> definitions = new List <FieldList>(data.RootList.Count); foreach (IFieldBase field in data.RootList) { BinaryField bin = field as BinaryField; if ((bin != null) && (bin.Data != null)) { WaveMessage msg = new WaveMessage(bin.Data); if ((DefAgentMessageID)msg.MessageID == DefAgentMessageID.DefinitionResponse) { definitions.Add(msg.RootList); } } } UnpackDefinitions(definitions); } break; } case DefAgentMessageID.DefinitionResponse: { UnpackDefinition(data.RootList); break; } } } } }
private void GoToApplication(string applicationHome, string applicationHomeNode, NodeTransition transition, bool isPopup, long sourceViewID) { //TODO: check in cache first, before trying to send a message WaveMessage msg = new WaveMessage(); Core.Navigation.Requests.Add(msg, sourceViewID, transition, isPopup); msg.AddString(NaviAgentFieldID.ApplicationURN, applicationHome); if (applicationHomeNode != null) { msg.AddString(MessageOutFieldID.ItemURI, applicationHomeNode); } Core.System.Location.AddLocationData(msg); msg.Send(WaveServerComponent.NavigationAgent, NaviAgentMessageID.GotoAnotherApplicationNode); Core.UI.SignalViewNavigationStart(sourceViewID); }
/// <summary> /// Routes server message to corresponding Wave Explorer service (if there is one). /// </summary> public static void RouteServerMessage(WaveMessage msg) { if (msg != null) { WaveServerComponent destination = (WaveServerComponent)msg.ApplicationID; Enum msgID = TransportBase.ConvertWaveMessageID(destination, msg.MessageID); DebugHelper.Trace("In: {0} -> {1}", destination, msgID); switch (destination) { case WaveServerComponent.NavigationAgent: Navigation.OnMessageReceived(destination, msgID, msg); break; case WaveServerComponent.DefinitionsAgent: Definitions.OnMessageReceived(destination, msgID, msg); break; case WaveServerComponent.CacheAgent: Cache.OnMessageReceived(destination, msgID, msg); break; case WaveServerComponent.UserManager: Authentication.OnMessageReceived(destination, msgID, msg); break; case WaveServerComponent.AggregatedMessageAgent: Network.OnMessageReceived(destination, msgID, msg); break; case WaveServerComponent.MediaAgent: Downloads.OnMessageReceived(destination, msgID, msg); break; default: DebugHelper.Out("Message for unsupported or unknown RTDS component {0} was discarded.", destination); break; } } }
/// <summary> /// Callback func. /// </summary> /// <param name="handle">The WaveOutHandle.</param> /// <param name="msg">The WaveMessage.</param> /// <param name="user">The UserData.</param> /// <param name="header">The WaveHdr.</param> /// <param name="reserved">Reserved.</param> private void Callback(IntPtr handle, WaveMessage msg, UIntPtr user, WaveHdr header, UIntPtr reserved) { if (WaveOutHandle != handle) { return; } if (msg == WaveMessage.WOM_DONE) { var hBuffer = (GCHandle)header.dwUser; var buffer = hBuffer.Target as WaveOutBuffer; Interlocked.Decrement(ref _activeBuffers); if (buffer == null) { return; } if (_playbackState != PlaybackState.Stopped) { lock (_lockObj) { if (buffer.WriteData()) { Interlocked.Increment(ref _activeBuffers); } } } if (_activeBuffers == 0) { _playbackState = PlaybackState.Stopped; RaisePlaybackChanged(); } } else if (msg == WaveMessage.WOM_CLOSE) { _playbackState = PlaybackState.Stopped; RaisePlaybackChanged(); } }
public void OnMessageReceived(WaveServerComponent dest, Enum msgID, WaveMessage data) { if (msgID is NaviAgentMessageID) { if (data != null) { switch ((NaviAgentMessageID)msgID) { case NaviAgentMessageID.ApplicationResponse: { UnpackApplicationID(data.RootList); // if we've got a cache item ID but no node URI in the message then the server is // telling us that the home node is already in our cache if (data.RootList.GetItemCount(MessageOutFieldID.ItemURI) == 0) { byte[] ciidData = data.RootList[MessageOutFieldID.CacheItemID].AsByteArray(); if (ciidData != null) { CacheItemID ciid = new CacheItemID(ciidData); byte[] bin = Core.Cache.Server.FindKey(ciid); if (bin != null) { string uri = StringHelper.GetString(bin); if (!String.IsNullOrEmpty(uri)) { FindAndStoreApplicationMessagePrefix(uri); } GoToNodeByID(ciid, String.Empty, NodeTransition.None, false, Core.UI.RootViewID); break; } } } // we also have the home node goto case NaviAgentMessageID.NodeResponse; } case NaviAgentMessageID.NodeResponse: { UnpackReceivedNode(data.RootList); break; } case NaviAgentMessageID.NodeIsInClientCache: { CacheItemID?ciid = null; short requestID = data.RootList[MessageOutFieldID.RequestID].AsShort() ?? -1; byte[] ciidData = data.RootList[MessageOutFieldID.CacheItemID].AsByteArray(); string uri = data.RootList[MessageOutFieldID.ItemURI].AsString(); if (ciidData != null) { ciid = new CacheItemID(ciidData); } RequestData rd = Core.Navigation.Requests.Remove(requestID); if (rd != null) { GoToNodeByID(ciid, uri, rd.Transition, rd.IsPopup, rd.ViewID); } else { GoToNodeByID(ciid, uri, NodeTransition.None, false, Core.UI.RootViewID); } break; } case NaviAgentMessageID.NodeResponseError: { View view = Core.UI[Core.Navigation.Requests.RemoveEx(data.RootList[MessageOutFieldID.RequestID].AsShort() ?? -1)]; if (view != null) { view.SignalNavigationFailure(); } break; } case NaviAgentMessageID.FormResponse: { if (data.RootList.GetItemCount(NaviAgentFieldID.SubmitFormResult) != 1) { break; // illegal message, only one form result should exist } SubmitFormResult sfr = (SubmitFormResult)(data[NaviAgentFieldID.SubmitFormResult].AsShort() ?? (short)SubmitFormResult.Empty); if (sfr == SubmitFormResult.NodeResponse) { UnpackReceivedNode(data.RootList); } //TODO: add waiting for result for form submit/response cycle (when navigation is replaced) break; } default: break; } } } }
public static void Send(this WaveMessage msg, WaveServerComponent destination, Enum msgID) { Core.SendMessage(destination, msgID, msg); }
/// <summary> /// Callback func. /// </summary> /// <param name="handle">The WaveOutHandle.</param> /// <param name="msg">The WaveMessage.</param> /// <param name="user">The UserData.</param> /// <param name="header">The WaveHdr.</param> /// <param name="reserved">Reserved.</param> private void Callback(IntPtr handle, WaveMessage msg, UIntPtr user, WaveHdr header, UIntPtr reserved) { if (WaveOutHandle != handle) return; if (msg == WaveMessage.WOM_DONE) { var hBuffer = (GCHandle) header.dwUser; var buffer = hBuffer.Target as WaveOutBuffer; Interlocked.Decrement(ref _activeBuffers); if (buffer == null) return; if (_playbackState != PlaybackState.Stopped) { lock (_lockObj) { if (buffer.WriteData()) Interlocked.Increment(ref _activeBuffers); } } if (_activeBuffers == 0) { _playbackState = PlaybackState.Stopped; RaisePlaybackChanged(); } } else if (msg == WaveMessage.WOM_CLOSE) { _playbackState = PlaybackState.Stopped; RaisePlaybackChanged(); } }
public void OnMessageReceived(WaveServerComponent dest, Enum msgID, WaveMessage data) { if (msgID is UserManagerMessageID) { if (data != null) { switch ((UserManagerMessageID)msgID) { case UserManagerMessageID.Challenge: { bool createAccount = false; // check if there is login already (otherwise set defaults) if (!Core.Application.HasLogin) { createAccount = true; Core.Application.UpdateCredentials(GenerateNewUsername(), StringHelper.GetBytes(DefaultPassword)); } // get CSL version WaveCSLVersion serverCSL = (WaveCSLVersion)(data[UserManagerFieldID.CSLVersion].AsShort() ?? (short)WaveCSLVersion.Unknown); switch (serverCSL) { case WaveCSLVersion.Version5: case WaveCSLVersion.Version4: Core.CSLVersion = serverCSL; break; default: Core.CSLVersion = WaveCSLVersion.Version3; break; } // get maximum protocol version WaveProtocolVersion serverProto = (WaveProtocolVersion)(data[UserManagerFieldID.MaxWeMessageVersion].AsByte() ?? (byte)WaveProtocolVersion.Unknown); switch (serverProto) { case WaveProtocolVersion.Version4: Core.ProtocolVersion = WaveProtocolVersion.Version4; break; default: Core.ProtocolVersion = WaveProtocolVersion.Version3; break; } // get challenge BinaryField challenge = (BinaryField)data[UserManagerFieldID.Challenge]; // assemble login message WaveMessage msgOut = new WaveMessage(); msgOut.AddInt16(UserManagerFieldID.CSLVersion, (short)Core.CSLVersion); msgOut.AddBoolean(UserManagerFieldID.EncryptSession, Core.UseEncryption); msgOut.AddInt16(UserManagerFieldID.PriorityMask, NetworkAgent.PrioritiesActiveMask); msgOut.AddBinary(UserManagerFieldID.UserCredentials, ProcessChallenge(challenge.Data, Core.Application, createAccount)); msgOut.AddBoolean(UserManagerFieldID.CreateAccount, createAccount); // cache hash byte[] cacheHash = Core.Cache.CacheHash; msgOut.AddBinary(CacheAgentFieldID.CacheHashCompressed, (cacheHash.Length > 0) ? CompressionHelper.GZipBuffer(cacheHash) : cacheHash); // cache ID (if any) if (Core.Cache.CacheID.HasValue) { msgOut.AddBinary(MessageOutFieldID.CacheItemID, Core.Cache.CacheID.Value.ToByteArray()); } // compiling device settings FieldList deviceSettingsList = FieldList.CreateField(UserManagerFieldID.DeviceSettings); deviceSettingsList.AddString(UserManagerFieldID.DeviceBuildID, Core.BuildID); deviceSettingsList.AddBoolean(NaviAgentFieldID.DeviceSupportsTouch, true); deviceSettingsList.AddInt16(NaviAgentFieldID.DeviceScreenResolutionWidth, 480); deviceSettingsList.AddInt16(NaviAgentFieldID.DeviceScreenResolutionHeight, 800); DeviceGroup[] devs = Core.System.SupportedDeviceGroups; foreach (DeviceGroup dev in devs) { deviceSettingsList.AddInt16(NaviAgentFieldID.DeviceProfileGroup, (short)dev); } deviceSettingsList.AddString(UserManagerFieldID.LanguageID, CultureInfo.CurrentCulture.Name); deviceSettingsList.AddString(UserManagerFieldID.Timezone, Core.Settings.TimeZone); deviceSettingsList.AddBoolean(UserManagerFieldID.AlphaSupport, true); deviceSettingsList.AddBoolean(UserManagerFieldID.CompressionSupport, true); msgOut.AddFieldList(deviceSettingsList); // compiling application request list FieldList appRequestList = FieldList.CreateField(UserManagerFieldID.ApplicationRequest); appRequestList.AddString(NaviAgentFieldID.ApplicationURN, Core.Application.URI); appRequestList.AddInt16(NaviAgentFieldID.ApplicationRequestAction, (short)AppRequestAction.GetAppEntryPage); msgOut.AddFieldList(appRequestList); msgOut.Send(WaveServerComponent.UserManager, UserManagerMessageID.Login); Core.UI.SignalViewNavigationStart(Core.UI.RootViewID); break; } case UserManagerMessageID.EncryptionKeys: { // setting encryption (if allowed by build configuration) if (Core.UseEncryption && (sessionHandshakeFish != null)) { BinaryField sessionKeyField = (BinaryField)data[UserManagerFieldID.SessionKey]; byte[] sessionKey = (byte[])sessionKeyField.Data; sessionHandshakeFish.Decrypt(sessionKey, sessionKey.Length); BinaryField globalServerKeyField = (BinaryField)data[UserManagerFieldID.GlobalServerKey]; byte[] globalServerKey = (byte[])globalServerKeyField.Data; sessionHandshakeFish.Decrypt(globalServerKey, globalServerKey.Length); Core.NotifyEncryptionKeysChanged(this, sessionKey, globalServerKey); } else { Core.NotifyEncryptionKeysChanged(this, null, null); } // setting login data StringField userName = (StringField)data[UserManagerFieldID.CreatedAccountUserName]; if (userName != null) { BinaryField userPass = (BinaryField)data[UserManagerFieldID.CreatedAccountPasswordHash]; if ((userPass != null) && (sessionHandshakeFish != null)) { byte[] passBuffer = (byte[])userPass.Data.Clone(); sessionHandshakeFish.Decrypt(passBuffer, passBuffer.Length); Core.Application.UpdateCredentials(userName.Data, passBuffer); // no longer needed sessionHandshakeFish = null; } } break; } case UserManagerMessageID.LoginResponse: { if (!authenticated) { Int16Field loginStatus = (Int16Field)data[UserManagerFieldID.LoginStatus]; switch ((UserLoginStatus)loginStatus.Data) { case UserLoginStatus.Success: { // signal authentication success Core.NotifyAuthentication(this, data[UserManagerFieldID.SessionInfo].AsByteArray()); // preparing login data message FieldList appContext = (FieldList)data[UserManagerFieldID.ApplicationContext]; if (appContext != null) { int appID = appContext[MessageOutFieldID.ApplicationID].AsInteger() ?? 0; string unqualifiedAppURI = appContext[UserManagerFieldID.ApplicationUnqualifiedURI].AsText(); string fullyQualifiedAppURI = appContext[UserManagerFieldID.ApplicationFullyQualifiedURI].AsText(); Core.NotifySuccessfulLogin(this, appID, unqualifiedAppURI, fullyQualifiedAppURI); } authenticated = true; authenticatedEver = true; break; } case UserLoginStatus.FailedInvalidCredentials: Core.NotifyTerminateSession(this, SessionTerminationReasonCode.InvalidCredentials); break; case UserLoginStatus.FailedNoUser: Core.NotifyTerminateSession(this, SessionTerminationReasonCode.NoSuchUser); break; } } break; } } } } }
public void OnMessageReceived(WaveServerComponent dest, Enum msgID, WaveMessage data) { if (msgID is MediaAgentMessageID) { if (data != null) { switch ((MediaAgentMessageID)msgID) { case MediaAgentMessageID.DownloadResponse: { // extract useful data byte[] ciidData = data[MessageOutFieldID.CacheItemID].AsByteArray(); byte[] cRefID = data[MessageOutFieldID.ContentReferenceID].AsByteArray(); byte cacheHint = (byte)CacheHint.PersistStore_ShouldCache; if (ciidData != null) { cacheHint = data[MessageOutFieldID.CacheHint].AsByte() ?? (byte)CacheHint.PersistStore_ShouldCache; } int downloadSize = data[MessageOutFieldID.DownloadSize].AsInteger() ?? -1; // only sent for multi-frame downloads if (downloadSize != -1) { // first frame of a multi-frame download byte[] binary = data[MediaReferenceFieldID.BinaryFrame].AsByteArray(); if (binary != null) { downloads.Start(ciidData, cRefID, binary, downloadSize, cacheHint); } // ack the frame SendFrameAcknowledgement(ciidData, cRefID, 0); } else { // single frame download byte[] binary = data[MediaReferenceFieldID.BinaryFrame].AsByteArray(); if (binary != null) { // act on download OnDownloadComplete(ciidData, cRefID, binary, cacheHint); // ack the frame SendFrameAcknowledgement(ciidData, cRefID, 0); } } break; } case MediaAgentMessageID.Frame: { short frameNumber = data[MediaReferenceFieldID.FrameNumber].AsShort() ?? -1; if (frameNumber != -1) { byte[] ciidData = data[MessageOutFieldID.CacheItemID].AsByteArray(); byte[] crefID = data[MessageOutFieldID.ContentReferenceID].AsByteArray(); if ((crefID != null) || (ciidData != null)) { //IMPLEMENT: support for bulk downloads byte[] binary = data[MediaReferenceFieldID.BinaryFrame].AsByteArray(); if (binary != null) { downloads.Add(ciidData, crefID, binary); // check if complete if (downloads.IsComplete(ciidData, crefID)) { DownloadManager.DownloadRecord dr = downloads.Retrieve(ciidData, crefID); if (dr != null) { OnDownloadComplete(dr.CacheItemID, dr.ContentRefenceID, dr.Buffer, dr.CacheHint); } } // ack the frame SendFrameAcknowledgement(ciidData, crefID, frameNumber); } } } break; } case MediaAgentMessageID.OpenStreamResponse: { byte[] contentID = data[MessageOutFieldID.ContentReferenceID].AsByteArray(); // content reference string streamURL = data[MediaReferenceFieldID.StreamURL].AsString(); byte[] streamSessionID = data[MediaReferenceFieldID.StreamSessionID].AsByteArray(); // for a stream switch between streams where 1 is not an MSG stream the player must be torn down and recreated. // only MSG supports the "fast stream switch" bool nonMsgStream = data.RootList.HasField(MediaReferenceFieldID.NonMSGStream); short mediaType = data[MessageOutFieldID.MediaPrimitiveType].AsShort() ?? -1; Core.NotifyStreamResponseReceived(this, contentID, streamURL, streamSessionID, nonMsgStream, mediaType); break; } } } } }