And the second method, createSession, is kind of self-explanatory. So, this method will create a session within which we'll obtain the keys to decrypt the content. But before we call any of these methods, we first have to take the media keys object that we just got, and we have to assign it to the video HTML media element or audio. But in our case, we are working with video today. So, once we have done that, then we can actually call the createSession method and it accepts only one parameter, which is type of the session. By default, it always creates a temporary one, but you can also create a persistent, but it requires a higher level of security. So, by default, we can just go with the temporary type, which we do. And then, as a result, we should get the media key session object back. And here, I listed three of the most important methods here.
And as the next step, we'll get the generateRequest method with two parameters, anyDataType and anyData. And now, these two are coming from, alone, from the encrypted event that was emitted in the very, very beginning by the browser. So, what we do here, we get whatever was called in the very beginning, whatever was included in the encrypted event in the very beginning, and we just pass it through to the generateRequest method. And what happens later is that this request is forwarded to the CDM module. And CDM module, at this point, realizes, okay, so this is an encrypted content, and in order to decrypt it, I need a key. So, I will emit a message event, which basically means that I need a key. So, what we do on the player's side, we listen for such messages through the onMessage event handler. So, once we received such message, then we make a POST request to the license server to obtain the license. If everything goes well, we got the license back. And as I mentioned, this one is, of course, also encrypted, but the license itself that contains the keys is also obfuscated. So, if you will see event inside for some reason how it looks like, this information is only understandable by the content decryption module. So, going back to the process, once we got the license back, we are proxying it to the content decryption module through the update method. So, once the content decryption module got it, then it can take it, unwrap it, take the key, and then decrypt the frame and provide the decrypted frame back to the user. So, now they can basically enjoy watching video or listen to a song.
So, yeah, I know it was quite a complex process, but hey, we did it! So, we went through all of the parts, which is great. And now, with that said, we can safely say that we support like both the criteria that we just specified in the very beginning. So, now we can, we have a control over playing fraction of the data, but we also are able to play unencrypted content, which is great. And that being said, now I think it's time for a demo. So, let's have a quick look how it all works in action. So, here I prepared for you a web application on the left-hand side that you can notice. And you can also see that I'm getting like a lot of errors.
Comments