Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the iris-ws.js file to CDNJS #1047

Open
dibyendu opened this Issue Jul 24, 2018 · 5 comments

Comments

Projects
None yet
2 participants
@dibyendu
Copy link
Contributor

commented Jul 24, 2018

Hi, for the websocket client-side module, currently iris has one .ts file here: https://github.com/kataras/iris/blob/master/websocket/client.ts, which is embedded as javascript in the client.go file

var ClientSource = []byte(`var websocketStringMessageType = 0;
and it is being served from within the .go file itself (on an endpoint called /iris-ws.js).

Here is a working snippet:

import (
    "github.com/kataras/iris"
    "github.com/kataras/iris/websocket"
)

func main() {
app := iris.New()
// serve the javascript built'n client-side library,
// see websockets.html script tags, this path is used.
app.Any("/iris-ws.js", func(ctx iris.Context) {
    ctx.Write(websocket.ClientSource)
})

But it would be nice if we could host the client side javascript on some CDN and server it from there. CDNJS is one such free CDN service provider. But it appears that they only serve Javascript and NOT Typescript or javascript embedded in .go.

I've already opened a request on CDNJS for hosting the iris-ws.js file. This is the issue: cdnjs/cdnjs#12884

But since there is no .js file in the iris repository, they seem to be finding it difficult to host.

Is it possible for you to add the client.js or iris-ws.js file along with the client.ts file in https://github.com/kataras/iris/blob/master/websocket/ ?

The client.ts can be converted to iris-ws.js as follows:

npm install -g typescript
tsc client.ts 

or using this online service: https://www.typescriptlang.org/play

kataras added a commit that referenced this issue Jul 25, 2018

@kataras

This comment has been minimized.

Copy link
Owner

commented Jul 25, 2018

Done @dibyendu , thank you a lot for this!

P.S: I know how to convert typescript to javascipt and the opossite, I am a typescript enthusiast from the beginning of its life :P

@dibyendu

This comment has been minimized.

Copy link
Contributor Author

commented Jul 30, 2018

Hi @kataras please add the client.min.js file as well to the repo, so that I can add it to the CDNJS autoupdate section here: https://github.com/cdnjs/cdnjs/pull/12896/files#diff-9a0f3365f38ba05fa353b7c8818ce584R12

@kataras

This comment has been minimized.

Copy link
Owner

commented Jul 30, 2018

Oups sorry, your PR is merged, thank you a lot @dibyendu!

@dibyendu

This comment has been minimized.

Copy link
Contributor Author

commented Aug 20, 2018

Hi @kataras, there is a good news. The client side library iris-ws.js is now part of CDNJS.
There are 2 files, client.js and client.min.js: https://cdnjs.com/libraries/iris-ws
Now you can mention this in the relevant README and/or change the part of the code accordingly.

<!doctype html>
<html>
<head>
-	<script type="text/javascript" src="/iris-ws.js"></script>
+	<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/iris-ws/10.7.0/client.min.js"></script>
</head>
	<body>
	</body>
</html>

Thanks

@kataras

This comment has been minimized.

Copy link
Owner

commented Aug 23, 2018

That's wonderful news, so end-devs are not necessarily need to serve the websocket.ClientSource manually if they are online. I will put a note at the v11 branch, thank you a lot for your contribution @dibyendu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.