Exemple #1
0
    void OnPostChannelInfo(HttpListenerRequest req, HttpListenerResponse res, string channel)
    {
        if (channels.Contains(channel))
        {
            OnError(req, res, "exist");
            return;
        }

        string inString = GetText(req);

        if (inString == null)
        {
            OnError(req, res, "400");
            return;
        }

        StreamingMesh.ChannelInfo channelInfo  = JsonUtility.FromJson <StreamingMesh.ChannelInfo>(inString);
        List <string>             meshUrls     = new List <string>(channelInfo.meshes);
        List <string>             materialUrls = new List <string>(channelInfo.materials);
        List <string>             textureUrls  = new List <string>(channelInfo.textures);

        for (int i = 0; i < meshUrls.Count; i++)
        {
            meshUrls[i] = url + "channels/" + channel + "/" + meshUrls[i];
        }
        for (int i = 0; i < materialUrls.Count; i++)
        {
            materialUrls[i] = url + "channels/" + channel + "/" + materialUrls[i];
        }
        for (int i = 0; i < textureUrls.Count; i++)
        {
            textureUrls[i] = url + "channels/" + channel + "/" + textureUrls[i];
        }
        channelInfo.meshes      = meshUrls;
        channelInfo.materials   = materialUrls;
        channelInfo.textures    = textureUrls;
        channelInfo.stream_info = url + "channels/" + channel + "/streaminfo.stmj";
        Debug.Log(JsonUtility.ToJson(channelInfo));
        FileWrite <string>("channels", channel, "stream.json", JsonUtility.ToJson(channelInfo));

        System.Random random = new System.Random();
        const string  chars  = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        string        auth   = new string(Enumerable.Repeat(chars, 8)
                                          .Select(s => s[random.Next(s.Length)]).ToArray());

        channels.Add(channel);
        auths.Add(auth);

        string outString = "{\"auth\":\"" + auth + "\"}";

        res.StatusCode  = (int)HttpStatusCode.OK;
        res.ContentType = MediaTypeNames.Text.Plain;

        SendText(outString, res);
    }