Example #1
0
func (c *controllerWrapper) LoadTrack(ident string, gids []string, cb *js.Object) {
	go func() {
		err := c.controller.LoadTrack(ident, gids)
		if err != nil {
			cb.Invoke("Hello failed: " + err.Error())
		}
	}()
}
Example #2
0
func (c *controllerWrapper) SendVolume(ident string, volume int, cb *js.Object) {
	go func() {
		err := c.controller.SendVolume(ident, volume)
		if err != nil {
			cb.Invoke("Hello failed: " + err.Error())
		}
	}()
}
Example #3
0
func (c *controllerWrapper) SendHello(cb *js.Object) {
	go func() {
		err := c.controller.SendHello()
		if err != nil {
			cb.Invoke("Hello failed: " + err.Error())
		}
	}()
}
Example #4
0
func loginSaved(username, authData string, appkey string, cb *js.Object) {
	go func() {
		key, _ := base64.StdEncoding.DecodeString(appkey)
		data, _ := base64.StdEncoding.DecodeString(authData)
		conn, _ := MakeConn()
		sController, err := spotcontrol.LoginConnectionSaved(username, data, key, "spotcontrol", conn)
		if err != nil {
			cb.Invoke(nil, "", "login failed")
		}
		c := &controllerWrapper{controller: sController}
		cb.Invoke(js.MakeWrapper(c), authData, nil)
	}()
}
Example #5
0
func login(username, password, appkey string, cb *js.Object) {
	go func() {
		key, _ := base64.StdEncoding.DecodeString(appkey)
		conn, _ := MakeConn()
		sController, err := spotcontrol.LoginConnection(username, password, key, "spotcontrol", conn)
		if err != nil {
			cb.Invoke(nil, "", "login failed")
		} else {
			authData := sController.SavedCredentials
			c := &controllerWrapper{controller: sController}
			cb.Invoke(js.MakeWrapper(c), base64.StdEncoding.EncodeToString(authData), nil)
		}
	}()
}
Example #6
0
func parsePSD(in *js.Object, progress *js.Object, complete *js.Object, failed *js.Object) {
	go func() {
		defer func() {
			if err := recover(); err != nil {
				failed.Invoke(fmt.Sprint("uncaught exception occurred on during parsing PSD: ", err))
			}
		}()
		r, err := newReaderFromJSObject(in)
		if err != nil {
			failed.Invoke(err.Error())
			return
		}
		canvasMap := map[int][2]*js.Object{}
		root, err := parse(r, func(prog float64) {
			progress.Invoke(prog)
		}, func(seqID int, l *psd.Layer) {
			var canvas, mask *js.Object
			if l.HasImage() && !l.Rect.Empty() {
				var a []byte
				if ach, ok := l.Channel[-1]; ok {
					a = ach.Data
				}
				canvas = createImageCanvas(
					l.Rect.Dx(),
					l.Rect.Dy(),
					l.Channel[0].Data,
					l.Channel[1].Data,
					l.Channel[2].Data,
					a,
				)
			}
			if m, ok := l.Channel[-2]; ok && l.Mask.Enabled() && !l.Mask.Rect.Empty() {
				mask = createMaskCanvas(l.Mask.Rect.Dx(), l.Mask.Rect.Dy(), m.Data, l.Mask.DefaultColor)
			}
			canvasMap[seqID] = [2]*js.Object{canvas, mask}
		})
		if err != nil {
			failed.Invoke(err.Error())
			return
		}
		mapCanvasGo(canvasMap, root)
		complete.Invoke(root)
	}()
}
Example #7
0
func parsePSDInWorker(in *js.Object, progress *js.Object, complete *js.Object, failed *js.Object) {
	script := js.Global.Get("document").Call("getElementById", "psdgo")
	if !script.Bool() {
		panic("id=psdgo not found")
	}
	worker := js.Global.Get("Worker").New(script.Get("src"))
	script.Set("psdgo", worker)
	canvasMap := map[int][2]*js.Object{}
	worker.Set("onmessage", func(e *js.Object) {
		data := e.Get("data")
		switch data.Get("type").String() {
		case "makeCanvas":
			var canvas, mask *js.Object
			if w, h := data.Get("w").Int(), data.Get("h").Int(); w*h > 0 {
				r := js.Global.Get("Uint8Array").New(data.Get("r")).Interface().([]byte)
				g := js.Global.Get("Uint8Array").New(data.Get("g")).Interface().([]byte)
				b := js.Global.Get("Uint8Array").New(data.Get("b")).Interface().([]byte)
				var a []byte
				if aab := data.Get("a"); aab.Bool() {
					a = js.Global.Get("Uint8Array").New(aab).Interface().([]byte)
				}
				canvas = createImageCanvas(w, h, r, g, b, a)
			}
			if m := data.Get("m"); m.Bool() {
				mask = createMaskCanvas(
					data.Get("mw").Int(), data.Get("mh").Int(),
					js.Global.Get("Uint8Array").New(m).Interface().([]byte),
					data.Get("mc").Int(),
				)
			}
			canvasMap[data.Get("id").Int()] = [2]*js.Object{canvas, mask}
		case "progress":
			progress.Invoke(data.Get("progress"))
		case "error":
			failed.Invoke(data.Get("error"))
		case "complete":
			root := data.Get("root")
			mapCanvasJS(canvasMap, root)
			complete.Invoke(root)
		}
	})
	if jsbuiltin.InstanceOf(in, js.Global.Get("ArrayBuffer")) {
		worker.Call("postMessage", js.M{
			"input": in,
		}, js.S{in})
	} else {
		worker.Call("postMessage", js.M{"input": in})
	}
}
Example #8
0
func jsCallback(f *js.Object) Callback {
	if f == nil || f == js.Undefined {
		return nil
	}
	return func(val interface{}) interface{} { return f.Invoke(val) }
}